From f240ece32c89b1a7121217c561410804a60aa3fd Mon Sep 17 00:00:00 2001 From: td Date: Sat, 29 Apr 2023 19:33:34 +0530 Subject: [PATCH] fix: updateMuteStatus after kConnected fix: makes sure any state/race issues we had with sdp packets or cloned streams get fixed automatically --- lib/src/voip/call.dart | 6 ++++-- lib/src/voip/group_call.dart | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/src/voip/call.dart b/lib/src/voip/call.dart index 58363031..22d8c903 100644 --- a/lib/src/voip/call.dart +++ b/lib/src/voip/call.dart @@ -1359,15 +1359,17 @@ class CallSession { } } }; - pc!.onIceConnectionState = (RTCIceConnectionState state) { + pc!.onIceConnectionState = (RTCIceConnectionState state) async { Logs().v('[VOIP] RTCIceConnectionState => ${state.toString()}'); if (state == RTCIceConnectionState.RTCIceConnectionStateConnected) { localCandidates.clear(); remoteCandidates.clear(); setCallState(CallState.kConnected); + // fix any state/race issues we had with sdp packets and cloned streams + await updateMuteStatus(); missedCall = false; } else if (state == RTCIceConnectionState.RTCIceConnectionStateFailed) { - hangup(CallErrorCode.IceFailed, false); + await hangup(CallErrorCode.IceFailed, false); } }; } catch (e) { diff --git a/lib/src/voip/group_call.dart b/lib/src/voip/group_call.dart index 3ca00b56..2f08eba8 100644 --- a/lib/src/voip/group_call.dart +++ b/lib/src/voip/group_call.dart @@ -981,8 +981,9 @@ class GroupCall { throw Exception('Cannot init call without user id'); } - call.onCallStateChanged.stream - .listen(((event) => onCallStateChanged(call, event))); + call.onCallStateChanged.stream.listen(((event) async { + await onCallStateChanged(call, event); + })); call.onCallReplaced.stream.listen((CallSession newCall) async { await replaceCall(call, newCall); @@ -1173,7 +1174,8 @@ class GroupCall { void onActiveSpeakerLoop() async { String? nextActiveSpeaker; // idc about screen sharing atm. - for (final stream in userMediaStreams) { + final userMediaStreamsCopyList = List.from(userMediaStreams); + for (final stream in userMediaStreamsCopyList) { if (stream.userId == client.userID && stream.pc == null) { continue; } @@ -1282,7 +1284,10 @@ class GroupCall { participants.add(user); onGroupCallEvent.add(GroupCallEvent.ParticipantsChanged); - for (final call in calls) { + + final callsCopylist = List.from(calls); + + for (final call in callsCopylist) { await call.updateMuteStatus(); } } @@ -1297,7 +1302,10 @@ class GroupCall { participants.removeAt(index); onGroupCallEvent.add(GroupCallEvent.ParticipantsChanged); - for (final call in calls) { + + final callsCopylist = List.from(calls); + + for (final call in callsCopylist) { await call.updateMuteStatus(); } }