mirror of
https://github.com/danbulant/discord.js
synced 2026-07-06 19:50:55 +00:00
add docs for ClientManager
This commit is contained in:
parent
24df1bc621
commit
e0c987c1b2
2 changed files with 26 additions and 1 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,12 +1,32 @@
|
||||||
const Constants = require('../util/Constants');
|
const Constants = require('../util/Constants');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the State and Background Tasks of the Client
|
||||||
|
* @class ClientManager
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
class ClientManager {
|
class ClientManager {
|
||||||
|
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
/**
|
||||||
|
* The Client that instantiated this Manager
|
||||||
|
* @type {Client}
|
||||||
|
*/
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
/**
|
||||||
|
* The heartbeat interval, null if not yet set
|
||||||
|
* @type {?Number}
|
||||||
|
*/
|
||||||
this.heartbeatInterval = null;
|
this.heartbeatInterval = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
connectToWebSocket(token, resolve, reject) {
|
connectToWebSocket(token, resolve, reject) {
|
||||||
this.client.store.token = token;
|
this.client.store.token = token;
|
||||||
this.client.rest.methods.getGateway()
|
this.client.rest.methods.getGateway()
|
||||||
|
|
@ -19,6 +39,11 @@ class ClientManager {
|
||||||
setTimeout(() => reject(Constants.Errors.TOOK_TOO_LONG), 1000 * 15);
|
setTimeout(() => reject(Constants.Errors.TOOK_TOO_LONG), 1000 * 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
setupKeepAlive(time) {
|
setupKeepAlive(time) {
|
||||||
this.heartbeatInterval = setInterval(() => {
|
this.heartbeatInterval = setInterval(() => {
|
||||||
this.client.ws.send({
|
this.client.ws.send({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue