@ -9,8 +9,10 @@ import 'package:diplomaticquarterapp/uitl/navigation_service.dart';
import ' package:diplomaticquarterapp/uitl/utils.dart ' ;
import ' package:diplomaticquarterapp/voipcall/call/chat_incoming_call_screen.dart ' ;
import ' package:diplomaticquarterapp/voipcall/consts.dart ' ;
import ' package:diplomaticquarterapp/voipcall/model/call.dart ' ;
import ' package:diplomaticquarterapp/voipcall/model/get_single_user_chat_call.dart ' ;
import ' package:diplomaticquarterapp/voipcall/model/get_user_login_token.dart ' ;
import ' package:diplomaticquarterapp/voipcall/model/webrtc_payloads.dart ' ;
import ' package:flutter/foundation.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter_callkit_incoming/flutter_callkit_incoming.dart ' ;
@ -90,7 +92,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
HubConnection hub ;
HttpConnectionOptions httpOp = HttpConnectionOptions ( skipNegotiation: false , logMessageContent: true ) ;
hub = HubConnectionBuilder ( )
. withUrl ( ApiConsts . chatHubConnectionUrl + " ?UserId= ${ AppState ( ) . chatDetails . response . id } &source=Desktop&access_token= ${ AppState ( ) . chatDetails . response . token } " , options: httpOp )
. withUrl ( ApiConsts . chatHubConnectionUrl + " ?UserId= ${ AppState ( ) . chatDetails ! . response ! . id } &source=Desktop&access_token= ${ AppState ( ) . chatDetails ! . response ! . token } " , options: httpOp )
. withAutomaticReconnect ( retryDelays: < int > [ 2000 , 5000 , 10000 , 20000 ] ) . build ( ) ;
return hub ;
}
@ -99,11 +101,11 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( kDebugMode ) {
print ( " =================== Call Listeners Registered ======================= " ) ;
}
chatHubConnection ! . on ( " OnCallAcceptedAsync " , onCallAcceptedAsync ! ) ;
chatHubConnection ! . on ( " OnIceCandidateAsync " , onIceCandidateAsync ! ) ;
chatHubConnection ! . on ( " OnOfferAsync " , onOfferAsync ! ) ;
chatHubConnection ! . on ( " OnAnswerOffer " , onAnswerOffer ! ) ;
chatHubConnection ! . on ( " OnHangUpAsync " , onHangUpAsync ! ) ;
chatHubConnection ! . on ( " OnCallAcceptedAsync " , onCallAcceptedAsync ) ;
chatHubConnection ! . on ( " OnIceCandidateAsync " , onIceCandidateAsync ) ;
chatHubConnection ! . on ( " OnOfferAsync " , onOfferAsync ) ;
chatHubConnection ! . on ( " OnAnswerOffer " , onAnswerOffer ) ;
chatHubConnection ! . on ( " OnHangUpAsync " , onHangUpAsync ) ;
/ / chatHubConnection ! . on ( " OnCallDeclinedAsync " , onCallDeclinedAsync ) ;
/ / chatHubConnection ! . on ( " OnIncomingCallAsync " , OnIncomingCallAsync ) ;
}
@ -126,12 +128,11 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / OutGoing Call / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Future < void > initLocalCamera ( { callData , BuildContext context , bool isIncomingCall = false } ) async {
Future < void > initLocalCamera ( { callData , BuildContext ? context , bool isIncomingCall = false } ) async {
isCallEnded = false ;
outGoingCallData = callData ;
await initStreams ( ) ;
await startCall ( callType: isVideoCall ? " Video " : " Audio " , context: context ) ;
await startCall ( callType: isVideoCall ? " Video " : " Audio " ) ;
_pc = await creatOfferWithCon ( ) ;
connectOutgoing ( ) ;
notifyListeners ( ) ;
@ -142,7 +143,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / notifyListeners ( ) ;
}
Future < void > startCall ( { String callType , BuildContext context } ) async {
Future < void > startCall ( { String ? callType } ) async {
/ / chatProvModel . isTextMsg = true ;
/ / chatProvModel . isAttachmentMsg = false ;
/ / chatProvModel . isVoiceMsg = false ;
@ -158,10 +159,10 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / ) ;
await invoke (
invokeMethod: " CallUserAsync " ,
currentUserID: outGoingCallData . callerId ,
targetUserID: outGoingCallData . receiverId ,
currentUserID: outGoingCallData ! . callerId ! ,
targetUserID: outGoingCallData ! . receiverId ! ,
) ;
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: outGoingCallData . callerId , targetUserID: outGoingCallData . receiverId , userStatus: 4 ) ;
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: outGoingCallData ! . callerId ! , targetUserID: outGoingCallData ! . receiverId ! , userStatus: 4 ) ;
}
/ / OutGoing Listeners
@ -169,8 +170,8 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
dynamic items = params ! . toList ( ) ;
RTCSessionDescription description = await _createOffer ( ) ;
await _pc ! . setLocalDescription ( description ) ;
dynamic payload = { " target " : items [ 0 ] [ " id " ] , " caller " : outGoingCallData . callerId , " sdp " : description . toMap ( ) } ;
invoke ( invokeMethod: " OfferAsync " , currentUserID: outGoingCallData . callerId , targetUserID: items [ 0 ] [ " id " ] , data: jsonEncode ( payload ) ) ;
dynamic payload = { " target " : items [ 0 ] [ " id " ] , " caller " : outGoingCallData ! . callerId , " sdp " : description . toMap ( ) } ;
invoke ( invokeMethod: " OfferAsync " , currentUserID: outGoingCallData ! . callerId ! , targetUserID: items [ 0 ] [ " id " ] , data: jsonEncode ( payload ) ) ;
}
Future < void > onIceCandidateAsync ( List < Object ? > ? params ) async {
@ -178,7 +179,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( isIncomingCall ) {
RemoteIceCandidatePayLoad data = RemoteIceCandidatePayLoad . fromJson ( jsonDecode ( items . first . toString ( ) ) ) ;
if ( _pc ! = null ) {
await _pc . addCandidate ( RTCIceCandidate ( data . candidate . candidate , data . candidate . sdpMid , data . candidate . sdpMLineIndex ) ) ;
await _pc ! . addCandidate ( RTCIceCandidate ( data . candidate ! . candidate , data . candidate ! . sdpMid , data . candidate ! . sdpMLineIndex ) ) ;
}
} else {
if ( kDebugMode ) {
@ -186,7 +187,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
}
RemoteIceCandidatePayLoad data = RemoteIceCandidatePayLoad . fromJson ( jsonDecode ( items . first . toString ( ) ) ) ;
if ( _pc ! = null ) {
await _pc . addCandidate ( RTCIceCandidate ( data . candidate . candidate , data . candidate . sdpMid , data . candidate . sdpMLineIndex ) ) ;
await _pc ! . addCandidate ( RTCIceCandidate ( data . candidate ! . candidate , data . candidate ! . sdpMid , data . candidate ! . sdpMLineIndex ) ) ;
if ( ! isCallStarted ) {
isCallStarted = true ;
notifyListeners ( ) ;
@ -196,14 +197,14 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( Platform . isIOS ) {
Future . delayed ( Duration ( seconds: 2 ) , ( ) {
Navigator . pushReplacement (
providerContext ,
providerContext ! ,
MaterialPageRoute (
builder: ( BuildContext context ) = > StartCallPage ( ) ,
) ) ;
} ) ;
} else {
Navigator . pushReplacement (
providerContext ,
providerContext ! ,
MaterialPageRoute (
builder: ( BuildContext context ) = > StartCallPage ( ) ,
) ) ;
@ -222,8 +223,8 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
_pc ! . setRemoteDescription ( RTCSessionDescription ( data [ 0 ] [ " sdp " ] [ " sdp " ] , data [ 0 ] [ " sdp " ] [ " type " ] ) ) ;
RTCSessionDescription description = await _createAnswer ( ) ;
await _pc ! . setLocalDescription ( description ) ;
dynamic payload = { " target " : data [ 0 ] [ " caller " ] , " caller " : AppState ( ) . chatDetails . response . id , " sdp " : description . toMap ( ) } ;
invoke ( invokeMethod: " AnswerOfferAsync " , currentUserID: AppState ( ) . chatDetails . response . id , targetUserID: incomingCallData . targetUserId , data: jsonEncode ( payload ) ) ;
dynamic payload = { " target " : data [ 0 ] [ " caller " ] , " caller " : AppState ( ) . chatDetails ! . response ! . id ! , " sdp " : description . toMap ( ) } ;
invoke ( invokeMethod: " AnswerOfferAsync " , currentUserID: AppState ( ) . chatDetails ! . response ! . id ! , targetUserID: incomingCallData ! . targetUserId ! , data: jsonEncode ( payload ) ) ;
}
/ / else {
/ / RTCSessionDescription description = await _createAnswer ( ) ;
@ -240,8 +241,8 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( isIncomingCall ) {
print ( " -----------------------Endeddddd By Me--------------------------- " ) ;
if ( chatHubConnection ! . state = = HubConnectionState . Connected ) {
await invoke ( invokeMethod: " HangUpAsync " , currentUserID: AppState ( ) . chatDetails . response . id , targetUserID: incomingCallData . targetUserId , userStatus: 0 ) ;
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: 0 ) ;
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: AppState ( ) . chatDetails ! . response ! . id ! , targetUserID: incomingCallData ! . targetUserId ! , userStatus: 1 ) ;
}
isCallStarted = false ;
isVideoCall = false ;
@ -253,38 +254,38 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
isAudioCall = false ;
if ( isCallConnected ) {
if ( _pc . connectionState = = RTCPeerConnectionState . RTCPeerConnectionStateConnected ) {
if ( _pc ! . connectionState = = RTCPeerConnectionState . RTCPeerConnectionStateConnected ) {
if ( kDebugMode ) {
print ( " ------------------ PC Stopped ---------------------------- " ) ;
}
_pc . close ( ) ;
_pc . dispose ( ) ;
_pc ! . close ( ) ;
_pc ! . dispose ( ) ;
}
}
if ( remoteRenderer ! = null ) {
remoteRenderer . dispose ( ) ;
remoteRenderer ! . dispose ( ) ;
remoteRenderer = null ;
}
if ( localVideoRenderer ! = null ) {
localVideoRenderer . dispose ( ) ;
localVideoRenderer ! . dispose ( ) ;
localVideoRenderer = null ;
}
if ( _localStream ! = null ) {
_localStream . dispose ( ) ;
_localStream ! . dispose ( ) ;
_localStream = null ;
}
if ( chatHubConnection ! = null & & ! isUserOnline ) {
chatHubConnection . stop ( ) ;
if ( chatHubConnection ! = null & & ! isUserOnline ! ) {
chatHubConnection ! . stop ( ) ;
}
await FlutterCallkitIncoming . endAllCalls ( ) ;
return true ;
} else {
if ( isOutGoingCall ) {
await invoke ( invokeMethod: " HangUpAsync " , currentUserID: outGoingCallData . callerId , targetUserID: outGoingCallData . receiverId , userStatus: 1 ) ;
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: outGoingCallData . callerId , targetUserID: outGoingCallData . receiverId , userStatus: 1 ) ;
await invoke ( invokeMethod: " HangUpAsync " , currentUserID: outGoingCallData ! . callerId ! , targetUserID: outGoingCallData ! . receiverId ! , userStatus: 1 ) ;
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: outGoingCallData ! . callerId ! , targetUserID: outGoingCallData ! . receiverId ! , userStatus: 1 ) ;
} else if ( isIncomingCall ) {
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: AppState ( ) . chatDetails . response . id , targetUserID: incomingCallData . targetUserId , userStatus: 1 ) ;
await invoke ( invokeMethod: " UpdateUserStatusAsync " , currentUserID: AppState ( ) . chatDetails ! . response ! . id ! , targetUserID: incomingCallData ! . targetUserId ! , userStatus: 1 ) ;
}
isCallStarted = false ;
isVideoCall = false ;
@ -292,22 +293,22 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
isMicOff = false ;
isLoudSpeaker = false ;
if ( isCallConnected ) {
if ( _pc . connectionState = = RTCPeerConnectionState . RTCPeerConnectionStateConnected ) {
_pc . close ( ) ;
_pc . dispose ( ) ;
if ( _pc ! . connectionState = = RTCPeerConnectionState . RTCPeerConnectionStateConnected ) {
_pc ! . close ( ) ;
_pc ! . dispose ( ) ;
}
}
if ( remoteRenderer ! = null ) {
remoteRenderer . dispose ( ) ;
remoteRenderer ! . dispose ( ) ;
remoteRenderer = null ;
}
if ( localVideoRenderer ! = null ) {
localVideoRenderer . dispose ( ) ;
localVideoRenderer ! . dispose ( ) ;
localVideoRenderer = null ;
}
if ( _localStream ! = null ) {
_localStream . dispose ( ) ;
_localStream ! . dispose ( ) ;
_localStream = null ;
}
isOutGoingCall = false ;
@ -319,29 +320,29 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / Incoming Listeners
void onAnswerOffer ( List < Object > payload ) async {
void onAnswerOffer ( List < Object ? >? payload ) async {
/ / if ( isIncomingCall ) {
/ / / / print ( " --------------------- On Answer Offer Async --------------------------------------- " ) ;
/ / / / await invoke ( invokeMethod: " InvokeMobile " , currentUserID: AppState ( ) . getchatUserDetails ! . response ! . id ! , targetUserID: incomingCallData . targetUserId ! , debugData: { " On Answer Offer Async " } ) ;
/ / } else {
var items = payload . toList ( ) ;
var items = payload ! . toList ( ) ;
if ( kDebugMode ) {
print ( " res: " + items . toString ( ) ) ;
}
CallSessionPayLoad data = CallSessionPayLoad . fromJson ( jsonDecode ( items . first . toString ( ) ) ) ;
RTCSessionDescription description = RTCSessionDescription ( data . sdp . sdp , ' answer ' ) ;
_pc . setRemoteDescription ( description ) ;
RTCSessionDescription description = RTCSessionDescription ( data . sdp ! . sdp , ' answer ' ) ;
_pc ! . setRemoteDescription ( description ) ;
/ / }
}
void onHangUpAsync ( List < Object > params ) {
void onHangUpAsync ( List < Object ? >? params ) {
print ( " --------------------- onHangUp ASYNC --------------------------------- " ) ;
dynamic items = params . toList ( ) ;
dynamic items = params ! . toList ( ) ;
/ / if ( kDebugMode ) {
/ / logger . i ( " res: " + items . toString ( ) ) ;
/ / }
if ( items [ 0 ] [ " id " ] ! = AppState ( ) . chatDetails . response . id ) {
if ( items [ 0 ] [ " id " ] ! = AppState ( ) . chatDetails ! . response ! . id ! ) {
if ( kDebugMode ) {
print ( " Call Ended By Other User " ) ;
}
@ -350,12 +351,12 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( isCallConnected & & isUserOnline ) {
isCallConnected = false ;
if ( ! AppState ( ) . isLogged ) {
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . pop ( ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . pop ( ) ;
} else {
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . popUntil ( ModalRoute . withName ( HOME ) ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . popUntil ( ModalRoute . withName ( HOME ) ) ;
}
} else {
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . pop ( ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . pop ( ) ;
}
} ) ;
} else {
@ -363,9 +364,9 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
endCall ( isUserOnline: isUserOnline ) . then ( ( bool value ) {
if ( isCallConnected & & isUserOnline ) {
isCallConnected = false ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . popUntil ( ModalRoute . withName ( HOME ) ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . popUntil ( ModalRoute . withName ( HOME ) ) ;
} else {
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . pop ( ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . pop ( ) ;
}
} ) ;
}
@ -377,9 +378,9 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( isOutGoingCall ) {
if ( isCallConnected & & isUserOnline ) {
isCallConnected = false ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . popUntil ( ModalRoute . withName ( HOME ) ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . popUntil ( ModalRoute . withName ( HOME ) ) ;
} else {
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ) . pop ( ) ;
Navigator . of ( locator < NavigationService > ( ) . navigatorKey . currentContext ! ) . pop ( ) ;
}
}
}
@ -388,7 +389,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / Navigator . of ( AppRoutes . navigatorKey . currentContext ! ) . popUntil ( ModalRoute . withName ( AppRoutes . chatDetailed ) ) ;
/ / isCallConnected = false ;
/ / }
/ / if ( items [ 0 ] [ " id " ] ! = AppState ( ) . chatDetails ! . response ! . id & & ! AppState ( ) . isBackgroundCall ) {
/ / if ( items [ 0 ] [ " id " ] ! = AppState ( ) . chatDetails ! ! . response ! . id & & ! AppState ( ) . isBackgroundCall ) {
/ / if ( kDebugMode ) {
/ / print ( " Popped Due to Another User " ) ;
/ / }
@ -418,12 +419,12 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / / / " callerEmail " : items [ 0 ] [ " email " ] ,
/ / / / " callerTitle " : items [ 0 ] [ " title " ] ,
/ / / / " callerPhone " : null ,
/ / / / " receiverID " : AppState ( ) . chatDetails ! . response ! . id ,
/ / / / " receiverName " : AppState ( ) . chatDetails ! . response ! . userName ,
/ / / / " receiverEmail " : AppState ( ) . chatDetails ! . response ! . email ,
/ / / / " receiverTitle " : AppState ( ) . chatDetails ! . response ! . title ,
/ / / / " receiverPhone " : AppState ( ) . chatDetails ! . response ! . phone ,
/ / / / " title " : AppState ( ) . chatDetails ! . response ! . userName ! . replaceAll ( " . " , " " ) ,
/ / / / " receiverID " : AppState ( ) . chatDetails ! ! . response ! . id ,
/ / / / " receiverName " : AppState ( ) . chatDetails ! ! . response ! . userName ,
/ / / / " receiverEmail " : AppState ( ) . chatDetails ! ! . response ! . email ,
/ / / / " receiverTitle " : AppState ( ) . chatDetails ! ! . response ! . title ,
/ / / / " receiverPhone " : AppState ( ) . chatDetails ! ! . response ! . phone ,
/ / / / " title " : AppState ( ) . chatDetails ! ! . response ! . userName ! . replaceAll ( " . " , " " ) ,
/ / / / " callType " : items [ 1 ] ? " Video " : " Audio " ,
/ / / / } ;
/ / / / CallDataModel callData = CallDataModel . fromJson ( json ) ;
@ -436,12 +437,12 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / / / " callerEmail " : items [ 0 ] [ " email " ] ,
/ / / / " callerTitle " : items [ 0 ] [ " title " ] ,
/ / / / " callerPhone " : null ,
/ / / / " receiverID " : AppState ( ) . chatDetails ! . response ! . id ,
/ / / / " receiverName " : AppState ( ) . chatDetails ! . response ! . userName ,
/ / / / " receiverEmail " : AppState ( ) . chatDetails ! . response ! . email ,
/ / / / " receiverTitle " : AppState ( ) . chatDetails ! . response ! . title ,
/ / / / " receiverPhone " : AppState ( ) . chatDetails ! . response ! . phone ,
/ / / / " title " : AppState ( ) . chatDetails ! . response ! . userName ! . replaceAll ( " . " , " " ) ,
/ / / / " receiverID " : AppState ( ) . chatDetails ! ! . response ! . id ,
/ / / / " receiverName " : AppState ( ) . chatDetails ! ! . response ! . userName ,
/ / / / " receiverEmail " : AppState ( ) . chatDetails ! ! . response ! . email ,
/ / / / " receiverTitle " : AppState ( ) . chatDetails ! ! . response ! . title ,
/ / / / " receiverPhone " : AppState ( ) . chatDetails ! ! . response ! . phone ,
/ / / / " title " : AppState ( ) . chatDetails ! ! . response ! . userName ! . replaceAll ( " . " , " " ) ,
/ / / / " callType " : items [ 1 ] ? " Video " : " Audio " ,
/ / / / } ;
/ / / / CallDataModel callData = CallDataModel . fromJson ( json ) ;
@ -480,7 +481,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / / / Invoke Methods
Future < void > invoke ( { String invokeMethod , int currentUserID , int targetUserID , var data , int userStatus = 1 , var debugData } ) async {
Future < void > invoke ( { required String invokeMethod , required int currentUserID , required int targetUserID , var data , int userStatus = 1 , var debugData } ) async {
List < Object > args = [ ] ;
if ( invokeMethod = = " CallUserAsync " ) {
args = [ currentUserID , targetUserID , isVideoCall ] ;
@ -501,17 +502,17 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
args = [ debugData ] ;
}
try {
await chatHubConnection . invoke ( " $ invokeMethod " , args: args ) ;
await chatHubConnection ! . invoke ( " $ invokeMethod " , args: args ) ;
} catch ( e ) {
print ( e ) ;
}
}
void stopListeners ( ) async {
chatHubConnection . off ( ' OnCallDeclinedAsync ' ) ;
chatHubConnection . off ( ' OnCallAcceptedAsync ' ) ;
chatHubConnection . off ( ' OnIceCandidateAsync ' ) ;
chatHubConnection . off ( ' OnAnswerOffer ' ) ;
chatHubConnection ! . off ( ' OnCallDeclinedAsync ' ) ;
chatHubConnection ! . off ( ' OnCallAcceptedAsync ' ) ;
chatHubConnection ! . off ( ' OnIceCandidateAsync ' ) ;
chatHubConnection ! . off ( ' OnAnswerOffer ' ) ;
}
void playRingtone ( ) async {
@ -559,24 +560,24 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / await pc . addStream ( _localStream ! ) ;
/ / Changed By Aamir
_localStream ? . getTracks ( ) . forEach ( ( track ) {
pc . addTrack ( track , _localStream ) ;
pc . addTrack ( track , _localStream ! ) ;
} ) ;
pc . onConnectionState = ( RTCPeerConnectionState state ) { } ;
pc . onAddStream = ( MediaStream stream ) {
remoteRenderer . srcObject = stream ;
remoteRenderer ! . srcObject = stream ;
notifyListeners ( ) ;
} ;
pc . onIceCandidate = ( RTCIceCandidate e ) async {
if ( isIncomingCall ) {
if ( e . candidate ! = null ) {
var payload = { " target " : incomingCallData . targetUserId , " candidate " : e . toMap ( ) } ;
invoke ( invokeMethod: " IceCandidateAsync " , currentUserID: AppState ( ) . chatDetails . response . id , targetUserID: incomingCallData . targetUserId , data: jsonEncode ( payload ) ) ;
var payload = { " target " : incomingCallData ! . targetUserId , " candidate " : e . toMap ( ) } ;
invoke ( invokeMethod: " IceCandidateAsync " , currentUserID: AppState ( ) . chatDetails ! . response ! . id ! , targetUserID: incomingCallData ! . targetUserId ! , data: jsonEncode ( payload ) ) ;
notifyListeners ( ) ;
}
} else {
if ( e . candidate ! = null ) {
var payload = { " target " : outGoingCallData . callerId , " candidate " : e . toMap ( ) } ;
invoke ( invokeMethod: " IceCandidateAsync " , currentUserID: outGoingCallData . callerId , targetUserID: outGoingCallData . receiverId , data: jsonEncode ( payload ) ) ;
var payload = { " target " : outGoingCallData ! . callerId , " candidate " : e . toMap ( ) } ;
invoke ( invokeMethod: " IceCandidateAsync " , currentUserID: outGoingCallData ! . callerId ! , targetUserID: outGoingCallData ! . receiverId ! , data: jsonEncode ( payload ) ) ;
}
}
} ;
@ -635,13 +636,13 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / }
Future < RTCSessionDescription > _createOffer ( ) async {
RTCSessionDescription description = await _pc . createOffer ( ) ;
RTCSessionDescription description = await _pc ! . createOffer ( ) ;
/ / _offer = true ;
return description ;
}
Future < RTCSessionDescription > _createAnswer ( ) async {
RTCSessionDescription description = await _pc . createAnswer ( ) ;
RTCSessionDescription description = await _pc ! . createAnswer ( ) ;
/ / _offer = false ;
return description ;
}
@ -652,7 +653,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
void micOff ( ) {
isMicOff = ! isMicOff ;
_localStream . getAudioTracks ( ) . forEach ( ( track ) {
_localStream ! . getAudioTracks ( ) . forEach ( ( track ) {
track . enabled = ! track . enabled ;
} ) ;
notifyListeners ( ) ;
@ -660,7 +661,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
void camOff ( ) {
isCamOff = ! isCamOff ;
_localStream . getVideoTracks ( ) . forEach ( ( track ) {
_localStream ! . getVideoTracks ( ) . forEach ( ( track ) {
track . enabled = ! track . enabled ;
} ) ;
/ / if ( isCamOff ) {
@ -673,7 +674,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
void loudOn ( ) {
isLoudSpeaker = ! isLoudSpeaker ;
remoteRenderer . srcObject ? . getAudioTracks ( ) . forEach ( ( track ) {
remoteRenderer ! . srcObject ? . getAudioTracks ( ) . forEach ( ( track ) {
if ( isLoudSpeaker ) {
track . enableSpeakerphone ( true ) ;
} else {
@ -685,7 +686,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
void switchCamera ( ) {
isFrontCamera = ! isFrontCamera ;
Helper . switchCamera ( _localStream . getVideoTracks ( ) [ 0 ] ) ;
Helper . switchCamera ( _localStream ! . getVideoTracks ( ) [ 0 ] ) ;
notifyListeners ( ) ;
}
@ -695,7 +696,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
List < MediaDeviceInfo > devices = await navigator . mediaDevices . enumerateDevices ( ) ;
remoteRenderer = RTCVideoRenderer ( ) ;
localVideoRenderer ? ? = RTCVideoRenderer ( ) ;
await localVideoRenderer . initialize ( ) ;
await localVideoRenderer ! . initialize ( ) ;
try {
_localStream = await navigator . mediaDevices . getUserMedia ( {
' audio ' : true ,
@ -714,8 +715,8 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
if ( kDebugMode ) {
print ( _localStream . . toString ( ) ) ;
}
localVideoRenderer . srcObject = _localStream ;
localVideoRenderer . value = ( const RTCVideoValue ( width: 200 , height: 200 , renderVideo: true ) ) ;
localVideoRenderer ! . srcObject = _localStream ;
localVideoRenderer ! . value = ( const RTCVideoValue ( width: 200 , height: 200 , renderVideo: true ) ) ;
print ( " Working localStream " ) ;
} catch ( e ) {
print ( " Failed to get user media: $ e " ) ;
@ -781,7 +782,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / : audioConstraints ) ;
/ / localVideoRenderer . srcObject = _localStream ;
await remoteRenderer . initialize ( ) ;
await remoteRenderer ! . initialize ( ) ;
notifyListeners ( ) ;
}
@ -800,7 +801,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
}
void connectIncomingCall ( ) {
invoke ( invokeMethod: " answerCallAsync " , currentUserID: AppState ( ) . getchatUserDetails . response . id , targetUserID: incomingCallData . targetUserId ) ;
invoke ( invokeMethod: " answerCallAsync " , currentUserID: AppState ( ) . getchatUserDetails . response ! . id ! , targetUserID: incomingCallData ! . targetUserId ! ) ;
isIncomingCallLoader = false ;
isIncomingCall = true ;
/ / isVideoCall = true ;
@ -842,7 +843,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
}
class ChatService extends BaseService {
Future < UserAutoLoginModel > getUserCallToken ( { String userid } ) async {
Future < UserAutoLoginModel > getUserCallToken ( { required String userid } ) async {
UserAutoLoginModel userLoginResponse = UserAutoLoginModel ( ) ;
baseAppClient . post (
" ${ ApiConsts . chatLoginTokenUrl } externaluserlogin " ,