mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Cleanup Part 2: Electric Boogaloo (Reloaded) (#594)
* Cleanup Part 2: Electric Boogaloo (Reloaded) * Moar cleanup * Tweak NOT_A_PERMISSION error
This commit is contained in:
committed by
Amish Shah
parent
5a9c42061f
commit
0b908f5bce
@@ -5,7 +5,6 @@ const Constants = require('../util/Constants');
|
||||
* @private
|
||||
*/
|
||||
class ClientManager {
|
||||
|
||||
constructor(client) {
|
||||
/**
|
||||
* The Client that instantiated this Manager
|
||||
@@ -21,25 +20,22 @@ class ClientManager {
|
||||
|
||||
/**
|
||||
* Connects the Client to the WebSocket
|
||||
* @param {string} token the authorization token
|
||||
* @param {function} resolve function to run when connection is successful
|
||||
* @param {function} reject function to run when connection fails
|
||||
* @param {string} token The authorization token
|
||||
* @param {function} resolve Function to run when connection is successful
|
||||
* @param {function} reject Function to run when connection fails
|
||||
*/
|
||||
connectToWebSocket(token, resolve, reject) {
|
||||
this.client.token = token;
|
||||
this.client.rest.methods.getGateway()
|
||||
.then(gateway => {
|
||||
this.client.ws.connect(gateway);
|
||||
this.client.once(Constants.Events.READY, () => resolve(token));
|
||||
})
|
||||
.catch(reject);
|
||||
|
||||
this.client.rest.methods.getGateway().then(gateway => {
|
||||
this.client.ws.connect(gateway);
|
||||
this.client.once(Constants.Events.READY, () => resolve(token));
|
||||
}).catch(reject);
|
||||
this.client.setTimeout(() => reject(Constants.Errors.TOOK_TOO_LONG), 1000 * 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a keep-alive interval to keep the Client's connection valid
|
||||
* @param {number} time the interval in milliseconds at which heartbeat packets should be sent
|
||||
* @param {number} time The interval in milliseconds at which heartbeat packets should be sent
|
||||
*/
|
||||
setupKeepAlive(time) {
|
||||
this.heartbeatInterval = this.client.setInterval(() => {
|
||||
|
||||
Reference in New Issue
Block a user