From 00abbd8630a3cbf3707744de1c42f5e977ae9662 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Sun, 30 Oct 2022 09:31:55 +0300 Subject: [PATCH] WebRtc Event Changes --- .../Appointments/toDoCountProviderModel.dart | 2 +- lib/pages/landing/landing_page.dart | 1 + .../webrtc/signaling.dart | 11 ++++-- .../webrtc/start_video_call.dart | 34 ++++++++----------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/models/Appointments/toDoCountProviderModel.dart b/lib/models/Appointments/toDoCountProviderModel.dart index ef4e069c..3363471f 100644 --- a/lib/models/Appointments/toDoCountProviderModel.dart +++ b/lib/models/Appointments/toDoCountProviderModel.dart @@ -11,7 +11,7 @@ class ToDoCountProviderModel with ChangeNotifier { bool get isShowBadge => _isShowBadge; - void setState(int count, bool isShowBadge, String notifCount) { + void setState(int count, bool isShowBadge, String notifCount) { _count = count; _isShowBadge = isShowBadge; _notificationsCount = notifCount; diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index e53c9201..23d993ff 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -618,6 +618,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { changeCurrentTab(1); }, onLoginClick: () { + login(); }, onMedicalFileClick: () { diff --git a/lib/pages/videocall-webrtc-rnd/webrtc/signaling.dart b/lib/pages/videocall-webrtc-rnd/webrtc/signaling.dart index fbafc8ba..cee85ac6 100644 --- a/lib/pages/videocall-webrtc-rnd/webrtc/signaling.dart +++ b/lib/pages/videocall-webrtc-rnd/webrtc/signaling.dart @@ -71,6 +71,7 @@ class Signaling { Function(dynamic event) onPeersUpdate; Function(dynamic event) onConnected; Function(dynamic event) onCallAccepted; + Function(dynamic event) onCallRejected; Function(SessionOneToOne session, RTCDataChannel dc, RTCDataChannelMessage data) onDataChannelMessage; Function(SessionOneToOne session, RTCDataChannel dc) onDataChannel; @@ -131,6 +132,12 @@ class Signaling { 'from': session.local_user.id, 'session_id': session.id, }); + + _send('patient_call_accepted', { + 'to': session.remote_user?.id, + 'from': session.local_user.id, + 'session_id': session.id, + }); } void offer(String media, bool useScreen) async { @@ -156,12 +163,11 @@ class Signaling { 'session_id': session.id, 'to': session.remote_user.id, 'from': session.local_user.id, - - // 'call_rejected' : callRejected }); _closeSession(session); } + void onMessage(message) async { Map mapData = message; var data = mapData['data']; @@ -232,7 +238,6 @@ class Signaling { onCallStateChange?.call(session, CallState.Bye); } break; - case 'keepalive': { print('keepalive response!'); diff --git a/lib/pages/videocall-webrtc-rnd/webrtc/start_video_call.dart b/lib/pages/videocall-webrtc-rnd/webrtc/start_video_call.dart index 1acee68c..abad8b07 100644 --- a/lib/pages/videocall-webrtc-rnd/webrtc/start_video_call.dart +++ b/lib/pages/videocall-webrtc-rnd/webrtc/start_video_call.dart @@ -18,14 +18,14 @@ class StartVideoCall extends StatefulWidget { StartVideoCall({@required this.signaling, @required this.session}); @override - StartVideoCallState createState() => StartVideoCallState(session: session, signaling: signaling); + StartVideoCallState createState() => StartVideoCallState(session: session, signaling: signaling); } class StartVideoCallState extends State { Signaling _signaling; SessionOneToOne _session; - StartVideoCallState({@required SessionOneToOne session, @required Signaling signaling}){ + StartVideoCallState({@required SessionOneToOne session, @required Signaling signaling}) { this._session = session; this._signaling = signaling; } @@ -40,6 +40,7 @@ class StartVideoCallState extends State { final RTCVideoRenderer _remoteRenderer = RTCVideoRenderer(); MediaStream get localMediaStream => _signaling.localStream; + MediaStream get remoteMediaStream => _signaling.remoteStreams.first; @override @@ -100,10 +101,8 @@ class StartVideoCallState extends State { ); } - void _setupEventListeners() async { - if(_session == null) - return; + if (_session == null) return; // _signaling ??= Signaling(widget.host, session: _session)..connect(); @@ -129,14 +128,11 @@ class StartVideoCallState extends State { _signaling?.callAccepted(_session); }); - _signaling?.onCallAccepted = ((event) { - - }); + _signaling?.onCallAccepted = ((event) {}); _signaling?.onLocalStream = ((stream) { _localRenderer.srcObject = stream; - setState(() { - }); + setState(() {}); }); _signaling?.onAddRemoteStream = ((_, stream) { @@ -159,14 +155,14 @@ class StartVideoCallState extends State { // _signaling?.muteMic(); // } - Function _onAudioEnable(){ + Function _onAudioEnable() { print("================= Audio Event Triggered ==================="); final audioTrack = localMediaStream.getAudioTracks()[0]; final micEnabled = audioTrack.enabled; localMediaStream.getAudioTracks()[0].enabled = !micEnabled; _audioButton.add(!micEnabled); - // _audioButton.add(!mute); - // Helper.setMicrophoneMute(!mute, audioTrack); + // _audioButton.add(!mute); + // Helper.setMicrophoneMute(!mute, audioTrack); } Function _onVideoEnabled() { @@ -183,8 +179,7 @@ class StartVideoCallState extends State { } void _onShowBar() { - setState(() { - }); + setState(() {}); _onButtonBarVisibleStreamController.add(true); } @@ -200,13 +195,12 @@ class StartVideoCallState extends State { } Future _onHangup({bool byRemote = false}) async { - print("================= HangUp Event Triggered ==================="); - print("================= $byRemote ==================="); - if(byRemote){ + + if (byRemote) { Navigator.of(context).pop(); - }else{ + } else { _signaling.bye(_session); Navigator.of(context).pop(); } } -} \ No newline at end of file +}