mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
add handler in case heartbeat is not acked (#1013)
* add handler in case heartbeat is not acked * ffs
This commit is contained in:
@@ -416,6 +416,7 @@ class Client extends EventEmitter {
|
|||||||
_pong(startTime) {
|
_pong(startTime) {
|
||||||
this.pings.unshift(Date.now() - startTime);
|
this.pings.unshift(Date.now() - startTime);
|
||||||
if (this.pings.length > 3) this.pings.length = 3;
|
if (this.pings.length > 3) this.pings.length = 3;
|
||||||
|
this.clearTimeout(this._ackTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
_setPresence(id, presence) {
|
_setPresence(id, presence) {
|
||||||
|
|||||||
@@ -48,14 +48,22 @@ class ClientManager {
|
|||||||
* @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) {
|
setupKeepAlive(time) {
|
||||||
this.heartbeatInterval = this.client.setInterval(() => {
|
this.heartbeatInterval = this.client.setInterval(this.ping.bind(this), time);
|
||||||
this.client.emit('debug', 'Sending heartbeat');
|
}
|
||||||
this.client._pingTimestamp = Date.now();
|
|
||||||
this.client.ws.send({
|
ping() {
|
||||||
op: Constants.OPCodes.HEARTBEAT,
|
this.client.emit('debug', 'Sending heartbeat');
|
||||||
d: this.client.ws.sequence,
|
this.client._pingTimestamp = Date.now();
|
||||||
}, true);
|
this.client.ws.send({
|
||||||
}, time);
|
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() {
|
destroy() {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ class ReadyHandler extends AbstractHandler {
|
|||||||
const client = this.packetManager.client;
|
const client = this.packetManager.client;
|
||||||
const data = packet.d;
|
const data = packet.d;
|
||||||
|
|
||||||
|
client.manager.ping();
|
||||||
|
|
||||||
const clientUser = new ClientUser(client, data.user);
|
const clientUser = new ClientUser(client, data.user);
|
||||||
client.user = clientUser;
|
client.user = clientUser;
|
||||||
client.readyAt = new Date();
|
client.readyAt = new Date();
|
||||||
|
|||||||
Reference in New Issue
Block a user