|
|
|
@ -15,7 +15,7 @@ import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
|
|
|
|
import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
|
|
|
|
import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class ChatVoipCall {
|
|
|
|
class ChatVoipCall extends WidgetsBindingObserver {
|
|
|
|
static final ChatVoipCall _instance = ChatVoipCall._internal();
|
|
|
|
static final ChatVoipCall _instance = ChatVoipCall._internal();
|
|
|
|
|
|
|
|
|
|
|
|
ChatVoipCall._internal();
|
|
|
|
ChatVoipCall._internal();
|
|
|
|
@ -26,34 +26,44 @@ class ChatVoipCall {
|
|
|
|
late ChatCallProvider cProv;
|
|
|
|
late ChatCallProvider cProv;
|
|
|
|
dynamic inCallData;
|
|
|
|
dynamic inCallData;
|
|
|
|
bool isUserOnline = false;
|
|
|
|
bool isUserOnline = false;
|
|
|
|
|
|
|
|
dynamic callData;
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> showCallkitIncoming({required String uuid, RemoteMessage? data, CallDataModel? incomingCallData, bool background = false}) async {
|
|
|
|
Future<void> showCallkitIncoming({required String uuid, RemoteMessage? data, CallDataModel? incomingCallData, bool background = false}) async {
|
|
|
|
await ChatVoipCall().listenerEvent();
|
|
|
|
await ChatVoipCall().listenerEvent();
|
|
|
|
|
|
|
|
//WidgetsBinding.instance.addObserver(this);
|
|
|
|
ALM.Response autoLoginData;
|
|
|
|
ALM.Response autoLoginData;
|
|
|
|
SingleUserChatModel callerData;
|
|
|
|
SingleUserChatModel callerData;
|
|
|
|
// if(!background){}
|
|
|
|
|
|
|
|
await initProviders();
|
|
|
|
|
|
|
|
if (data!.data["user_token_response"] == null || data.data["user_token_response"].isEmpty) {
|
|
|
|
if (data!.data["user_token_response"] == null || data.data["user_token_response"].isEmpty) {
|
|
|
|
autoLoginData = ALM.Response.fromJson(AppState().getchatUserDetails!.response!.toJson());
|
|
|
|
autoLoginData = ALM.Response.fromJson(AppState().getchatUserDetails!.response!.toJson());
|
|
|
|
dynamic items = jsonDecode(data!.data["user_chat_history_response"]);
|
|
|
|
dynamic items = jsonDecode(data!.data["user_chat_history_response"]);
|
|
|
|
callerData = SingleUserChatModel(
|
|
|
|
callerData = SingleUserChatModel(
|
|
|
|
targetUserId: items["CurrentUserId"],
|
|
|
|
targetUserId: items["CurrentUserId"],
|
|
|
|
targetUserEmail: items["CurrentUserName"],
|
|
|
|
targetUserEmail: items["CurrentUserEmail"],
|
|
|
|
targetUserName: items["CurrentUserEmail"],
|
|
|
|
targetUserName: items["CurrentUserName"].split("@").first,
|
|
|
|
currentUserId: autoLoginData.id,
|
|
|
|
currentUserId: autoLoginData.id,
|
|
|
|
currentUserEmail: autoLoginData.email,
|
|
|
|
currentUserEmail: autoLoginData.email,
|
|
|
|
currentUserName: autoLoginData.userName!.split("@").first,
|
|
|
|
currentUserName: autoLoginData.userName,
|
|
|
|
chatEventId: 3);
|
|
|
|
chatEventId: 3);
|
|
|
|
isUserOnline = true;
|
|
|
|
isUserOnline = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
autoLoginData = ALM.Response.fromJson(jsonDecode(data.data["user_token_response"]));
|
|
|
|
autoLoginData = ALM.Response.fromJson(jsonDecode(data.data["user_token_response"]));
|
|
|
|
callerData = SingleUserChatModel.fromJson(json.decode(data!.data["user_chat_history_response"]));
|
|
|
|
callerData = SingleUserChatModel.fromJson(json.decode(data!.data["user_chat_history_response"]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data!.data["callType"] == "video") {
|
|
|
|
callData = jsonEncode([
|
|
|
|
cProv.isVideoCall = true;
|
|
|
|
{
|
|
|
|
} else {
|
|
|
|
"loginDetails": autoLoginData.toJson(),
|
|
|
|
cProv.isAudioCall = true;
|
|
|
|
"callerDetails": callerData.toJson(),
|
|
|
|
cProv.isVideoCall = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!background) {
|
|
|
|
|
|
|
|
await initProviders();
|
|
|
|
|
|
|
|
if (data!.data["callType"] == "video") {
|
|
|
|
|
|
|
|
cProv.isVideoCall = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cProv.isAudioCall = true;
|
|
|
|
|
|
|
|
cProv.isVideoCall = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CallKitParams params = CallKitParams(
|
|
|
|
CallKitParams params = CallKitParams(
|
|
|
|
id: uuid,
|
|
|
|
id: uuid,
|
|
|
|
@ -99,11 +109,6 @@ class ChatVoipCall {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (callerData.chatEventId == 3) {
|
|
|
|
if (callerData.chatEventId == 3) {
|
|
|
|
await Utils.saveStringFromPrefs("isIncomingCall", "true");
|
|
|
|
await Utils.saveStringFromPrefs("isIncomingCall", "true");
|
|
|
|
connection(
|
|
|
|
|
|
|
|
data: jsonEncode([
|
|
|
|
|
|
|
|
{"loginDetails": autoLoginData.toJson(), "callerDetails": callerData.toJson()}
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
isUserOnline: isUserOnline);
|
|
|
|
|
|
|
|
await FlutterCallkitIncoming.showCallkitIncoming(params);
|
|
|
|
await FlutterCallkitIncoming.showCallkitIncoming(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -114,8 +119,8 @@ class ChatVoipCall {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void connection({required data, required bool isUserOnline}) async {
|
|
|
|
void connection({required data, required bool isUserOnline}) async {
|
|
|
|
cProv.isUserOnline = isUserOnline;
|
|
|
|
|
|
|
|
if (isUserOnline) {
|
|
|
|
if (isUserOnline) {
|
|
|
|
|
|
|
|
cProv.isUserOnline = isUserOnline;
|
|
|
|
cProv.startIncomingCallViaKit(inCallData: data);
|
|
|
|
cProv.startIncomingCallViaKit(inCallData: data);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
dynamic callData = await jsonDecode(data);
|
|
|
|
dynamic callData = await jsonDecode(data);
|
|
|
|
@ -141,6 +146,7 @@ class ChatVoipCall {
|
|
|
|
switch (event!.event) {
|
|
|
|
switch (event!.event) {
|
|
|
|
case Event.ACTION_CALL_INCOMING:
|
|
|
|
case Event.ACTION_CALL_INCOMING:
|
|
|
|
// TODO: received an incoming call
|
|
|
|
// TODO: received an incoming call
|
|
|
|
|
|
|
|
connection(data: callData, isUserOnline: isUserOnline);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Event.ACTION_CALL_START:
|
|
|
|
case Event.ACTION_CALL_START:
|
|
|
|
// TODO: started an outgoing call
|
|
|
|
// TODO: started an outgoing call
|
|
|
|
@ -150,6 +156,10 @@ class ChatVoipCall {
|
|
|
|
if (isUserOnline) {
|
|
|
|
if (isUserOnline) {
|
|
|
|
cProv.init();
|
|
|
|
cProv.init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isUserOnline) {
|
|
|
|
|
|
|
|
initProviders();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
|
|
|
|
Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
|
|
|
|
|
|
|
|
|
|
|
|
// Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
|
|
|
|
// Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall);
|
|
|
|
@ -193,4 +203,27 @@ class ChatVoipCall {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} on Exception {}
|
|
|
|
} on Exception {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
|
|
|
|
super.didChangeAppLifecycleState(state);
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
|
|
|
case AppLifecycleState.paused:
|
|
|
|
|
|
|
|
logger.i('paused');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AppLifecycleState.inactive:
|
|
|
|
|
|
|
|
logger.i('inactive');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AppLifecycleState.resumed:
|
|
|
|
|
|
|
|
logger.i('resumed');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AppLifecycleState.detached:
|
|
|
|
|
|
|
|
logger.i('detached');
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|