acceptCall method

Call acceptCall(
  1. IncomingInviteParams invite,
  2. String callerName,
  3. String callerNumber,
  4. String clientState, {
  5. bool isAttach = false,
  6. Map<String, String> customHeaders = const {},
  7. List<AudioCodec>? preferredCodecs,
  8. bool debug = false,
})

Accepts an incoming call.

This method should be called in response to an invite event received via the onSocketMessageReceived callback.

  • invite: The IncomingInviteParams object from the received invite message.
  • callerName: The name of the user accepting the call.
  • callerNumber: The number or SIP URI of the user accepting the call.
  • clientState: A custom string for application-specific state.
  • isAttach: Set to true if this is a call being re-attached (e.g., after network reconnection).
  • customHeaders: Optional custom SIP headers to add to the response.
  • preferredCodecs: Optional list of preferred audio codecs in order of preference. If any codec in the list is not supported by the platform or remote party, the system will automatically fall back to a supported codec.
  • debug: Enables detailed logging for this specific call if set to true.

Returns the Call object associated with the accepted call.

Implementation

Call acceptCall(
  IncomingInviteParams invite,
  String callerName,
  String callerNumber,
  String clientState, {
  bool isAttach = false,
  Map<String, String> customHeaders = const {},
  List<AudioCodec>? preferredCodecs,
  bool debug = false,
}) {
  final Call answerCall = getCallOrNull(invite.callID!) ?? _createCall()
    ..callId = invite.callID
    ..sessionCallerName = callerName
    ..sessionCallerNumber = callerNumber
    ..callState = CallState.connecting
    ..sessionDestinationNumber = invite.callerIdNumber ?? '-1'
    ..sessionClientState = clientState;

  final destinationNum = invite.callerIdNumber;

  // Create the peer connection
  answerCall.peerConnection = Peer(
    txSocket,
    debug || _debug,
    this,
    getForceRelayCandidate(),
  );

  // Convert AudioCodec objects to Map format for the peer connection
  List<Map<String, dynamic>>? codecMaps;
  if (preferredCodecs != null && preferredCodecs.isNotEmpty) {
    codecMaps = preferredCodecs.map((codec) => codec.toJson()).toList();
  }

  // Set up the session with the callback if debug is enabled
  answerCall.peerConnection?.accept(
    callerName,
    callerNumber,
    destinationNum!,
    clientState,
    answerCall.callId!,
    invite,
    customHeaders,
    isAttach,
    preferredCodecs: codecMaps,
  );
  answerCall.callHandler.changeState(CallState.connecting);
  if (debug) {
    answerCall.initCallMetrics();
  }
  answerCall.stopAudio();
  if (answerCall.callId != null) {
    updateCall(answerCall);
  }
  clearPushMetaData();
  return answerCall;
}