|  |  |  | @ -15,6 +15,7 @@ import 'package:mohem_flutter_app/models/chat/webrtc_payloads.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/ui/chat/call/start_call_screen.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:signalr_netcore/hub_connection.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:uuid/uuid.dart'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
	
		
			
				
					|  |  |  | @ -136,9 +137,13 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> endCall() async { | 
		
	
		
			
				|  |  |  |  |     if (isIncomingCall) { | 
		
	
		
			
				|  |  |  |  |       await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |       await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |       _pc.dispose(); | 
		
	
		
			
				|  |  |  |  |       if (chatHubConnection.state == HubConnectionState.Connected) { | 
		
	
		
			
				|  |  |  |  |         await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |         await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) { | 
		
	
		
			
				|  |  |  |  |         _pc.dispose(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       isCallStarted = false; | 
		
	
		
			
				|  |  |  |  |       isVideoCall = false; | 
		
	
		
			
				|  |  |  |  |       isCamOff = false; | 
		
	
	
		
			
				
					|  |  |  | @ -149,9 +154,13 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |       isIncomingCall = false; | 
		
	
		
			
				|  |  |  |  |       return true; | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |       await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |       _pc.dispose(); | 
		
	
		
			
				|  |  |  |  |       if (chatHubConnection.state == HubConnectionState.Connected) { | 
		
	
		
			
				|  |  |  |  |         await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |         await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) { | 
		
	
		
			
				|  |  |  |  |         _pc.dispose(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       isCallStarted = false; | 
		
	
		
			
				|  |  |  |  |       isVideoCall = false; | 
		
	
		
			
				|  |  |  |  |       isCamOff = false; | 
		
	
	
		
			
				
					|  |  |  | @ -421,16 +430,35 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |       logger.i("rtc ice gathering state: " + state.name); | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  |     pc!.onIceConnectionState = (RTCIceConnectionState state) { | 
		
	
		
			
				|  |  |  |  |       // invoke( | 
		
	
		
			
				|  |  |  |  |       //     invokeMethod: "InvokeMobile", | 
		
	
		
			
				|  |  |  |  |       //     currentUserID: AppState().getchatUserDetails!.response!.id!, | 
		
	
		
			
				|  |  |  |  |       //     targetUserID: incomingCallData.targetUserId!, | 
		
	
		
			
				|  |  |  |  |       //     debugData: {"location": "onIceConnection", "parms": state.name}); | 
		
	
		
			
				|  |  |  |  |       if (RTCIceConnectionState.RTCIceConnectionStateFailed == state || | 
		
	
		
			
				|  |  |  |  |           RTCIceConnectionState.RTCIceConnectionStateDisconnected == state || | 
		
	
		
			
				|  |  |  |  |           RTCIceConnectionState.RTCIceConnectionStateClosed == state) { | 
		
	
		
			
				|  |  |  |  |         logger.i("Ice Connection State:" + state.name); | 
		
	
		
			
				|  |  |  |  |         endCall(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  |     pc!.onRenegotiationNeeded = () {}; | 
		
	
		
			
				|  |  |  |  |     pc!.onRenegotiationNeeded = _onRenegotiate; | 
		
	
		
			
				|  |  |  |  |     return pc; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void _onRenegotiate() async { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       print('onRenegotiationNeeded start'); | 
		
	
		
			
				|  |  |  |  |       //  makingOffer = true; | 
		
	
		
			
				|  |  |  |  |       await _pc.setLocalDescription(await _pc.createOffer(videoConstraints)); | 
		
	
		
			
				|  |  |  |  |       print('onRenegotiationNeeded state after setLocalDescription: ' + _pc.signalingState.toString()); | 
		
	
		
			
				|  |  |  |  |       // send offer via callManager | 
		
	
		
			
				|  |  |  |  |       var localDesc = await _pc.getLocalDescription(); | 
		
	
		
			
				|  |  |  |  |       // callManager.sendCallMessage(MsgType.rtc_offer, RtcOfferAnswer(localDesc.sdp, localDesc.type)); | 
		
	
		
			
				|  |  |  |  |       print('onRenegotiationNeeded; offer sent'); | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       print("onRenegotiationNeeded error: " + e.toString()); | 
		
	
		
			
				|  |  |  |  |     } finally { | 
		
	
		
			
				|  |  |  |  |       //   makingOffer = false; | 
		
	
		
			
				|  |  |  |  |       print('onRenegotiationNeeded done'); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void playRingtone() async { | 
		
	
		
			
				|  |  |  |  |     player.stop(); | 
		
	
		
			
				|  |  |  |  |     await player.setVolume(1.0); | 
		
	
	
		
			
				
					|  |  |  | 
 |