fix heartbeat issues
This commit is contained in:
parent
e2e442c604
commit
20b716ae57
2 changed files with 16 additions and 12 deletions
|
@ -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) {
|
||||
|
|
|
@ -35,7 +35,6 @@ class Localuser{
|
|||
guildhtml:Map<string, HTMLDivElement>;
|
||||
ws:WebSocket;
|
||||
typing:[string,number][];
|
||||
wsinterval:NodeJS.Timeout;
|
||||
connectionSucceed=0;
|
||||
errorBackoff=0;
|
||||
mfa_enabled:boolean;
|
||||
|
@ -109,7 +108,6 @@ class Localuser{
|
|||
}
|
||||
unload():void{
|
||||
this.initialized=false;
|
||||
clearInterval(this.wsinterval);
|
||||
this.outoffocus();
|
||||
this.guilds=[];
|
||||
this.guildids=new Map();
|
||||
|
@ -207,7 +205,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");
|
||||
|
@ -329,13 +326,17 @@ 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:number;
|
||||
resolveChannelFromID(ID:string):Channel{
|
||||
let resolve=this.guilds.find(guild => guild.channelids[ID]);
|
||||
if(resolve){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue