mirror of
https://github.com/danbulant/discord.js
synced 2026-07-05 19:20:42 +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.emit('close', event);
|
||||||
this.heartbeat(-1);
|
this.heartbeat(-1);
|
||||||
// Should we reconnect?
|
// Should we reconnect?
|
||||||
const shouldReconnect = ![1000, 4004, 4010, 4011].includes(event.code);
|
if (![1000, 4004, 4010, 4011].includes(event.code)) this.reconnect();
|
||||||
if (shouldReconnect) this.reconnect();
|
|
||||||
else this.destroy();
|
else this.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24675,25 +24674,48 @@ class WebSocketManager extends EventEmitter {
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a heartbeat on the available connection
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
heartbeat() {
|
heartbeat() {
|
||||||
if (!this.connection) return this.debug('No connection to heartbeat');
|
if (!this.connection) return this.debug('No connection to heartbeat');
|
||||||
return this.connection.heartbeat();
|
return this.connection.heartbeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits a debug event
|
||||||
|
* @param {string} message the debug message
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
debug(message) {
|
debug(message) {
|
||||||
return this.client.emit('debug', `[ws] ${message}`);
|
return this.client.emit('debug', `[ws] ${message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the client
|
||||||
|
* @returns {boolean} Whether or not destruction was successful
|
||||||
|
*/
|
||||||
destroy() {
|
destroy() {
|
||||||
if (!this.connection) return this.debug('Attempted to destroy WebSocket but no connection exists!');
|
if (!this.connection) return this.debug('Attempted to destroy WebSocket but no connection exists!');
|
||||||
return this.connection.destroy();
|
return this.connection.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a packet on the available WebSocket
|
||||||
|
* @param {Object} packet the packet to send
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
send(packet) {
|
send(packet) {
|
||||||
if (!this.connection) return this.debug('No connection to websocket');
|
if (!this.connection) return this.debug('No connection to websocket');
|
||||||
return this.connection.send(packet);
|
return this.connection.send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connects the client to a gateway
|
||||||
|
* @param {string} gateway the gateway to connect to
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
connect(gateway) {
|
connect(gateway) {
|
||||||
if (!this.connection) {
|
if (!this.connection) {
|
||||||
this.connection = new WebSocketConnection(this, gateway);
|
this.connection = new WebSocketConnection(this, gateway);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue