|  |  |  | @ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_callkit_incoming/entities/entities.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/app_state/app_state.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/consts.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/navigationService.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/notifications.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/utils.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -13,9 +14,14 @@ import 'package:mohem_flutter_app/models/chat/call.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as ALM; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart'; | 
		
	
		
			
				|  |  |  |  | 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/ui/chat/call/chat_incoming_call_screen.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:provider/provider.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:signalr_netcore/hub_connection.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:signalr_netcore/signalr_client.dart'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |   static final ChatVoipCall _instance = ChatVoipCall._internal(); | 
		
	
	
		
			
				
					|  |  |  | @ -29,6 +35,7 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |   dynamic inCallData; | 
		
	
		
			
				|  |  |  |  |   bool isUserOnline = false; | 
		
	
		
			
				|  |  |  |  |   dynamic callData; | 
		
	
		
			
				|  |  |  |  |   late IncomingCallModel sessionData; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> showCallkitIncoming({required String uuid, RemoteMessage? data, CallDataModel? incomingCallData, bool background = false}) async { | 
		
	
		
			
				|  |  |  |  |     await ChatVoipCall().listenerEvent(); | 
		
	
	
		
			
				
					|  |  |  | @ -38,7 +45,6 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |     if (data!.data["user_token_response"] == null || data.data["user_token_response"].isEmpty) { | 
		
	
		
			
				|  |  |  |  |       // Online & App Logged In | 
		
	
		
			
				|  |  |  |  |       ALM.Response sharedDetails = ALM.Response.fromJson(jsonDecode(await Utils.getStringFromPrefs("userLoginChatDetails"))); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       autoLoginData = ALM.Response.fromJson(AppState().getchatUserDetails == null ? sharedDetails.toJson() : AppState().getchatUserDetails!.response!.toJson()); | 
		
	
		
			
				|  |  |  |  |       dynamic items = jsonDecode(data!.data["user_chat_history_response"]); | 
		
	
		
			
				|  |  |  |  |       callerData = SingleUserChatModel( | 
		
	
	
		
			
				
					|  |  |  | @ -61,7 +67,7 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |       appName: 'Mohemm', | 
		
	
		
			
				|  |  |  |  |       handle: '', | 
		
	
		
			
				|  |  |  |  |       type: 0, | 
		
	
		
			
				|  |  |  |  |       duration: 25000, | 
		
	
		
			
				|  |  |  |  |       duration: 20000, | 
		
	
		
			
				|  |  |  |  |       textAccept: 'Accept', | 
		
	
		
			
				|  |  |  |  |       textDecline: 'Decline', | 
		
	
		
			
				|  |  |  |  |       textMissedCall: 'Missed call', | 
		
	
	
		
			
				
					|  |  |  | @ -70,6 +76,7 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |         "loginDetails": autoLoginData.toJson(), | 
		
	
		
			
				|  |  |  |  |         "callerDetails": callerData.toJson(), | 
		
	
		
			
				|  |  |  |  |         'isIncomingCall': true, | 
		
	
		
			
				|  |  |  |  |         'isUserOnline': isUserOnline, | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |       android: const AndroidParams( | 
		
	
		
			
				|  |  |  |  |         isCustomNotification: true, | 
		
	
	
		
			
				
					|  |  |  | @ -98,11 +105,13 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |         ringtonePath: 'system_ringtone_default', | 
		
	
		
			
				|  |  |  |  |       ), | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     sessionData = IncomingCallModel.fromJson(params.toJson()); | 
		
	
		
			
				|  |  |  |  |     if (callerData.chatEventId == 3) { | 
		
	
		
			
				|  |  |  |  |       await Utils.saveStringFromPrefs("isIncomingCall", "true"); | 
		
	
		
			
				|  |  |  |  |       await FlutterCallkitIncoming.showCallkitIncoming(params); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future getCurrentCall() async { | 
		
	
		
			
				|  |  |  |  |     var calls = await FlutterCallkitIncoming.activeCalls(); | 
		
	
		
			
				|  |  |  |  |     if (calls is List) { | 
		
	
	
		
			
				
					|  |  |  | @ -115,19 +124,19 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void checkAndNavigationCallingPage() async { | 
		
	
		
			
				|  |  |  |  |     var currentCall = await getCurrentCall(); | 
		
	
		
			
				|  |  |  |  |     dynamic currentCall = await getCurrentCall(); | 
		
	
		
			
				|  |  |  |  |     if (currentCall != null) { | 
		
	
		
			
				|  |  |  |  |       Future.delayed(const Duration(seconds: 2)).whenComplete(() { | 
		
	
		
			
				|  |  |  |  |       Future.delayed(const Duration(seconds: 1)).whenComplete(() { | 
		
	
		
			
				|  |  |  |  |         Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall); | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> isCall() async { | 
		
	
		
			
				|  |  |  |  |     var calls = await FlutterCallkitIncoming.activeCalls(); | 
		
	
		
			
				|  |  |  |  |     dynamic calls = await FlutterCallkitIncoming.activeCalls(); | 
		
	
		
			
				|  |  |  |  |     if (calls is List) { | 
		
	
		
			
				|  |  |  |  |       if (calls.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |         NavigationService.navigateTo(AppRoutes.chatStartCall); | 
		
	
		
			
				|  |  |  |  |         NavigationService.navigateToPage(StartCallPage()); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
	
		
			
				
					|  |  |  | @ -143,18 +152,15 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |             break; | 
		
	
		
			
				|  |  |  |  |           case Event.ACTION_CALL_ACCEPT: | 
		
	
		
			
				|  |  |  |  |             if (isUserOnline) { | 
		
	
		
			
				|  |  |  |  |             checkAndNavigationCallingPage(); | 
		
	
		
			
				|  |  |  |  |              } else { | 
		
	
		
			
				|  |  |  |  |                isCall(); | 
		
	
		
			
				|  |  |  |  |              } | 
		
	
		
			
				|  |  |  |  |               checkAndNavigationCallingPage(); | 
		
	
		
			
				|  |  |  |  |             } else { | 
		
	
		
			
				|  |  |  |  |               isCall(); | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |             break; | 
		
	
		
			
				|  |  |  |  |           case Event.ACTION_CALL_DECLINE: | 
		
	
		
			
				|  |  |  |  |            // cProv.isIncomingCall = true; | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("isIncomingCall", "false"); | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("inComingCallData", "null"); | 
		
	
		
			
				|  |  |  |  |              | 
		
	
		
			
				|  |  |  |  |            // cProv.endCall(isUserOnline: true); | 
		
	
		
			
				|  |  |  |  |             FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |             declineCall(); | 
		
	
		
			
				|  |  |  |  |             break; | 
		
	
		
			
				|  |  |  |  |           case Event.ACTION_CALL_ENDED: | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("isIncomingCall", "false"); | 
		
	
	
		
			
				
					|  |  |  | @ -164,40 +170,44 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |           case Event.ACTION_CALL_TIMEOUT: | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("isIncomingCall", "false"); | 
		
	
		
			
				|  |  |  |  |             Utils.saveStringFromPrefs("inComingCallData", "null"); | 
		
	
		
			
				|  |  |  |  |             FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |             break; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  |     } on Exception {} | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void nothing() { | 
		
	
		
			
				|  |  |  |  |     // if (!background) { | 
		
	
		
			
				|  |  |  |  |     //   await initProviders(); | 
		
	
		
			
				|  |  |  |  |     //   if (data!.data["callType"] == "video") { | 
		
	
		
			
				|  |  |  |  |     //     cProv.isVideoCall = true; | 
		
	
		
			
				|  |  |  |  |     //   } else { | 
		
	
		
			
				|  |  |  |  |     //     cProv.isAudioCall = true; | 
		
	
		
			
				|  |  |  |  |     //     cProv.isVideoCall = false; | 
		
	
		
			
				|  |  |  |  |     //   } | 
		
	
		
			
				|  |  |  |  |     // } | 
		
	
		
			
				|  |  |  |  |     // | 
		
	
		
			
				|  |  |  |  |     // // if(!background){} | 
		
	
		
			
				|  |  |  |  |     // await initProviders(); | 
		
	
		
			
				|  |  |  |  |   Future<void> declineCall() async { | 
		
	
		
			
				|  |  |  |  |     if (isUserOnline) { | 
		
	
		
			
				|  |  |  |  |       if (chatHubConnection.state == HubConnectionState.Connected) { | 
		
	
		
			
				|  |  |  |  |         if (sessionData?.extra != null) { | 
		
	
		
			
				|  |  |  |  |           chatHubConnection.invoke("HangUpAsync", args: [ | 
		
	
		
			
				|  |  |  |  |             int.parse(sessionData.extra!.callerDetails!.currentUserId.toString()), | 
		
	
		
			
				|  |  |  |  |             int.parse(sessionData.extra!.callerDetails!.targetUserId.toString()), | 
		
	
		
			
				|  |  |  |  |           ]); | 
		
	
		
			
				|  |  |  |  |           chatHubConnection.invoke("UpdateUserStatusAsync", args: [ | 
		
	
		
			
				|  |  |  |  |             int.parse(sessionData.extra!.callerDetails!.currentUserId.toString()), | 
		
	
		
			
				|  |  |  |  |             1, | 
		
	
		
			
				|  |  |  |  |           ]); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     //   callData = jsonEncode([ | 
		
	
		
			
				|  |  |  |  |     //       { | 
		
	
		
			
				|  |  |  |  |     //         "loginDetails": autoLoginData.toJson(), | 
		
	
		
			
				|  |  |  |  |     //         "callerDetails": callerData.toJson(), | 
		
	
		
			
				|  |  |  |  |     //       } | 
		
	
		
			
				|  |  |  |  |     //     ]); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     // connection(data: callData, isUserOnline: isUserOnline).whenComplete(() => {}); | 
		
	
		
			
				|  |  |  |  |     // if (isUserOnline) { | 
		
	
		
			
				|  |  |  |  |     //   cProv.init(); | 
		
	
		
			
				|  |  |  |  |     // } | 
		
	
		
			
				|  |  |  |  |     // if (!isUserOnline) { | 
		
	
		
			
				|  |  |  |  |     //   initProviders(); | 
		
	
		
			
				|  |  |  |  |     // } | 
		
	
		
			
				|  |  |  |  |     // Navigator.pushNamed(AppRoutes.navigatorKey.currentContext!, AppRoutes.chatStartCall); | 
		
	
		
			
				|  |  |  |  |           FlutterCallkitIncoming.endCall(sessionData.id!); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); | 
		
	
		
			
				|  |  |  |  |       HubConnection hc = HubConnectionBuilder() | 
		
	
		
			
				|  |  |  |  |           .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${sessionData.extra!.loginDetails!.id}&source=Desktop&access_token=${sessionData.extra?.loginDetails!.token}", options: httpOp) | 
		
	
		
			
				|  |  |  |  |           .withAutomaticReconnect(retryDelays: <int>[2000, 5000, 10000, 20000]).build(); | 
		
	
		
			
				|  |  |  |  |       await hc.start(); | 
		
	
		
			
				|  |  |  |  |       await hc.invoke( | 
		
	
		
			
				|  |  |  |  |         "HangUpAsync", | 
		
	
		
			
				|  |  |  |  |         args: [ | 
		
	
		
			
				|  |  |  |  |           int.parse(sessionData.extra!.callerDetails!.currentUserId.toString()), | 
		
	
		
			
				|  |  |  |  |           int.parse(sessionData.extra!.callerDetails!.targetUserId.toString()), | 
		
	
		
			
				|  |  |  |  |         ], | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |       FlutterCallkitIncoming.endCall(sessionData.id!); | 
		
	
		
			
				|  |  |  |  |       hc.stop(); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | 
 |