This commit is contained in:
hydrabolt
2016-04-16 22:58:49 +01:00
commit 9956e43c8e
43 changed files with 1634 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
'use strict';
const Constants = require('../util/Constants');
class ClientManager {
constructor(client) {
this.client = client;
this.heartbeatInterval = null;
}
connectToWebSocket(token, resolve, reject) {
this.client.store.token = token;
this.client.rest.methods.GetGateway()
.then(gateway => {
this.client.ws.connect(gateway);
this.client.once(Constants.Events.READY, () => resolve(token));
})
.catch(reject);
setTimeout(() => reject(Constants.Errors.TOOK_TOO_LONG), 1000 * 15);
}
setupKeepAlive(time) {
this.heartbeatInterval = setInterval(() => {
this.client.ws.send({
op: Constants.OPCodes.HEARTBEAT,
d: Date.now(),
});
}, time);
}
}
module.exports = ClientManager;