From 167217a5a09603cdede8ddbc861ebf6a18ae6bdc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 20 Apr 2020 18:13:28 +0200 Subject: [PATCH] Can receive remote video --- lib/helpers/calls_helper.dart | 2 +- lib/ui/screens/call_screen.dart | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/helpers/calls_helper.dart b/lib/helpers/calls_helper.dart index b9dcc98..92ed4a6 100644 --- a/lib/helpers/calls_helper.dart +++ b/lib/helpers/calls_helper.dart @@ -60,6 +60,6 @@ class CallsHelper { "callID": callID, "peerID": peerID, "type": "CANDIDATE", - "data": jsonEncode(candidate) + "data": jsonEncode(candidate.toMap()) }); } diff --git a/lib/ui/screens/call_screen.dart b/lib/ui/screens/call_screen.dart index 6268d41..285f6a2 100644 --- a/lib/ui/screens/call_screen.dart +++ b/lib/ui/screens/call_screen.dart @@ -44,6 +44,7 @@ class _CallScreenState extends SafeState { CallMembersList _membersList; UsersList _usersList; final _peersConnections = Map(); + final _renderers = Map(); @override void initState() { @@ -168,9 +169,13 @@ class _CallScreenState extends SafeState { _peersConnections[memberID] = peerConnection; + // Create a renderer + _renderers[memberID] = RTCVideoRenderer()..initialize(); + // Register callbacks peerConnection.onIceCandidate = (c) => CallsHelper.sendIceCandidate(convID, memberID, c); + peerConnection.onAddStream = (s) => _renderers[memberID].srcObject = s; // Request an offer to establish a peer connection await CallsHelper.requestOffer(convID, memberID); @@ -199,6 +204,7 @@ class _CallScreenState extends SafeState { // Send answer if required if (ev.sessionDescription.type == "offer") { final answer = await _peersConnections[ev.peerID].createAnswer({}); + await _peersConnections[ev.peerID].setLocalDescription(answer); await CallsHelper.sendSessionDescription(convID, ev.peerID, answer); } @@ -223,6 +229,11 @@ class _CallScreenState extends SafeState { await _peersConnections[memberID].close(); _peersConnections.remove(memberID); } + + if (_renderers.containsKey(memberID)) { + await _renderers[memberID].dispose(); + _renderers.remove(memberID); + } } /// Call this when a member has completely left the call @@ -264,7 +275,11 @@ class _CallScreenState extends SafeState { if (_membersList == null) return buildCenteredProgressBar(); return Column( - children: [_buildMembersArea(), Spacer(), _buildFooterArea()], + children: [ + _buildMembersArea(), + _buildVideosArea(), + _buildFooterArea() + ], ); } @@ -287,6 +302,20 @@ class _CallScreenState extends SafeState { ); } + /// Videos area + Widget _buildVideosArea() { + return Expanded( + child: Column( + children: _membersList.readyPeers + .map((f) => _buildMemberVideo(f.userID)) + .toList(), + )); + } + + Widget _buildMemberVideo(int peerID) { + return Expanded(child: RTCVideoView(_renderers[peerID])); + } + /// Footer area Widget _buildFooterArea() { return Material(