@ -8,7 +8,6 @@ import 'package:diplomaticquarterapp/models/chat/call.dart';
import ' package:diplomaticquarterapp/models/chat/webrtc_payloads.dart ' ;
import ' package:diplomaticquarterapp/routes.dart ' ;
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/get_single_user_chat_call.dart ' ;
@ -56,38 +55,35 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
List < MediaDeviceInfo > devices = [ ] ;
Future < void > buildHubConnection ( ) async {
try {
chatHubConnection = await getHubConnection ( ) ;
} catch ( e ) {
Utils . showErrorToast ( e . toString ( ) ) ;
}
await chatHubConnection . start ( ) ;
if ( kDebugMode ) {
print ( " Hub Conn: Startedddddddd " ) ;
}
/ / chatHubConnection . on ( " OnDeliveredChatUserAsync " , onMsgReceived ) ;
/ / chatHubConnection . on ( " OnGetChatConversationCount " , onNewChatConversion ) ;
/ / chatHubConnection . on ( " OnDeliveredGroupChatHistoryAsync " , onGroupMsgReceived ) ;
chatHubConnection = await getHubConnection ( ) ;
if ( chatHubConnection ! = null ) await chatHubConnection . start ( ) ;
print ( " Hub Conn: Startedddddddd " ) ;
registerCallListners ( ) ;
Future . delayed ( Duration ( seconds: 3 ) , ( ) { } ) ;
return ;
}
/ / { " id " : 341682 , " userName " : " Aamir.Muhammad " , " email " : " Aamir.Muhammad@cloudsolutions.com.sa " , " phone " : null , " title " : " Aamir Saleem Ahmad Dost Muhammad " , " token " : " eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzNDE2ODIiLCJlbWFpbCI6IkFhbWlyLk11aGFtbWFkQGNsb3Vkc29sdXRpb25zLmNvbS5zYSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvdXNlcmRhdGEiOiJBYW1pci5NdWhhbW1hZCIsIm5iZiI6MTcwNzIwNTAyMywiZXhwIjoxNzA3MjkxNDIzLCJpYXQiOjE3MDcyMDUwMjN9.Zz2bcsMwiLAAWGZh2E_p5Qs6ItMt0JHhDFI_0DLdggCQtt6HHcT4n8nvqMZx-uYr3jLwqhA_IAjTuaCeSE15sw " , " isDomainUser " : true , " isActiveCode " : false , " encryptedUserId " : " nn7RkYzbnQc= " , " encryptedUserName " : " /QruOyp4QMcmNXKZlljUgg== " }
Future < HubConnection > getHubConnection ( ) async {
AppState ( ) . chatDetails . response = Response . fromJson (
{
" id " : 341682 ,
" userName " : " Aamir.Muhammad " ,
" email " : " Aamir.Muhammad@cloudsolutions.com.sa " ,
" phone " : null ,
" title " : " Aamir Saleem Ahmad Dost Muhammad " ,
" token " :
" eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzNDE2ODIiLCJlbWFpbCI6IkFhbWlyLk11aGFtbWFkQGNsb3Vkc29sdXRpb25zLmNvbS5zYSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvdXNlcmRhdGEiOiJBYW1pci5NdWhhbW1hZCIsIm5iZiI6MTcwNzIwNTAyMywiZXhwIjoxNzA3MjkxNDIzLCJpYXQiOjE3MDcyMDUwMjN9.Zz2bcsMwiLAAWGZh2E_p5Qs6ItMt0JHhDFI_0DLdggCQtt6HHcT4n8nvqMZx-uYr3jLwqhA_IAjTuaCeSE15sw " ,
" isDomainUser " : true ,
" isActiveCode " : false ,
" encryptedUserId " : " nn7RkYzbnQc= " ,
" encryptedUserName " : " /QruOyp4QMcmNXKZlljUgg== "
} ,
) ;
if ( AppState ( ) . chatDetails = = null ) {
AppState ( ) . chatDetails = UserAutoLoginModel . fromJson (
{
" response " : {
" id " : 341682 ,
" userName " : " Aamir.Muhammad " ,
" email " : " Aamir.Muhammad@cloudsolutions.com.sa " ,
" phone " : null ,
" title " : " Aamir Saleem Ahmad Dost Muhammad " ,
" token " :
" eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIzNDE2ODIiLCJlbWFpbCI6IkFhbWlyLk11aGFtbWFkQGNsb3Vkc29sdXRpb25zLmNvbS5zYSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvdXNlcmRhdGEiOiJBYW1pci5NdWhhbW1hZCIsIm5iZiI6MTcwNzM3NzMyMiwiZXhwIjoxNzA3NDYzNzIyLCJpYXQiOjE3MDczNzczMjJ9.qYzwICr5URSIE0kQ0PQypKZCpqTAx0EYBNlhHl8Bq0InpmL4zhvHHDfC6YPNL1DTQpfp6kk5G7VZTr6nCAmuyg " ,
" isDomainUser " : true ,
" isActiveCode " : false ,
" encryptedUserId " : " nn7RkYzbnQc= " ,
" encryptedUserName " : " /QruOyp4QMcmNXKZlljUgg== "
} ,
" errorResponses " : null ,
} ,
) ;
}
HubConnection hub ;
HttpConnectionOptions httpOp = HttpConnectionOptions ( skipNegotiation: false , logMessageContent: true ) ;
@ -97,10 +93,26 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
return hub ;
}
Future < CallDataModel > makeCall ( { String callType } ) async {
Map < String , dynamic > json = {
" callerID " : AppState ( ) . chatDetails . response . id ,
" callerName " : AppState ( ) . chatDetails . response . userName ,
" callerEmail " : AppState ( ) . chatDetails . response . email ,
" callerTitle " : AppState ( ) . chatDetails . response . title ,
" callerPhone " : AppState ( ) . chatDetails . response . phone ,
" receiverID " : 266642 ,
" receiverName " : " Muhammad Alam " ,
" receiverEmail " : " Muhamad.Alam@cloudsolutions.com.sa " ,
" receiverTitle " : " Muhammad Alam " ,
" receiverPhone " : " 123456789 " ,
" title " : " Muhammad Alam " ,
" callType " : callType = = " VIDEO " ? " Video " : " Audio " ,
} ;
CallDataModel callData = CallDataModel . fromJson ( json ) ;
return callData ;
}
void registerCallListners ( ) {
if ( kDebugMode ) {
print ( " =================== Call Listeners Registered ======================= " ) ;
}
chatHubConnection . on ( " OnCallAcceptedAsync " , onCallAcceptedAsync ) ;
chatHubConnection . on ( " OnIceCandidateAsync " , onIceCandidateAsync ) ;
chatHubConnection . on ( " OnOfferAsync " , onOfferAsync ) ;
@ -132,16 +144,14 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
isCallEnded = false ;
outGoingCallData = callData ;
await initStreams ( ) ;
await startCall ( callType: isVideoCall ? " Video " : " Audio " , context: context ) ;
_pc = await creatOfferWithCon ( ) ;
connectOutgoing( ) ;
isOutGoingCall = true ;
notifyListeners ( ) ;
}
void connectOutgoing ( ) {
isOutGoingCall = true ;
/ / notifyListeners ( ) ;
}
Future < void > startCall ( { String callType , BuildContext context } ) async {
@ -558,11 +568,11 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
' optional ' : [ ]
} ;
RTCPeerConnection pc = await createPeerConnection ( configuration , offerSdpConstraints ) ;
/ / await pc . addStream ( _localStream ! ) ;
await pc . addStream ( _localStream ) ;
/ / Changed By Aamir
_localStream ? . getTracks ( ) . forEach ( ( track ) {
pc . addTrack ( track , _localStream ) ;
} ) ;
/ / _localStream . getTracks ( ) . forEach ( ( track ) {
/ / pc . addTrack ( track , _localStream ) ;
/ / } ) ;
pc . onConnectionState = ( RTCPeerConnectionState state ) { } ;
pc . onAddStream = ( MediaStream stream ) {
remoteRenderer . srcObject = stream ;
@ -694,14 +704,15 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
/ / / / / / / / / / / / / / / / / Incoming Call / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Future < void > initStreams ( ) async {
print ( " INIT STREAMSSSSS " ) ;
List < MediaDeviceInfo > devices = await navigator . mediaDevices . enumerateDevices ( ) ;
remoteRenderer = RTCVideoRenderer ( ) ;
localVideoRenderer ?? = RTCVideoRenderer ( ) ;
localVideoRenderer = RTCVideoRenderer ( ) ;
await localVideoRenderer . initialize ( ) ;
try {
_localStream = await navigator . mediaDevices . getUserMedia ( {
' audio ' : true ,
' video ' : isVideoCall
' video ' : true
? {
' mandatory ' : {
' minWidth ' : ' 640 ' , / / Provide your own width , height and frame rate here
@ -722,67 +733,6 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin {
} catch ( e ) {
print ( " Failed to get user media: $ e " ) ;
}
/ / _localStream = await navigator . mediaDevices . getUserMedia ( isVideoCall
/ / ? Platform . isIOS
/ / ? {
/ / ' audio ' : true ,
/ / ' video ' : {
/ / ' facingMode ' : ' user ' , / / Use ' user ' for front camera , ' environment ' for back camera
/ / ' width ' : {
/ / ' ideal ' : 1080 , / / Set the ideal width ( maximum quality )
/ / } ,
/ / ' height ' : {
/ / ' ideal ' : 1920 , / / Set the ideal height ( maximum quality )
/ / } ,
/ / ' frameRate ' : {
/ / ' ideal ' : 30 , / / Set the ideal frame rate ( adjust as needed )
/ / } ,
/ / } ,
/ / }
/ / : {
/ / ' audio ' : true ,
/ / ' video ' : {
/ / ' facingMode ' : ' user ' , / / Use ' user ' for front camera , ' environment ' for back camera
/ / ' width ' : {
/ / ' ideal ' : 1920 , / / Set the ideal width ( maximum quality )
/ / } ,
/ / ' height ' : {
/ / ' ideal ' : 1080 , / / Set the ideal height ( maximum quality )
/ / } ,
/ / ' frameRate ' : {
/ / ' ideal ' : 30 , / / Set the ideal frame rate ( adjust as needed )
/ / } ,
/ / } ,
/ / }
/ /
/ / / / ? {
/ / / / " video " : {
/ / / / " mandatory " : {
/ / / / " width " : { " min " : 1080 } ,
/ / / / " height " : { " min " : 1920 }
/ / / / } ,
/ / / / " optional " : Platform . isAndroid
/ / / / ? [
/ / / / { ' sourceId ' : devices [ 1 ] . deviceId } ,
/ / / / {
/ / / / " width " : { " max " : 1080 }
/ / / / } ,
/ / / / { " frameRate " : 30 } ,
/ / / / { " facingMode " : " user " }
/ / / / ]
/ / / / : [
/ / / / { " frameRate " : 30 } ,
/ / / / { " facingMode " : " user " }
/ / / / ]
/ / / / } ,
/ / / / " frameRate " : 30 ,
/ / / / " width " : 1080 , / / 420 , / / 640 , / / 1280 ,
/ / / / " height " : 1920 , / / 240 / / 480 / / 720
/ / / / " audio " : true ,
/ / / / }
/ / : audioConstraints ) ;
/ / localVideoRenderer . srcObject = _localStream ;
await remoteRenderer . initialize ( ) ;
notifyListeners ( ) ;
}