1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 08:16:28 +00:00

Can receive remote video

This commit is contained in:
Pierre HUBERT 2020-04-20 18:13:28 +02:00
parent 7364fc49a8
commit 167217a5a0
2 changed files with 31 additions and 2 deletions

View File

@ -60,6 +60,6 @@ class CallsHelper {
"callID": callID, "callID": callID,
"peerID": peerID, "peerID": peerID,
"type": "CANDIDATE", "type": "CANDIDATE",
"data": jsonEncode(candidate) "data": jsonEncode(candidate.toMap())
}); });
} }

View File

@ -44,6 +44,7 @@ class _CallScreenState extends SafeState<CallScreen> {
CallMembersList _membersList; CallMembersList _membersList;
UsersList _usersList; UsersList _usersList;
final _peersConnections = Map<int, RTCPeerConnection>(); final _peersConnections = Map<int, RTCPeerConnection>();
final _renderers = Map<int, RTCVideoRenderer>();
@override @override
void initState() { void initState() {
@ -168,9 +169,13 @@ class _CallScreenState extends SafeState<CallScreen> {
_peersConnections[memberID] = peerConnection; _peersConnections[memberID] = peerConnection;
// Create a renderer
_renderers[memberID] = RTCVideoRenderer()..initialize();
// Register callbacks // Register callbacks
peerConnection.onIceCandidate = peerConnection.onIceCandidate =
(c) => CallsHelper.sendIceCandidate(convID, memberID, c); (c) => CallsHelper.sendIceCandidate(convID, memberID, c);
peerConnection.onAddStream = (s) => _renderers[memberID].srcObject = s;
// Request an offer to establish a peer connection // Request an offer to establish a peer connection
await CallsHelper.requestOffer(convID, memberID); await CallsHelper.requestOffer(convID, memberID);
@ -199,6 +204,7 @@ class _CallScreenState extends SafeState<CallScreen> {
// Send answer if required // Send answer if required
if (ev.sessionDescription.type == "offer") { if (ev.sessionDescription.type == "offer") {
final answer = await _peersConnections[ev.peerID].createAnswer({}); final answer = await _peersConnections[ev.peerID].createAnswer({});
await _peersConnections[ev.peerID].setLocalDescription(answer);
await CallsHelper.sendSessionDescription(convID, ev.peerID, answer); await CallsHelper.sendSessionDescription(convID, ev.peerID, answer);
} }
@ -223,6 +229,11 @@ class _CallScreenState extends SafeState<CallScreen> {
await _peersConnections[memberID].close(); await _peersConnections[memberID].close();
_peersConnections.remove(memberID); _peersConnections.remove(memberID);
} }
if (_renderers.containsKey(memberID)) {
await _renderers[memberID].dispose();
_renderers.remove(memberID);
}
} }
/// Call this when a member has completely left the call /// Call this when a member has completely left the call
@ -264,7 +275,11 @@ class _CallScreenState extends SafeState<CallScreen> {
if (_membersList == null) return buildCenteredProgressBar(); if (_membersList == null) return buildCenteredProgressBar();
return Column( return Column(
children: <Widget>[_buildMembersArea(), Spacer(), _buildFooterArea()], children: <Widget>[
_buildMembersArea(),
_buildVideosArea(),
_buildFooterArea()
],
); );
} }
@ -287,6 +302,20 @@ class _CallScreenState extends SafeState<CallScreen> {
); );
} }
/// 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 /// Footer area
Widget _buildFooterArea() { Widget _buildFooterArea() {
return Material( return Material(