mirror of
https://github.com/danbulant/discord.js
synced 2026-06-19 14:41:36 +00:00
Webpack build for branch wsrewrite: 4025fd733350a111076e35b686f1f30dd90a931a
This commit is contained in:
parent
3443dc45db
commit
8a49e8691a
1 changed files with 24 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue