mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can receive remote video
This commit is contained in:
parent
7364fc49a8
commit
167217a5a0
@ -60,6 +60,6 @@ class CallsHelper {
|
||||
"callID": callID,
|
||||
"peerID": peerID,
|
||||
"type": "CANDIDATE",
|
||||
"data": jsonEncode(candidate)
|
||||
"data": jsonEncode(candidate.toMap())
|
||||
});
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
CallMembersList _membersList;
|
||||
UsersList _usersList;
|
||||
final _peersConnections = Map<int, RTCPeerConnection>();
|
||||
final _renderers = Map<int, RTCVideoRenderer>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -168,9 +169,13 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
|
||||
_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<CallScreen> {
|
||||
// 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<CallScreen> {
|
||||
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<CallScreen> {
|
||||
if (_membersList == null) return buildCenteredProgressBar();
|
||||
|
||||
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
|
||||
Widget _buildFooterArea() {
|
||||
return Material(
|
||||
|
Loading…
Reference in New Issue
Block a user