Skip to content

Commit b9da036

Browse files
committed
fix usage with cloudflare workers
Cloudflare Workers (and other runtimes, including Node v22+) have a native global standards based Websocket class. This patch detects it and uses it when available.
1 parent 339e955 commit b9da036

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export class RealtimeAPI extends RealtimeEventHandler {
6363
if (this.isConnected()) {
6464
throw new Error(`Already connected`);
6565
}
66-
if (globalThis.document) {
66+
if (globalThis.WebSocket) {
6767
/**
6868
* Web browser
6969
*/
70-
if (this.apiKey) {
70+
if (globalThis.document && this.apiKey) {
7171
console.warn(
7272
'Warning: Connecting using API key in the browser, this is not recommended',
7373
);

0 commit comments

Comments
 (0)