remoteSessionReceived method

void remoteSessionReceived(
  1. String sdp
)

Sets the remote session description when an answer is received.

sdp The SDP string of the remote description.

Implementation

void remoteSessionReceived(String sdp) async {
  CallTimingBenchmark.start(isOutbound: true);
  await _sessions[_selfId]?.peerConnection?.setRemoteDescription(
        RTCSessionDescription(sdp, 'answer'),
      );
  CallTimingBenchmark.mark('remote_answer_sdp_set');

  // Process any queued candidates after setting remote SDP
  final session = _sessions[_selfId];
  if (session != null && session.remoteCandidates.isNotEmpty) {
    GlobalLogger()
        .i('Peer :: Processing queued remote candidates after remote SDP');
    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');
  }
}