|  |  |  | @ -1,8 +1,11 @@ | 
		
	
		
			
				|  |  |  |  | import 'dart:convert'; | 
		
	
		
			
				|  |  |  |  | import 'dart:io'; | 
		
	
		
			
				|  |  |  |  | import 'package:firebase_messaging/firebase_messaging.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/services.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_callkit_incoming/entities/entities.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:logger/logger.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/app_state/app_state.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/consts.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -14,6 +17,7 @@ import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' a | 
		
	
		
			
				|  |  |  |  | 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:path_provider/path_provider.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:signalr_netcore/hub_connection.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:signalr_netcore/signalr_client.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:workmanager/workmanager.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -64,8 +68,6 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |       duration: 20000, | 
		
	
		
			
				|  |  |  |  |       textAccept: 'Accept', | 
		
	
		
			
				|  |  |  |  |       textDecline: 'Decline', | 
		
	
		
			
				|  |  |  |  |       textMissedCall: 'Missed call', | 
		
	
		
			
				|  |  |  |  |       textCallback: 'Call back', | 
		
	
		
			
				|  |  |  |  |       extra: { | 
		
	
		
			
				|  |  |  |  |         "loginDetails": autoLoginData.toJson(), | 
		
	
		
			
				|  |  |  |  |         "callerDetails": callerData.toJson(), | 
		
	
	
		
			
				
					|  |  |  | @ -76,8 +78,6 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  |       android: const AndroidParams( | 
		
	
		
			
				|  |  |  |  |         isCustomNotification: true, | 
		
	
		
			
				|  |  |  |  |         isShowLogo: false, | 
		
	
		
			
				|  |  |  |  |         isShowCallback: false, | 
		
	
		
			
				|  |  |  |  |         isShowMissedCallNotification: true, | 
		
	
		
			
				|  |  |  |  |         ringtonePath: 'system_ringtone_default', | 
		
	
		
			
				|  |  |  |  |         backgroundColor: '#0955fa', | 
		
	
		
			
				|  |  |  |  |         backgroundUrl: 'assets/test.png', | 
		
	
	
		
			
				
					|  |  |  | @ -108,33 +108,49 @@ class ChatVoipCall { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> declineCall({var payload}) async { | 
		
	
		
			
				|  |  |  |  |     IncomingCallModel data = IncomingCallModel.fromJson(jsonDecode(payload)); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (isUserOnline) { | 
		
	
		
			
				|  |  |  |  |       HubConnection _hc = await makeHub(sessionData: data); | 
		
	
		
			
				|  |  |  |  |       await _hc.start(); | 
		
	
		
			
				|  |  |  |  |       if (_hc.state == HubConnectionState.Connected) { | 
		
	
		
			
				|  |  |  |  |         if (data.extra != null) { | 
		
	
		
			
				|  |  |  |  |           _hc.invoke("HangUpAsync", args: [ | 
		
	
		
			
				|  |  |  |  |             data.extra!.callerDetails!.currentUserId!, | 
		
	
		
			
				|  |  |  |  |             data.extra!.callerDetails!.targetUserId!, | 
		
	
		
			
				|  |  |  |  |           ]); | 
		
	
		
			
				|  |  |  |  |           _hc.invoke("UpdateUserStatusAsync", args: [ | 
		
	
		
			
				|  |  |  |  |             int.parse(data.extra!.callerDetails!.currentUserId.toString()), | 
		
	
		
			
				|  |  |  |  |             1, | 
		
	
		
			
				|  |  |  |  |           ]); | 
		
	
		
			
				|  |  |  |  |           await _hc.invoke("HangUpAsync", args: [data.extra!.callerDetails!.currentUserId!, data.extra!.callerDetails!.targetUserId!]); | 
		
	
		
			
				|  |  |  |  |           await _hc.invoke("UpdateUserStatusAsync", args: [int.parse(data.extra!.callerDetails!.currentUserId.toString()), 1]); | 
		
	
		
			
				|  |  |  |  |           FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |           chatHubConnection = _hc; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       try { | 
		
	
		
			
				|  |  |  |  |         var response = await platform.invokeMethod( | 
		
	
		
			
				|  |  |  |  |             'executeHttpPostRequest', {"currentUserID": data.extra!.callerDetails!.targetUserId, "targetUserID": data.extra!.callerDetails!.currentUserId, "token": data.extra!.loginDetails!.token}); | 
		
	
		
			
				|  |  |  |  |         print('HTTP POST response: $response'); | 
		
	
		
			
				|  |  |  |  |       } on PlatformException catch (e) { | 
		
	
		
			
				|  |  |  |  |         print('Error invoking method: ${e.message}'); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       // await ChatApiClient().callDecline(cUserID: data.extra!.callerDetails!.targetUserId!, tUserID: data.extra!.callerDetails!.currentUserId!, targetUsertoken: data.extra!.loginDetails!.token!); | 
		
	
		
			
				|  |  |  |  |       // Future.delayed(const Duration(seconds: 3), () { | 
		
	
		
			
				|  |  |  |  |       //   ChatApiClient().callDecline(cUserID: data.extra!.callerDetails!.targetUserId!, tUserID: data.extra!.callerDetails!.currentUserId!, targetUsertoken: data.extra!.loginDetails!.token!); | 
		
	
		
			
				|  |  |  |  |       // }); | 
		
	
		
			
				|  |  |  |  |       // HubConnection _hc = await makeHub(sessionData: data); | 
		
	
		
			
				|  |  |  |  |       // await _hc.start(); | 
		
	
		
			
				|  |  |  |  |       // if (_hc.state == HubConnectionState.Connected) { | 
		
	
		
			
				|  |  |  |  |       //   logger.log(Level.info, "HUB-EVENT"); | 
		
	
		
			
				|  |  |  |  |       //   await _hc.invoke("HangUpAsync", args: [ | 
		
	
		
			
				|  |  |  |  |       //     data.extra!.callerDetails!.currentUserId!, | 
		
	
		
			
				|  |  |  |  |       //     data.extra!.callerDetails!.targetUserId!, | 
		
	
		
			
				|  |  |  |  |       //   ]); | 
		
	
		
			
				|  |  |  |  |       //   FlutterCallkitIncoming.endAllCalls(); | 
		
	
		
			
				|  |  |  |  |       //   await _hc.stop(); | 
		
	
		
			
				|  |  |  |  |       // } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     // | 
		
	
		
			
				|  |  |  |  |     // try { | 
		
	
		
			
				|  |  |  |  |     //   var response = await platform.invokeMethod( | 
		
	
		
			
				|  |  |  |  |     //       'executeHttpPostRequest', {"currentUserID": data.extra!.callerDetails!.targetUserId, "targetUserID": data.extra!.callerDetails!.currentUserId, "token": data.extra!.loginDetails!.token}); | 
		
	
		
			
				|  |  |  |  |     //   print('HTTP POST response: $response'); | 
		
	
		
			
				|  |  |  |  |     //   Future.delayed(Duration(seconds: 3), () { | 
		
	
		
			
				|  |  |  |  |     //     ChatApiClient().callDecline(cUserID: data.extra!.callerDetails!.targetUserId!, tUserID: data.extra!.callerDetails!.currentUserId!, targetUsertoken: data.extra!.loginDetails!.token!); | 
		
	
		
			
				|  |  |  |  |     //   }); | 
		
	
		
			
				|  |  |  |  |     // } on PlatformException catch (e) { | 
		
	
		
			
				|  |  |  |  |     //   print('Error invoking method: ${e.message}'); | 
		
	
		
			
				|  |  |  |  |     // } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | //await ChatApiClient().callDecline(cUserID: data.extra!.callerDetails!.targetUserId!, tUserID: data.extra!.callerDetails!.currentUserId!, targetUsertoken: data.extra!.loginDetails!.token!); | 
		
	
		
			
				|  |  |  |  | // logger.log(Level.error, "API-EVENT-END"); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<HubConnection> makeHub({required IncomingCallModel sessionData}) async { | 
		
	
	
		
			
				
					|  |  |  | 
 |