Merge branch 'voip/fix-glare-mr-side-effects' into 'main'

fix: fix glare side effects for group calls.

See merge request famedly/company/frontend/famedlysdk!1227
This commit is contained in:
Malin Errenst 2023-01-30 07:48:19 +00:00
commit bc300ac2af
2 changed files with 38 additions and 29 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), () {

View File

@ -535,7 +535,9 @@ class VoIP {
return Null as CallSession; return Null as CallSession;
} }
final callId = 'cid${DateTime.now().millisecondsSinceEpoch}'; final callId = 'cid${DateTime.now().millisecondsSinceEpoch}';
incomingCallRoomId[roomId] = callId; if (currentGroupCID == null) {
incomingCallRoomId[roomId] = callId;
}
final opts = CallOptions() final opts = CallOptions()
..callId = callId ..callId = callId
..type = type ..type = type