Skip to content
Draft
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
18 changes: 17 additions & 1 deletion src/modules/StreamingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,23 @@ export class StreamingClient {
}
this.resetAttemptScopedMilestoneState();
this.connectionMilestones?.record('connection_start_requested');
// start the connection
// Pre-gather ICE candidates in parallel with the WebSocket handshake.
// Creating the peer connection and local offer now starts ICE gathering
// (including any TURN allocation) immediately, instead of waiting for the
// socket to open. The offer and trickled candidates are queued by the
// SignallingClient's sending buffer and flushed, in order, once the
// socket opens - so the connection can proceed as soon as signalling is up.
void this.initPeerConnectionAndSendOffer().catch((error) => {
console.error(
'StreamingClient - startConnection: error preparing peer connection',
error,
);
// If the connection was torn down while the pre-gather task was still
// in flight, shutdown() has already set iceRestartStopped and the
// rejection is expected - don't surface a spurious WebRTC failure.
if (!this.iceRestartStopped) this.handleWebrtcFailure(error);
});
// Establish the signalling channel concurrently with ICE gathering.
this.signallingClient.connect();
} catch (error) {
console.error('StreamingClient - startConnection: error', error);
Expand Down