Immediately Heartbeat on HELLO for non-zero ping initially
This commit is contained in:
parent
f6eaa739ab
commit
e40b7bd544
1 changed files with 26 additions and 14 deletions
|
@ -76,21 +76,10 @@ class Gateway {
|
|||
this.debug(
|
||||
`Received HELLO. Heartbeat Interval: ${this.heartbeatInterval}`
|
||||
)
|
||||
this.heartbeatIntervalID = setInterval(() => {
|
||||
if (this.heartbeatServerResponded) {
|
||||
this.heartbeatServerResponded = false
|
||||
} else {
|
||||
clearInterval(this.heartbeatIntervalID)
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.reconnect()
|
||||
return
|
||||
}
|
||||
|
||||
this.send({
|
||||
op: GatewayOpcodes.HEARTBEAT,
|
||||
d: this.sequenceID ?? null
|
||||
})
|
||||
this.lastPingTimestamp = Date.now()
|
||||
this.sendHeartbeat()
|
||||
this.heartbeatIntervalID = setInterval(() => {
|
||||
this.heartbeat()
|
||||
}, this.heartbeatInterval)
|
||||
|
||||
if (!this.initialized) {
|
||||
|
@ -305,6 +294,29 @@ class Gateway {
|
|||
d: data
|
||||
})
|
||||
}
|
||||
|
||||
sendHeartbeat() {
|
||||
const payload = {
|
||||
op: GatewayOpcodes.HEARTBEAT,
|
||||
d: this.sequenceID ?? null
|
||||
};
|
||||
|
||||
this.send(payload)
|
||||
this.lastPingTimestamp = Date.now()
|
||||
}
|
||||
|
||||
heartbeat() {
|
||||
if (this.heartbeatServerResponded) {
|
||||
this.heartbeatServerResponded = false
|
||||
} else {
|
||||
clearInterval(this.heartbeatIntervalID)
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.reconnect()
|
||||
return
|
||||
}
|
||||
|
||||
this.sendHeartbeat()
|
||||
}
|
||||
}
|
||||
|
||||
export type GatewayEventHandler = (gateway: Gateway, d: any) => void
|
||||
|
|
Loading…
Reference in a new issue