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: improved error handling when connecting to an SFU #1648

Merged
merged 3 commits into from
Jan 20, 2025
Merged
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
13 changes: 10 additions & 3 deletions packages/client/src/StreamSfuClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,23 @@ export class StreamSfuClient {
},
});

this.signalWs.addEventListener('close', this.handleWebSocketClose);

this.signalReady = makeSafePromise(
Promise.race<WebSocket>([
new Promise((resolve) => {
new Promise((resolve, reject) => {
const onOpen = () => {
this.signalWs.removeEventListener('open', onOpen);
resolve(this.signalWs);
};

this.signalWs.addEventListener('open', onOpen);

this.signalWs.addEventListener('close', () => {
this.handleWebSocketClose();
// Normally, this shouldn't have any effect, because WS should never emit 'close'
// before emitting 'open'. However, strager things have happened, and we don't
// want to leave signalReady in pending state.
reject(new Error('SFU WS closed unexpectedly'));
});
}),

new Promise((resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/rtc/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const createWebSocketSignalChannel = (opts: {
}) => {
const { endpoint, onMessage, logTag } = opts;
const logger = getLogger(['SfuClientWS', logTag]);
logger('debug', 'Creating signaling WS channel:', endpoint);
const ws = new WebSocket(endpoint);
ws.binaryType = 'arraybuffer'; // do we need this?

Expand Down
Loading