diff --git a/discord.wsrewrite.js b/discord.wsrewrite.js index e930190d..496b9aef 100644 --- a/discord.wsrewrite.js +++ b/discord.wsrewrite.js @@ -16145,8 +16145,7 @@ class WebSocketConnection extends EventEmitter { this.emit('close', event); this.heartbeat(-1); // Should we reconnect? - const shouldReconnect = ![1000, 4004, 4010, 4011].includes(event.code); - if (shouldReconnect) this.reconnect(); + if (![1000, 4004, 4010, 4011].includes(event.code)) this.reconnect(); else this.destroy(); } @@ -24675,25 +24674,48 @@ class WebSocketManager extends EventEmitter { this.connection = null; } + /** + * Sends a heartbeat on the available connection + * @returns {void} + */ heartbeat() { if (!this.connection) return this.debug('No connection to heartbeat'); return this.connection.heartbeat(); } + /** + * Emits a debug event + * @param {string} message the debug message + * @returns {void} + */ debug(message) { return this.client.emit('debug', `[ws] ${message}`); } + /** + * Destroy the client + * @returns {boolean} Whether or not destruction was successful + */ destroy() { if (!this.connection) return this.debug('Attempted to destroy WebSocket but no connection exists!'); return this.connection.destroy(); } + /** + * Send a packet on the available WebSocket + * @param {Object} packet the packet to send + * @returns {void} + */ send(packet) { if (!this.connection) return this.debug('No connection to websocket'); return this.connection.send(packet); } + /** + * Connects the client to a gateway + * @param {string} gateway the gateway to connect to + * @returns {boolean} + */ connect(gateway) { if (!this.connection) { this.connection = new WebSocketConnection(this, gateway);