Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't attempt to recover broken WebSockets when there isn't a network connection #1490

Merged
merged 7 commits into from
Sep 20, 2024
22 changes: 19 additions & 3 deletions packages/client/src/StreamSfuClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,33 @@ export class StreamSfuClient {
},
},
}),
2000, // two-second timeout for leave request
);
};

private send = async (message: SfuRequest) => {
await this.signalReady; // wait for the signal ws to be open
/**
* Sends a message to the SFU via the WebSocket connection.
*
* @param message the message to send.
* @param timeout an optional timeout in milliseconds for sending the message.
*/
private send = async (message: SfuRequest, timeout: number = 0) => {
// wait for the signal ws to be open
if (timeout > 0) {
await Promise.race([
this.signalReady,
new Promise((_, reject) => {
setTimeout(() => reject(new Error('Timeout sending msg')), timeout);
}),
]);
} else {
await this.signalReady;
}
const msgJson = SfuRequest.toJson(message);
if (this.signalWs.readyState !== WebSocket.OPEN) {
this.logger('debug', 'Signal WS is not open. Skipping message', msgJson);
return;
}
this.logger('debug', `Sending message to: ${this.edgeName}`, msgJson);
this.signalWs.send(SfuRequest.toBinary(message));
};

Expand Down
Loading