From ef4f48725780a593f1284cad64ebfc396be44d61 Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Sat, 3 Aug 2024 00:59:21 +0000 Subject: [PATCH] fix: zlib --- src/websocket/discord/shard.ts | 2 +- src/websocket/discord/socket/custom.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/websocket/discord/shard.ts b/src/websocket/discord/shard.ts index 1be3dee..b7870f2 100644 --- a/src/websocket/discord/shard.ts +++ b/src/websocket/discord/shard.ts @@ -101,7 +101,7 @@ export class Shard { // biome-ignore lint/correctness/noUndeclaredVariables: /\ bun lol this.websocket = new BaseSocket(typeof Bun === 'undefined' ? 'ws' : 'bun', this.currentGatewayURL); - this.websocket!.onmessage = ({ data }: { data: string }) => { + this.websocket!.onmessage = ({ data }: { data: string | Buffer }) => { this.handleMessage(data); }; diff --git a/src/websocket/discord/socket/custom.ts b/src/websocket/discord/socket/custom.ts index 83b641d..42f1c34 100644 --- a/src/websocket/discord/socket/custom.ts +++ b/src/websocket/discord/socket/custom.ts @@ -1,7 +1,6 @@ import { randomBytes, createHash, randomUUID } from 'node:crypto'; import { request } from 'node:https'; import type { Socket } from 'node:net'; -import { inflateSync } from 'node:zlib'; export class SeyfertWebSocket { socket?: Socket = undefined; @@ -23,7 +22,7 @@ export class SeyfertWebSocket { ) { const urlParts = new URL(url); this.hostname = urlParts.hostname || ''; - this.path = `${urlParts.pathname}${urlParts.search || ''}&encoding=json`; + this.path = `${urlParts.pathname}${urlParts.search || ''}`; this.connect(); } @@ -121,7 +120,10 @@ export class SeyfertWebSocket { break; // binary case 0x2: - this.onmessage({ data: inflateSync(body, { info: true }).buffer.toString() }); + { + if (body[1] === 80) body = body.subarray(6); + this.onmessage({ data: body }); + } break; // pong case 0x9: @@ -175,7 +177,7 @@ export class SeyfertWebSocket { onopen() {} - onmessage(_payload: { data: string }) {} + onmessage(_payload: { data: string | Buffer }) {} onclose(_close: { code: number; reason: string }) {}