fix heartbeat issues

This commit is contained in:
MathMan05 2024-08-11 15:48:39 -05:00
parent e2e442c604
commit 20b716ae57
2 changed files with 16 additions and 12 deletions

View file

@ -31,7 +31,6 @@ class Localuser {
guildhtml;
ws;
typing;
wsinterval;
connectionSucceed = 0;
errorBackoff = 0;
mfa_enabled;
@ -103,7 +102,6 @@ class Localuser {
}
unload() {
this.initialized = false;
clearInterval(this.wsinterval);
this.outoffocus();
this.guilds = [];
this.guildids = new Map();
@ -197,8 +195,6 @@ class Localuser {
});
this.ws.addEventListener("close", event => {
console.log("WebSocket closed with code " + event.code);
if (this.wsinterval)
clearInterval(this.wsinterval);
this.unload();
document.getElementById("loading").classList.remove("doneloading");
document.getElementById("loading").classList.add("loading");
@ -319,13 +315,20 @@ class Localuser {
}
else if (temp.op === 10) {
console.log("heartbeat down");
this.wsinterval = setInterval(_ => {
this.heartbeat_interval = temp.d.heartbeat_interval;
this.ws.send(JSON.stringify({ op: 1, d: this.lastSequence }));
}
else if (temp.op === 11) {
setTimeout(_ => {
if (!this.ws)
return;
if (this.connectionSucceed === 0)
this.connectionSucceed = Date.now();
this.ws.send(JSON.stringify({ op: 1, d: this.lastSequence }));
}, temp.d.heartbeat_interval);
}, this.heartbeat_interval);
}
}
heartbeat_interval;
resolveChannelFromID(ID) {
let resolve = this.guilds.find(guild => guild.channelids[ID]);
if (resolve) {