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