fix: updateMuteStatus after kConnected

fix: makes sure any state/race issues we had with sdp packets or cloned streams get fixed automatically
This commit is contained in:
td 2023-04-29 19:33:34 +05:30
parent 1a58a8ec09
commit f240ece32c
No known key found for this signature in database
GPG Key ID: F6D9E9BF14C7D103
2 changed files with 17 additions and 7 deletions

View File

@ -1359,15 +1359,17 @@ class CallSession {
} }
} }
}; };
pc!.onIceConnectionState = (RTCIceConnectionState state) { pc!.onIceConnectionState = (RTCIceConnectionState state) async {
Logs().v('[VOIP] RTCIceConnectionState => ${state.toString()}'); Logs().v('[VOIP] RTCIceConnectionState => ${state.toString()}');
if (state == RTCIceConnectionState.RTCIceConnectionStateConnected) { if (state == RTCIceConnectionState.RTCIceConnectionStateConnected) {
localCandidates.clear(); localCandidates.clear();
remoteCandidates.clear(); remoteCandidates.clear();
setCallState(CallState.kConnected); setCallState(CallState.kConnected);
// fix any state/race issues we had with sdp packets and cloned streams
await updateMuteStatus();
missedCall = false; missedCall = false;
} else if (state == RTCIceConnectionState.RTCIceConnectionStateFailed) { } else if (state == RTCIceConnectionState.RTCIceConnectionStateFailed) {
hangup(CallErrorCode.IceFailed, false); await hangup(CallErrorCode.IceFailed, false);
} }
}; };
} catch (e) { } catch (e) {

View File

@ -981,8 +981,9 @@ class GroupCall {
throw Exception('Cannot init call without user id'); throw Exception('Cannot init call without user id');
} }
call.onCallStateChanged.stream call.onCallStateChanged.stream.listen(((event) async {
.listen(((event) => onCallStateChanged(call, event))); await onCallStateChanged(call, event);
}));
call.onCallReplaced.stream.listen((CallSession newCall) async { call.onCallReplaced.stream.listen((CallSession newCall) async {
await replaceCall(call, newCall); await replaceCall(call, newCall);
@ -1173,7 +1174,8 @@ class GroupCall {
void onActiveSpeakerLoop() async { void onActiveSpeakerLoop() async {
String? nextActiveSpeaker; String? nextActiveSpeaker;
// idc about screen sharing atm. // 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) { if (stream.userId == client.userID && stream.pc == null) {
continue; continue;
} }
@ -1282,7 +1284,10 @@ class GroupCall {
participants.add(user); participants.add(user);
onGroupCallEvent.add(GroupCallEvent.ParticipantsChanged); onGroupCallEvent.add(GroupCallEvent.ParticipantsChanged);
for (final call in calls) {
final callsCopylist = List.from(calls);
for (final call in callsCopylist) {
await call.updateMuteStatus(); await call.updateMuteStatus();
} }
} }
@ -1297,7 +1302,10 @@ class GroupCall {
participants.removeAt(index); participants.removeAt(index);
onGroupCallEvent.add(GroupCallEvent.ParticipantsChanged); onGroupCallEvent.add(GroupCallEvent.ParticipantsChanged);
for (final call in calls) {
final callsCopylist = List.from(calls);
for (final call in callsCopylist) {
await call.updateMuteStatus(); await call.updateMuteStatus();
} }
} }