From ab3553c52e4d526711f0c540038ee1661b5a3c31 Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Wed, 14 Jul 2021 09:02:09 -0700 Subject: [PATCH] fix: several small ts errors --- src/gateway/gatewayClient.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; }); } }