fix: zlib

This commit is contained in:
MARCROCK22 2024-08-03 00:59:21 +00:00
parent 2c69e1cb41
commit ef4f487257
2 changed files with 7 additions and 5 deletions

View File

@ -101,7 +101,7 @@ export class Shard {
// biome-ignore lint/correctness/noUndeclaredVariables: /\ bun lol // biome-ignore lint/correctness/noUndeclaredVariables: /\ bun lol
this.websocket = new BaseSocket(typeof Bun === 'undefined' ? 'ws' : 'bun', this.currentGatewayURL); 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); this.handleMessage(data);
}; };

View File

@ -1,7 +1,6 @@
import { randomBytes, createHash, randomUUID } from 'node:crypto'; import { randomBytes, createHash, randomUUID } from 'node:crypto';
import { request } from 'node:https'; import { request } from 'node:https';
import type { Socket } from 'node:net'; import type { Socket } from 'node:net';
import { inflateSync } from 'node:zlib';
export class SeyfertWebSocket { export class SeyfertWebSocket {
socket?: Socket = undefined; socket?: Socket = undefined;
@ -23,7 +22,7 @@ export class SeyfertWebSocket {
) { ) {
const urlParts = new URL(url); const urlParts = new URL(url);
this.hostname = urlParts.hostname || ''; this.hostname = urlParts.hostname || '';
this.path = `${urlParts.pathname}${urlParts.search || ''}&encoding=json`; this.path = `${urlParts.pathname}${urlParts.search || ''}`;
this.connect(); this.connect();
} }
@ -121,7 +120,10 @@ export class SeyfertWebSocket {
break; break;
// binary // binary
case 0x2: case 0x2:
this.onmessage({ data: inflateSync(body, { info: true }).buffer.toString() }); {
if (body[1] === 80) body = body.subarray(6);
this.onmessage({ data: body });
}
break; break;
// pong // pong
case 0x9: case 0x9:
@ -175,7 +177,7 @@ export class SeyfertWebSocket {
onopen() {} onopen() {}
onmessage(_payload: { data: string }) {} onmessage(_payload: { data: string | Buffer }) {}
onclose(_close: { code: number; reason: string }) {} onclose(_close: { code: number; reason: string }) {}