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,
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), () {

View File

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