Skip to content

Commit

Permalink
chore: keep using npm module for now
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Jul 9, 2023
1 parent 8e0be7c commit 1cb29b7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/ws/src/ws/WebSocketShard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -83,9 +83,11 @@ export interface SendRateLimitState {
export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
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;

Expand Down Expand Up @@ -495,7 +497,7 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
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;
}
}
Expand Down

0 comments on commit 1cb29b7

Please sign in to comment.