add handler in case heartbeat is not acked (#1013)

* add handler in case heartbeat is not acked

* ffs
This commit is contained in:
Gus Caplan
2016-12-24 05:04:27 -06:00
committed by Amish Shah
parent 7c12fdcb56
commit 3eca3ba95e
3 changed files with 19 additions and 8 deletions

View File

@@ -48,14 +48,22 @@ class ClientManager {
* @param {number} time The interval in milliseconds at which heartbeat packets should be sent
*/
setupKeepAlive(time) {
this.heartbeatInterval = this.client.setInterval(() => {
this.client.emit('debug', 'Sending heartbeat');
this.client._pingTimestamp = Date.now();
this.client.ws.send({
op: Constants.OPCodes.HEARTBEAT,
d: this.client.ws.sequence,
}, true);
}, time);
this.heartbeatInterval = this.client.setInterval(this.ping.bind(this), time);
}
ping() {
this.client.emit('debug', 'Sending heartbeat');
this.client._pingTimestamp = Date.now();
this.client.ws.send({
op: Constants.OPCodes.HEARTBEAT,
d: this.client.ws.sequence,
}, true);
const lastPing = this.client.ping;
this.client._ackTimeout = this.client.setTimeout(() => {
this.client.ws.ws.close(1005);
}, lastPing ? lastPing * 20 : 20e3);
}
destroy() {