terminate method

Future<void> terminate(
  1. CallParty party,
  2. String reason,
  3. bool shouldEmit
)

Implementation

Future<void> terminate(
  CallParty party,
  String reason,
  bool shouldEmit,
) async {
  Logs().d('[VOIP] terminating call');
  inviteTimer?.cancel();
  inviteTimer = null;

  ringingTimer?.cancel();
  ringingTimer = null;

  try {
    await voip.delegate.stopRingtone();
  } catch (e) {
    // maybe rigntone never started (group calls) or has been stopped already
    Logs().d('stopping ringtone failed ', e);
  }

  hangupParty = party;
  hangupReason = reason;

  // don't see any reason to wrap this with shouldEmit atm,
  // looks like a local state change only
  setCallState(CallState.kEnded);

  if (!isGroupCall) {
    if (callId != voip.currentCID) return;
    voip.currentCID = null;
    voip.incomingCallRoomId.removeWhere((key, value) => value == callId);
  }

  voip.calls.remove(callId);

  await cleanUp();
  if (shouldEmit) {
    onCallHangupNotifierForGroupCalls.add(this);
    await voip.delegate.handleCallEnded(this);
    fireCallEvent(CallEvent.kHangup);
    if ((party == CallParty.kRemote && missedCall)) {
      await voip.delegate.handleMissedCall(this);
    }
  }
}