Skip to content

Commit f247994

Browse files
matannahmanilukeocodes
authored andcommitted
Update AbstractLiveClient.ts to close #317
Mismatch client protocol when using Bun native Websockets. If bun env is detected we replace native websocket with "ws"
1 parent 034d5b0 commit f247994

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/packages/AbstractLiveClient.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ export abstract class AbstractLiveClient extends AbstractClient {
119119
return;
120120
}
121121

122+
/**
123+
* @summary Bun websocket transport has a bug where it's native WebSocket implementation messes up the headers
124+
* @summary This is a workaround to use the WS package for the websocket connection instead of the native Bun WebSocket
125+
* @summary you can track the issue here
126+
* @link https://github.com/oven-sh/bun/issues/4529
127+
*/
128+
if (process?.versions?.bun) {
129+
import("ws").then(({ default: WS }) => {
130+
this.conn = new WS(requestUrl, {
131+
headers: this.headers,
132+
});
133+
console.log(`Using WS package`);
134+
this.setupConnection();
135+
});
136+
return;
137+
}
138+
122139
/**
123140
* Native websocket transport (browser)
124141
*/

0 commit comments

Comments
 (0)