1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Handles peer ready & peer destroyed streams events

This commit is contained in:
2020-04-20 14:58:23 +02:00
parent 0f99e807f8
commit 99ecc399ee
5 changed files with 61 additions and 6 deletions

View File

@ -82,6 +82,7 @@ class _CallScreenState extends SafeState<CallScreen> {
// Register to events
this.listenChangeState<UserJoinedCallEvent>((e) {
// TODO : get user information if required
if (e.callID == convID) _membersList.add(CallMember(id: e.userID));
});
@ -89,6 +90,14 @@ class _CallScreenState extends SafeState<CallScreen> {
if (e.callID == convID) _removeMember(e.userID);
});
this.listen<CallPeerReadyEvent>((e) {
if (e.callID == convID) _memberReady(e.peerID);
});
this.listen<CallPeerInterruptedStreamingEvent>((e) {
if (e.callID == convID) _removeRemotePeerConnection(e.peerID);
});
this.listen<CallClosedEvent>((e) {
if (e.callID == convID) _leaveCall(needConfirm: false);
});
@ -98,7 +107,7 @@ class _CallScreenState extends SafeState<CallScreen> {
}
}
// Do clean up operations when call screen is destroyed
/// Do clean up operations when call screen is destroyed
void _endCall() async {
try {
// Leave the call
@ -108,7 +117,7 @@ class _CallScreenState extends SafeState<CallScreen> {
}
}
// Make us leave the call
/// Make us leave the call
void _leaveCall({bool needConfirm = true}) async {
if (needConfirm &&
!await showConfirmDialog(
@ -118,7 +127,23 @@ class _CallScreenState extends SafeState<CallScreen> {
MainController.of(context).popPage();
}
/// Call this when a user started to stream media
void _memberReady(int memberID) {
_membersList.getUser(memberID).status = MemberStatus.READY;
setState((){});
}
/// Call this when a user has interrupted streaming
void _removeRemotePeerConnection(int memberID) {
_membersList.getUser(memberID).status = MemberStatus.JOINED;
setState((){});
}
/// Call this when a members has completely left the call
void _removeMember(int memberID) {
_removeRemotePeerConnection(memberID);
_membersList.removeUser(memberID);
setState(() {});
}