remoteSessionReceived method
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);
// Extract and cache remote ICE candidates from the SDP
_callReportCollector?.cacheIceCandidatesFromSdp(sdp, isLocal: false);
await _sessions[_selfId]?.peerConnection?.setRemoteDescription(
RTCSessionDescription(sdp, 'answer'),
);
CallTimingBenchmark.mark('remote_answer_sdp_set');
// Latency milestones for outbound call remote SDP
// Find the call ID for the current session
String? remoteSdpCallId;
for (final call in _txClient.calls.values) {
if (call.peerConnection == this) {
remoteSdpCallId = call.callId;
break;
}
}
if (remoteSdpCallId != null) {
_txClient.latencyTracker.markCallMilestone(remoteSdpCallId, LatencyTracker.milestoneRemoteSdpReceived);
_txClient.latencyTracker.markCallMilestone(remoteSdpCallId, LatencyTracker.milestoneRemoteSdpSet);
}
// 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');
}
}