From a234c5476ae98255269311df382344b4021bce23 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Sat, 9 Dec 2023 22:22:44 +0200 Subject: [PATCH] feat: use globally available WebSocket client in runtimes that have it --- packages/ws/src/ws/WebSocketShard.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/ws/src/ws/WebSocketShard.ts b/packages/ws/src/ws/WebSocketShard.ts index 921453a909b9..6575de9461e3 100644 --- a/packages/ws/src/ws/WebSocketShard.ts +++ b/packages/ws/src/ws/WebSocketShard.ts @@ -7,7 +7,7 @@ import { URLSearchParams } from 'node:url'; import { TextDecoder } from 'node:util'; import { inflate } from 'node:zlib'; import { Collection } from '@discordjs/collection'; -import { lazy } from '@discordjs/util'; +import { lazy, shouldUseGlobalFetchAndWebSocket } from '@discordjs/util'; import { AsyncQueue } from '@sapphire/async-queue'; import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; import { @@ -80,11 +80,9 @@ export interface SendRateLimitState { resetAt: number; } -// TODO(vladfrangu): enable this once https://github.com/oven-sh/bun/issues/3392 is solved -// const WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket() -// ? (globalThis as any).WebSocket -// : WebSocket; -const WebSocketConstructor: typeof WebSocket = WebSocket; +const WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket() + ? (globalThis as any).WebSocket + : WebSocket; export class WebSocketShard extends AsyncEventEmitter { private connection: WebSocket | null = null;