startIceRenegotiation method
Starts ICE renegotiation process when ICE connection fails
Implementation
Future<void> startIceRenegotiation(String callId, String sessionId) async {
try {
GlobalLogger()
.i('Web Peer :: Starting ICE renegotiation for call: $callId');
if (_sessions[sessionId] != null) {
onCallStateChange?.call(_sessions[sessionId]!, CallState.renegotiation);
final peerConnection = _sessions[sessionId]?.peerConnection;
if (peerConnection == null) {
GlobalLogger().e(
'Web Peer :: No peer connection found for session: $sessionId',
);
return;
}
// Create constraints with IceRestart flag to force ICE restart
final constraints = {
'mandatory': {'IceRestart': true},
'optional': [],
};
// Create new offer with ICE restart enabled
final offer = await peerConnection.createOffer(constraints);
// Set the local description with the new local SDP
await peerConnection.setLocalDescription(offer);
GlobalLogger().i(
'Web Peer :: Created new offer with ICE restart, waiting for ICE candidates...',
);
// Set up callback for when negotiation is complete
_setOnNegotiationComplete(() async {
// Get the complete SDP with ICE candidates from the peer connection
final localDescription = await peerConnection.getLocalDescription();
if (localDescription != null && localDescription.sdp != null) {
_sendUpdateMediaMessage(callId, sessionId, localDescription.sdp!);
} else {
GlobalLogger().e(
'Web Peer :: No local description found with ICE candidates',
);
}
});
// Start negotiation timer
_startNegotiationTimer();
}
} catch (e) {
GlobalLogger().e('Web Peer :: Error during ICE renegotiation: $e');
}
}