endCurrentAndAcceptIncoming method

Call endCurrentAndAcceptIncoming(
  1. String incomingCallId, {
  2. required void endCall(
    1. String callId
    ),
  3. required Call acceptCall(
    1. String callId
    ),
})

Ends the current active call and accepts an incoming call.

incomingCallId – the callId of the ringing incoming call. endCall – a function that ends a call by callId. acceptCall – a function that accepts the incoming call and returns it.

Returns the accepted call.

Implementation

Call endCurrentAndAcceptIncoming(
  String incomingCallId, {
  required void Function(String callId) endCall,
  required Call Function(String callId) acceptCall,
}) {
  final currentCallId = _currentCall?.callId;
  if (currentCallId != null) {
    GlobalLogger().i(
      'CallManager: Ending current call $currentCallId before accepting incoming $incomingCallId',
    );
    // Suppress auto-unhold: we're about to accept a new call, so we don't
    // want endCurrentAndUnholdLast (called inside endCall) to unhold a
    // held call — we'll keep held calls as-is and set the new call as current.
    _suppressAutoUnhold = true;
    try {
      unregisterCall(currentCallId);
      endCall(currentCallId);
    } finally {
      _suppressAutoUnhold = false;
    }
  }

  final acceptedCall = acceptCall(incomingCallId);
  setCurrentCall(acceptedCall);

  return acceptedCall;
}