fix heartbeat issues
This commit is contained in:
@@ -31,7 +31,6 @@ class Localuser {
|
|||||||
guildhtml;
|
guildhtml;
|
||||||
ws;
|
ws;
|
||||||
typing;
|
typing;
|
||||||
wsinterval;
|
|
||||||
connectionSucceed = 0;
|
connectionSucceed = 0;
|
||||||
errorBackoff = 0;
|
errorBackoff = 0;
|
||||||
mfa_enabled;
|
mfa_enabled;
|
||||||
@@ -103,7 +102,6 @@ class Localuser {
|
|||||||
}
|
}
|
||||||
unload() {
|
unload() {
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
clearInterval(this.wsinterval);
|
|
||||||
this.outoffocus();
|
this.outoffocus();
|
||||||
this.guilds = [];
|
this.guilds = [];
|
||||||
this.guildids = new Map();
|
this.guildids = new Map();
|
||||||
@@ -197,8 +195,6 @@ class Localuser {
|
|||||||
});
|
});
|
||||||
this.ws.addEventListener("close", event => {
|
this.ws.addEventListener("close", event => {
|
||||||
console.log("WebSocket closed with code " + event.code);
|
console.log("WebSocket closed with code " + event.code);
|
||||||
if (this.wsinterval)
|
|
||||||
clearInterval(this.wsinterval);
|
|
||||||
this.unload();
|
this.unload();
|
||||||
document.getElementById("loading").classList.remove("doneloading");
|
document.getElementById("loading").classList.remove("doneloading");
|
||||||
document.getElementById("loading").classList.add("loading");
|
document.getElementById("loading").classList.add("loading");
|
||||||
@@ -319,13 +315,20 @@ class Localuser {
|
|||||||
}
|
}
|
||||||
else if (temp.op === 10) {
|
else if (temp.op === 10) {
|
||||||
console.log("heartbeat down");
|
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)
|
if (this.connectionSucceed === 0)
|
||||||
this.connectionSucceed = Date.now();
|
this.connectionSucceed = Date.now();
|
||||||
this.ws.send(JSON.stringify({ op: 1, d: this.lastSequence }));
|
this.ws.send(JSON.stringify({ op: 1, d: this.lastSequence }));
|
||||||
}, temp.d.heartbeat_interval);
|
}, this.heartbeat_interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
heartbeat_interval;
|
||||||
resolveChannelFromID(ID) {
|
resolveChannelFromID(ID) {
|
||||||
let resolve = this.guilds.find(guild => guild.channelids[ID]);
|
let resolve = this.guilds.find(guild => guild.channelids[ID]);
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
|
@@ -35,7 +35,6 @@ class Localuser{
|
|||||||
guildhtml:Map<string, HTMLDivElement>;
|
guildhtml:Map<string, HTMLDivElement>;
|
||||||
ws:WebSocket;
|
ws:WebSocket;
|
||||||
typing:[string,number][];
|
typing:[string,number][];
|
||||||
wsinterval:NodeJS.Timeout;
|
|
||||||
connectionSucceed=0;
|
connectionSucceed=0;
|
||||||
errorBackoff=0;
|
errorBackoff=0;
|
||||||
mfa_enabled:boolean;
|
mfa_enabled:boolean;
|
||||||
@@ -109,7 +108,6 @@ class Localuser{
|
|||||||
}
|
}
|
||||||
unload():void{
|
unload():void{
|
||||||
this.initialized=false;
|
this.initialized=false;
|
||||||
clearInterval(this.wsinterval);
|
|
||||||
this.outoffocus();
|
this.outoffocus();
|
||||||
this.guilds=[];
|
this.guilds=[];
|
||||||
this.guildids=new Map();
|
this.guildids=new Map();
|
||||||
@@ -207,7 +205,6 @@ class Localuser{
|
|||||||
|
|
||||||
this.ws.addEventListener("close", event => {
|
this.ws.addEventListener("close", event => {
|
||||||
console.log("WebSocket closed with code " + event.code);
|
console.log("WebSocket closed with code " + event.code);
|
||||||
if (this.wsinterval) clearInterval(this.wsinterval);
|
|
||||||
|
|
||||||
this.unload();
|
this.unload();
|
||||||
document.getElementById("loading").classList.remove("doneloading");
|
document.getElementById("loading").classList.remove("doneloading");
|
||||||
@@ -329,13 +326,17 @@ class Localuser{
|
|||||||
|
|
||||||
}else if(temp.op===10){
|
}else if(temp.op===10){
|
||||||
console.log("heartbeat down");
|
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()
|
if (this.connectionSucceed===0) this.connectionSucceed=Date.now()
|
||||||
|
|
||||||
this.ws.send(JSON.stringify({op:1,d:this.lastSequence}))
|
this.ws.send(JSON.stringify({op:1,d:this.lastSequence}))
|
||||||
},temp.d.heartbeat_interval)
|
},this.heartbeat_interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
heartbeat_interval:number;
|
||||||
resolveChannelFromID(ID:string):Channel{
|
resolveChannelFromID(ID:string):Channel{
|
||||||
let resolve=this.guilds.find(guild => guild.channelids[ID]);
|
let resolve=this.guilds.find(guild => guild.channelids[ID]);
|
||||||
if(resolve){
|
if(resolve){
|
||||||
|
Reference in New Issue
Block a user