From 76ca4243bc68329f5316b95e5c4b4b946f183729 Mon Sep 17 00:00:00 2001 From: td Date: Mon, 25 Mar 2024 17:09:07 +0530 Subject: [PATCH] chore: emit handleCallEnded on ice fail --- lib/src/voip/call.dart | 21 +++++++++++---------- lib/src/voip/group_call.dart | 4 +++- lib/src/voip/voip.dart | 1 + 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/src/voip/call.dart b/lib/src/voip/call.dart index fd10290d..12815de3 100644 --- a/lib/src/voip/call.dart +++ b/lib/src/voip/call.dart @@ -525,7 +525,7 @@ class CallSession { Logs().v('[VOIP] Call invite has expired. Hanging up.'); hangupParty = CallParty.kRemote; // effectively fireCallEvent(CallEvent.kHangup); - hangup(CallErrorCode.InviteTimeout); + hangup(reason: CallErrorCode.InviteTimeout); } ringingTimer?.cancel(); ringingTimer = null; @@ -550,7 +550,7 @@ class CallSession { successor = newCall; onCallReplaced.add(newCall); // ignore: unawaited_futures - hangup(CallErrorCode.Replaced, true); + hangup(reason: CallErrorCode.Replaced); } Future sendAnswer(RTCSessionDescription answer) async { @@ -1164,7 +1164,7 @@ class CallSession { if (state != CallState.kRinging && state != CallState.kFledgling) { Logs().e( '[VOIP] Call must be in \'ringing|fledgling\' state to reject! (current state was: ${state.toString()}) Calling hangup instead'); - await hangup(reason, shouldEmit); + await hangup(reason: reason, shouldEmit: shouldEmit); return; } Logs().d('[VOIP] Rejecting call: $callId'); @@ -1174,7 +1174,7 @@ class CallSession { } } - Future hangup([String? reason, bool shouldEmit = true]) async { + Future hangup({String? reason, bool shouldEmit = true}) async { await terminate( CallParty.kLocal, reason ?? CallErrorCode.UserHangup, shouldEmit); @@ -1303,8 +1303,9 @@ class CallSession { capabilities: callCapabilities, metadata: metadata); // just incase we ended the call but already sent the invite + // raraley happens during glares if (state == CallState.kEnded) { - await hangup(CallErrorCode.Replaced, false); + await hangup(reason: CallErrorCode.Replaced); return; } inviteOrAnswerSent = true; @@ -1318,7 +1319,7 @@ class CallSession { inviteTimer = Timer(CallTimeouts.callInviteLifetime, () { if (state == CallState.kInviteSent) { - hangup(CallErrorCode.InviteTimeout); + hangup(reason: CallErrorCode.InviteTimeout); } inviteTimer?.cancel(); inviteTimer = null; @@ -1404,7 +1405,7 @@ class CallSession { await updateMuteStatus(); missedCall = false; } else if (state == RTCIceConnectionState.RTCIceConnectionStateFailed) { - await hangup(CallErrorCode.IceFailed, false); + await hangup(reason: CallErrorCode.IceFailed); } }; } catch (e) { @@ -1614,7 +1615,7 @@ class CallSession { 'Failed to send candidates on attempt $candidateSendTries Giving up on this call.'); lastError = CallError(CallErrorCode.SignallingFailed, 'Signalling failed', e); - await hangup(CallErrorCode.SignallingFailed, true); + await hangup(reason: CallErrorCode.SignallingFailed); return; } @@ -1655,7 +1656,7 @@ class CallSession { fireCallEvent(CallEvent.kError); lastError = CallError( CallErrorCode.LocalOfferFailed, 'Failed to get local offer!', err); - await terminate(CallParty.kLocal, CallErrorCode.LocalOfferFailed, false); + await terminate(CallParty.kLocal, CallErrorCode.LocalOfferFailed, true); } Future _getUserMediaFailed(dynamic err) async { @@ -1666,7 +1667,7 @@ class CallSession { CallErrorCode.NoUserMedia, 'Couldn\'t start capturing media! Is your microphone set up and does this app have permission?', err); - await terminate(CallParty.kLocal, CallErrorCode.NoUserMedia, false); + await terminate(CallParty.kLocal, CallErrorCode.NoUserMedia, true); } } diff --git a/lib/src/voip/group_call.dart b/lib/src/voip/group_call.dart index 44f364bb..b0c42275 100644 --- a/lib/src/voip/group_call.dart +++ b/lib/src/voip/group_call.dart @@ -1029,7 +1029,9 @@ class GroupCall { } if (call.state != CallState.kEnded) { - await call.hangup(hangupReason, false); + // no need to emit individual handleCallEnded on group calls + // also prevents a loop of hangup and onCallHangupNotifierForGroupCalls + await call.hangup(reason: hangupReason, shouldEmit: false); } final usermediaStream = getUserMediaStreamByUserId(opponentMemberId); diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index c099815b..931449a9 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -244,6 +244,7 @@ class VoIP { (confId == null || confId != currentGroupCID)) { Logs().v( '[VOIP] onCallInvite: Unable to handle new calls, maybe user is busy.'); + // no need to emit here because handleNewCall was never triggered yet await newCall.reject(reason: CallErrorCode.UserBusy, shouldEmit: false); await delegate.handleMissedCall(newCall); return;