diff --git a/src/gateway/gatewayClient.ts b/src/gateway/gatewayClient.ts index 986a792..807002f 100644 --- a/src/gateway/gatewayClient.ts +++ b/src/gateway/gatewayClient.ts @@ -1,9 +1,9 @@ import zlib from 'fast-zlib'; import WebSocket from 'ws'; - import type { Client } from '../client/client'; import type { IGatewayMessage } from '../utils/types'; + export class GatewayClient { public client: Client; public connection: WebSocket | null; @@ -38,7 +38,11 @@ export class GatewayClient { this.connection.on('message', async (msg: Buffer | string) => { let parsedMessage: IGatewayMessage; - if (this.client.options.ws.compression) parsedMessage = this.inflate.process(msg); + if (this.client.options.ws.compression && typeof msg === 'object') parsedMessage = JSON.parse(this.inflate.process(msg).toString('utf8')); + else if (!this.client.options.ws.compression && typeof msg === 'string') parsedMessage = JSON.parse(msg); + else parsedMessage = JSON.parse(msg.toString('utf8')); + + if (parsedMessage.s) this._sequence = parsedMessage.s; }); } }