accept method

void accept(
  1. String callerName,
  2. String callerNumber,
  3. String destinationNumber,
  4. String clientState,
  5. String callId,
  6. IncomingInviteParams invite,
  7. Map<String, String> customHeaders,
  8. bool isAttach,
)

Accepts an incoming call.

callerName The name of the caller. callerNumber The number of the caller. destinationNumber The destination number (usually the current user's number). clientState The client state. callId The unique ID of the call. invite The incoming invite parameters. customHeaders Custom headers to include in the answer. isAttach Whether this is an attach call.

Implementation

void accept(
  String callerName,
  String callerNumber,
  String destinationNumber,
  String clientState,
  String callId,
  IncomingInviteParams invite,
  Map<String, String> customHeaders,
  bool isAttach,
) async {
  CallTimingBenchmark.start();
  final sessionId = _selfId;
  final Session session = await _createSession(
    null,
    peerId: Uuid().v4(),
    sessionId: sessionId,
    callId: callId,
    media: 'audio',
  );
  _sessions[sessionId] = session;

  await session.peerConnection?.setRemoteDescription(
    RTCSessionDescription(invite.sdp, 'offer'),
  );
  CallTimingBenchmark.mark('remote_sdp_set');

  // Process any queued candidates after setting remote SDP
  if (session.remoteCandidates.isNotEmpty) {
    GlobalLogger().i(
      'Peer :: Processing queued remote candidates after setting remote SDP in accept',
    );
    for (var candidate in session.remoteCandidates) {
      if (candidate.candidate != null) {
        GlobalLogger()
            .i('Peer :: Adding queued candidate: ${candidate.candidate}');
        await session.peerConnection?.addCandidate(candidate);
      }
    }
    session.remoteCandidates.clear();
    GlobalLogger()
        .i('Peer :: Cleared queued candidates after processing in accept');
  }

  await _createAnswer(
    session,
    'audio',
    callerName,
    callerNumber,
    destinationNumber,
    clientState,
    callId,
    customHeaders,
    isAttach,
  );

  onCallStateChange?.call(session, CallState.active);
}