Archived
0
0
Fork 0

fix: several small ts errors

This commit is contained in:
Daryl Ronningen 2021-07-14 09:02:09 -07:00
parent b1bdc8cc14
commit ab3553c52e
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B

View file

@ -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<null>;
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;
});
}
}