Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions lib/features/call/bloc/call_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2187,21 +2187,35 @@ class CallBloc extends Bloc<CallEvent, CallState> with WidgetsBindingObserver im
'__onPeerConnectionEventIceConnectionStateChanged: peerConnection is null - most likely some state issue',
);
} else {
await peerConnection.restartIce();
final localDescription = await peerConnection.createOffer({});
sdpMunger?.apply(localDescription);

// According to RFC 8829 5.6 (https://datatracker.ietf.org/doc/html/rfc8829#section-5.6),
// localDescription should be set before sending the answer to transition into stable state.
await peerConnection.setLocalDescription(localDescription);

final updateRequest = UpdateRequest(
transaction: WebtritSignalingClient.generateTransactionId(),
line: activeCall.line,
callId: activeCall.callId,
jsep: localDescription.toMap(),
);
await _signalingClient?.execute(updateRequest);
final pcState = peerConnection.signalingState;
if (pcState == RTCSignalingState.RTCSignalingStateStable) {
await peerConnection.restartIce();
final localDescription = await peerConnection.createOffer({});
sdpMunger?.apply(localDescription);

final currentState = peerConnection.signalingState;
if (currentState == RTCSignalingState.RTCSignalingStateStable) {
// According to the WebRTC spec (https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-setlocaldescription),
// setLocalDescription must be called before sending the offer to the remote side.
await peerConnection.setLocalDescription(localDescription);

final updateRequest = UpdateRequest(
transaction: WebtritSignalingClient.generateTransactionId(),
line: activeCall.line,
callId: activeCall.callId,
jsep: localDescription.toMap(),
);
await _signalingClient?.execute(updateRequest);
} else {
_logger.warning(
'__onPeerConnectionEventIceConnectionStateChanged: signalingState changed mid-flight ($currentState), skipping setLocalDescription',
);
}
} else {
_logger.warning(
'__onPeerConnectionEventIceConnectionStateChanged: signalingState is $pcState, skipping ICE restart',
);
}
}
});
} catch (e, stackTrace) {
Expand Down
Loading
Loading