From 1cb29b77891e6f1e861262bedb957712ef2ca098 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Sun, 9 Jul 2023 18:31:15 +0300 Subject: [PATCH] chore: keep using npm module for now --- packages/ws/src/ws/WebSocketShard.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/ws/src/ws/WebSocketShard.ts b/packages/ws/src/ws/WebSocketShard.ts index 45e5ebf1071c..de0a8af3a43f 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, shouldUseGlobalFetchAndWebSocket } from '@discordjs/util'; +import { lazy } from '@discordjs/util'; import { AsyncQueue } from '@sapphire/async-queue'; import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; import { @@ -83,9 +83,11 @@ export interface SendRateLimitState { export class WebSocketShard extends AsyncEventEmitter { private connection: WebSocket | null = null; - private WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket() - ? (globalThis as any).WebSocket - : WebSocket; + // TODO(vladfrangu): enable this once https://github.com/oven-sh/bun/issues/3392 is solved + // private WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket() + // ? (globalThis as any).WebSocket + // : WebSocket; + private WebSocketConstructor: typeof WebSocket = WebSocket; private useIdentifyCompress = false; @@ -495,7 +497,7 @@ export class WebSocketShard extends AsyncEventEmitter { try { return JSON.parse(data as string) as GatewayReceivePayload; } catch { - // Either bun emulates the rejection as a message event or discord sent us invalid JSON, either way, we can't do anything with it + // This is a non-JSON payload / (at the time of writing this comment) emitted by bun wrongly interpreting custom close codes https://github.com/oven-sh/bun/issues/3392 return null; } }