1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Can request call offer

This commit is contained in:
Pierre HUBERT 2020-04-20 15:50:01 +02:00
parent 73c7fa8807
commit 80f05cb008
3 changed files with 22 additions and 3 deletions

View File

@ -34,4 +34,8 @@ class CallsHelper {
))
.toList()
.cast<CallMember>());
/// Request an offer to access another peer's stream
static Future<void> requestOffer(int callID, int peerID) async =>
await ws("calls/request_offer", {"callID": callID, "peerID": peerID});
}

View File

@ -14,4 +14,8 @@ class CallMembersList extends AbstractList<CallMember> {
/// Get the connection of a specific user
CallMember getUser(int userID) => this.firstWhere((f) => f.userID == userID);
/// Extract ready peers from this list
CallMembersList get readyPeers =>
CallMembersList()..addAll(where((f) => f.status == MemberStatus.READY));
}

View File

@ -101,6 +101,10 @@ class _CallScreenState extends SafeState<CallScreen> {
this.listen<CallClosedEvent>((e) {
if (e.callID == convID) _leaveCall(needConfirm: false);
});
// Connect to ready peers
for (final peer in _membersList.readyPeers)
await this._memberReady(peer.userID);
} catch (e, stack) {
print("Could not initialize call! $e\n$stack");
setState(() => _error = true);
@ -128,10 +132,17 @@ class _CallScreenState extends SafeState<CallScreen> {
}
/// Call this when a user started to stream media
void _memberReady(int memberID) {
Future<void> _memberReady(int memberID) async {
try {
_membersList.getUser(memberID).status = MemberStatus.READY;
setState(() {});
// Request an offer to establish a peer connection
await CallsHelper.requestOffer(convID, memberID);
} catch (e, stack) {
print("Could not connect to remote peer $e\n$stack!");
showSimpleSnack(context, tr("Could not connect to a remote peer!"));
}
}
/// Call this when a user has interrupted streaming