Skip to content

Commit

Permalink
Update AbstractLiveClient.ts to close #317
Browse files Browse the repository at this point in the history
Mismatch client protocol when using Bun native Websockets.
If bun env is detected we replace native websocket with "ws"
  • Loading branch information
matannahmani authored and lukeocodes committed Jul 23, 2024
1 parent 034d5b0 commit f247994
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/packages/AbstractLiveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ export abstract class AbstractLiveClient extends AbstractClient {
return;
}

/**
* @summary Bun websocket transport has a bug where it's native WebSocket implementation messes up the headers
* @summary This is a workaround to use the WS package for the websocket connection instead of the native Bun WebSocket
* @summary you can track the issue here
* @link https://github.com/oven-sh/bun/issues/4529
*/
if (process?.versions?.bun) {
import("ws").then(({ default: WS }) => {
this.conn = new WS(requestUrl, {
headers: this.headers,
});
console.log(`Using WS package`);
this.setupConnection();
});
return;
}

/**
* Native websocket transport (browser)
*/
Expand Down

0 comments on commit f247994

Please sign in to comment.