diff --git a/lib/src/voip/call.dart b/lib/src/voip/call.dart index b067a394..322a719d 100644 --- a/lib/src/voip/call.dart +++ b/lib/src/voip/call.dart @@ -422,34 +422,36 @@ class CallSession { Future initWithInvite(CallType type, RTCSessionDescription offer, SDPStreamMetadata? metadata, int lifetime, bool isGroupCall) async { - // glare fixes - final prevCallId = voip.incomingCallRoomId[room.id]; - if (prevCallId != null) { - // This is probably an outbound call, but we already have a incoming invite, so let's terminate it. - final prevCall = voip.calls[prevCallId]; - if (prevCall != null) { - if (prevCall.inviteOrAnswerSent) { - Logs().d('[glare] invite or answer sent, lex compare now'); - if (callId.compareTo(prevCall.callId) > 0) { - Logs().d( - '[glare] new call $callId needs to be canceled because the older one ${prevCall.callId} has a smaller lex'); - await hangup(); - return; + if (!isGroupCall) { + // glare fixes + final prevCallId = voip.incomingCallRoomId[room.id]; + if (prevCallId != null) { + // This is probably an outbound call, but we already have a incoming invite, so let's terminate it. + final prevCall = voip.calls[prevCallId]; + if (prevCall != null) { + if (prevCall.inviteOrAnswerSent) { + Logs().d('[glare] invite or answer sent, lex compare now'); + if (callId.compareTo(prevCall.callId) > 0) { + Logs().d( + '[glare] new call $callId needs to be canceled because the older one ${prevCall.callId} has a smaller lex'); + await hangup(); + return; + } else { + Logs().d( + '[glare] nice, lex of newer call $callId is smaller auto accept this here'); + + /// These fixes do not work all the time because sometimes the code + /// is at an unrecoverable stage (invite already sent when we were + /// checking if we want to send a invite), so commented out answering + /// automatically to prevent unknown cases + // await answer(); + // return; + } } else { Logs().d( - '[glare] nice, lex of newer call $callId is smaller auto accept this here'); - - /// These fixes do not work all the time because sometimes the code - /// is at an unrecoverable stage (invite already sent when we were - /// checking if we want to send a invite), so commented out answering - /// automatically to prevent unknown cases - // await answer(); - // return; + '[glare] ${prevCall.callId} was still preparing prev call, nvm now cancel it'); + await prevCall.hangup(); } - } else { - Logs().d( - '[glare] ${prevCall.callId} was still preparing prev call, nvm now cancel it'); - await prevCall.hangup(); } } } @@ -1082,10 +1084,11 @@ class CallSession { if (!isGroupCall) { if (callId != voip.currentCID) return; voip.currentCID = null; + voip.incomingCallRoomId.removeWhere((key, value) => value == callId); } voip.calls.remove(callId); - voip.incomingCallRoomId.removeWhere((key, value) => value == callId); + await cleanUp(); if (shouldEmit) { onCallHangup.add(this); @@ -1156,8 +1159,12 @@ class CallSession { return; } inviteOrAnswerSent = true; - Logs().d('[glare] set callid because new invite sent'); - voip.incomingCallRoomId[room.id] = callId; + + if (!isGroupCall) { + Logs().d('[glare] set callid because new invite sent'); + voip.incomingCallRoomId[room.id] = callId; + } + setCallState(CallState.kInviteSent); inviteTimer = Timer(Duration(seconds: Timeouts.callTimeoutSec), () {