chore: emit handleCallEnded on ice fail

This commit is contained in:
td 2024-03-25 17:09:07 +05:30
parent 81ebb19a5c
commit 76ca4243bc
No known key found for this signature in database
GPG Key ID: 62A30523D4D6CE28
3 changed files with 15 additions and 11 deletions

View File

@ -525,7 +525,7 @@ class CallSession {
Logs().v('[VOIP] Call invite has expired. Hanging up.'); Logs().v('[VOIP] Call invite has expired. Hanging up.');
hangupParty = CallParty.kRemote; // effectively hangupParty = CallParty.kRemote; // effectively
fireCallEvent(CallEvent.kHangup); fireCallEvent(CallEvent.kHangup);
hangup(CallErrorCode.InviteTimeout); hangup(reason: CallErrorCode.InviteTimeout);
} }
ringingTimer?.cancel(); ringingTimer?.cancel();
ringingTimer = null; ringingTimer = null;
@ -550,7 +550,7 @@ class CallSession {
successor = newCall; successor = newCall;
onCallReplaced.add(newCall); onCallReplaced.add(newCall);
// ignore: unawaited_futures // ignore: unawaited_futures
hangup(CallErrorCode.Replaced, true); hangup(reason: CallErrorCode.Replaced);
} }
Future<void> sendAnswer(RTCSessionDescription answer) async { Future<void> sendAnswer(RTCSessionDescription answer) async {
@ -1164,7 +1164,7 @@ class CallSession {
if (state != CallState.kRinging && state != CallState.kFledgling) { if (state != CallState.kRinging && state != CallState.kFledgling) {
Logs().e( Logs().e(
'[VOIP] Call must be in \'ringing|fledgling\' state to reject! (current state was: ${state.toString()}) Calling hangup instead'); '[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; return;
} }
Logs().d('[VOIP] Rejecting call: $callId'); Logs().d('[VOIP] Rejecting call: $callId');
@ -1174,7 +1174,7 @@ class CallSession {
} }
} }
Future<void> hangup([String? reason, bool shouldEmit = true]) async { Future<void> hangup({String? reason, bool shouldEmit = true}) async {
await terminate( await terminate(
CallParty.kLocal, reason ?? CallErrorCode.UserHangup, shouldEmit); CallParty.kLocal, reason ?? CallErrorCode.UserHangup, shouldEmit);
@ -1303,8 +1303,9 @@ class CallSession {
capabilities: callCapabilities, capabilities: callCapabilities,
metadata: metadata); metadata: metadata);
// just incase we ended the call but already sent the invite // just incase we ended the call but already sent the invite
// raraley happens during glares
if (state == CallState.kEnded) { if (state == CallState.kEnded) {
await hangup(CallErrorCode.Replaced, false); await hangup(reason: CallErrorCode.Replaced);
return; return;
} }
inviteOrAnswerSent = true; inviteOrAnswerSent = true;
@ -1318,7 +1319,7 @@ class CallSession {
inviteTimer = Timer(CallTimeouts.callInviteLifetime, () { inviteTimer = Timer(CallTimeouts.callInviteLifetime, () {
if (state == CallState.kInviteSent) { if (state == CallState.kInviteSent) {
hangup(CallErrorCode.InviteTimeout); hangup(reason: CallErrorCode.InviteTimeout);
} }
inviteTimer?.cancel(); inviteTimer?.cancel();
inviteTimer = null; inviteTimer = null;
@ -1404,7 +1405,7 @@ class CallSession {
await updateMuteStatus(); await updateMuteStatus();
missedCall = false; missedCall = false;
} else if (state == RTCIceConnectionState.RTCIceConnectionStateFailed) { } else if (state == RTCIceConnectionState.RTCIceConnectionStateFailed) {
await hangup(CallErrorCode.IceFailed, false); await hangup(reason: CallErrorCode.IceFailed);
} }
}; };
} catch (e) { } catch (e) {
@ -1614,7 +1615,7 @@ class CallSession {
'Failed to send candidates on attempt $candidateSendTries Giving up on this call.'); 'Failed to send candidates on attempt $candidateSendTries Giving up on this call.');
lastError = lastError =
CallError(CallErrorCode.SignallingFailed, 'Signalling failed', e); CallError(CallErrorCode.SignallingFailed, 'Signalling failed', e);
await hangup(CallErrorCode.SignallingFailed, true); await hangup(reason: CallErrorCode.SignallingFailed);
return; return;
} }
@ -1655,7 +1656,7 @@ class CallSession {
fireCallEvent(CallEvent.kError); fireCallEvent(CallEvent.kError);
lastError = CallError( lastError = CallError(
CallErrorCode.LocalOfferFailed, 'Failed to get local offer!', err); CallErrorCode.LocalOfferFailed, 'Failed to get local offer!', err);
await terminate(CallParty.kLocal, CallErrorCode.LocalOfferFailed, false); await terminate(CallParty.kLocal, CallErrorCode.LocalOfferFailed, true);
} }
Future<void> _getUserMediaFailed(dynamic err) async { Future<void> _getUserMediaFailed(dynamic err) async {
@ -1666,7 +1667,7 @@ class CallSession {
CallErrorCode.NoUserMedia, CallErrorCode.NoUserMedia,
'Couldn\'t start capturing media! Is your microphone set up and does this app have permission?', 'Couldn\'t start capturing media! Is your microphone set up and does this app have permission?',
err); err);
await terminate(CallParty.kLocal, CallErrorCode.NoUserMedia, false); await terminate(CallParty.kLocal, CallErrorCode.NoUserMedia, true);
} }
} }

View File

@ -1029,7 +1029,9 @@ class GroupCall {
} }
if (call.state != CallState.kEnded) { 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); final usermediaStream = getUserMediaStreamByUserId(opponentMemberId);

View File

@ -244,6 +244,7 @@ class VoIP {
(confId == null || confId != currentGroupCID)) { (confId == null || confId != currentGroupCID)) {
Logs().v( Logs().v(
'[VOIP] onCallInvite: Unable to handle new calls, maybe user is busy.'); '[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 newCall.reject(reason: CallErrorCode.UserBusy, shouldEmit: false);
await delegate.handleMissedCall(newCall); await delegate.handleMissedCall(newCall);
return; return;