Skip to content

Commit

Permalink
Prevent heartbeat during identify (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 authored Nov 10, 2021
1 parent e8dfcbb commit 5db41aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,7 @@ declare namespace Eris {
requestMembersPromise: { [s: string]: RequestMembersPromise };
seq: number;
sessionID: string | null;
status: "disconnected" | "connecting" | "handshaking" | "ready" | "resuming";
status: "connecting" | "disconnected" | "handshaking" | "identifying" | "ready" | "resuming";
unsyncedGuilds: number;
ws: WebSocket | BrowserWebSocket | null;
constructor(id: number, client: Client);
Expand Down
7 changes: 4 additions & 3 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ try {
* @prop {Number} lastHeartbeatSent Last time shard sent a heartbeat, null if shard has not sent heartbeat yet
* @prop {Number} latency The current latency between the shard and Discord, in milliseconds
* @prop {Boolean} ready Whether the shard is ready
* @prop {String} status The status of the shard. "disconnected"/"connecting"/"handshaking"/"ready"
* @prop {String} status The status of the shard. "disconnected"/"connecting"/"handshaking"/"ready"/"identifying"/"resuming"
*/
class Shard extends EventEmitter {
constructor(id, client) {
Expand Down Expand Up @@ -287,8 +287,8 @@ class Shard extends EventEmitter {
}

heartbeat(normal) {
// Can only heartbeat after resume succeeds, discord/discord-api-docs#1619
if(this.status === "resuming") {
// Can only heartbeat after identify/resume succeeds, session will be killed otherwise, discord/discord-api-docs#1619
if(this.status === "resuming" || this.status === "identifying") {
return;
}
if(normal) {
Expand Down Expand Up @@ -321,6 +321,7 @@ class Shard extends EventEmitter {
this.emit("error", new Error("pako/zlib-sync not found, cannot decompress data"));
return;
}
this.status = "identifying";
const identify = {
token: this._token,
v: GATEWAY_VERSION,
Expand Down

0 comments on commit 5db41aa

Please sign in to comment.