fix: fix glare side effects for group calls.

This commit is contained in:
duanweiwei1982@gmail.com 2023-01-28 01:10:29 +08:00
parent 0eb8dc96c1
commit 0deb8d9e6e
1 changed files with 35 additions and 28 deletions

View File

@ -422,34 +422,36 @@ class CallSession {
Future<void> initWithInvite(CallType type, RTCSessionDescription offer, Future<void> initWithInvite(CallType type, RTCSessionDescription offer,
SDPStreamMetadata? metadata, int lifetime, bool isGroupCall) async { SDPStreamMetadata? metadata, int lifetime, bool isGroupCall) async {
// glare fixes if (!isGroupCall) {
final prevCallId = voip.incomingCallRoomId[room.id]; // glare fixes
if (prevCallId != null) { final prevCallId = voip.incomingCallRoomId[room.id];
// This is probably an outbound call, but we already have a incoming invite, so let's terminate it. if (prevCallId != null) {
final prevCall = voip.calls[prevCallId]; // This is probably an outbound call, but we already have a incoming invite, so let's terminate it.
if (prevCall != null) { final prevCall = voip.calls[prevCallId];
if (prevCall.inviteOrAnswerSent) { if (prevCall != null) {
Logs().d('[glare] invite or answer sent, lex compare now'); if (prevCall.inviteOrAnswerSent) {
if (callId.compareTo(prevCall.callId) > 0) { Logs().d('[glare] invite or answer sent, lex compare now');
Logs().d( if (callId.compareTo(prevCall.callId) > 0) {
'[glare] new call $callId needs to be canceled because the older one ${prevCall.callId} has a smaller lex'); Logs().d(
await hangup(); '[glare] new call $callId needs to be canceled because the older one ${prevCall.callId} has a smaller lex');
return; 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 { } else {
Logs().d( Logs().d(
'[glare] nice, lex of newer call $callId is smaller auto accept this here'); '[glare] ${prevCall.callId} was still preparing prev call, nvm now cancel it');
await prevCall.hangup();
/// 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] ${prevCall.callId} was still preparing prev call, nvm now cancel it');
await prevCall.hangup();
} }
} }
} }
@ -1082,10 +1084,11 @@ class CallSession {
if (!isGroupCall) { if (!isGroupCall) {
if (callId != voip.currentCID) return; if (callId != voip.currentCID) return;
voip.currentCID = null; voip.currentCID = null;
voip.incomingCallRoomId.removeWhere((key, value) => value == callId);
} }
voip.calls.remove(callId); voip.calls.remove(callId);
voip.incomingCallRoomId.removeWhere((key, value) => value == callId);
await cleanUp(); await cleanUp();
if (shouldEmit) { if (shouldEmit) {
onCallHangup.add(this); onCallHangup.add(this);
@ -1156,8 +1159,12 @@ class CallSession {
return; return;
} }
inviteOrAnswerSent = true; 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); setCallState(CallState.kInviteSent);
inviteTimer = Timer(Duration(seconds: Timeouts.callTimeoutSec), () { inviteTimer = Timer(Duration(seconds: Timeouts.callTimeoutSec), () {