Skip to content

Commit

Permalink
feat: add hasReadyInitRetryInt
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisheng Lu committed Jan 29, 2024
1 parent a369851 commit 1478433
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/discord.ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class WsMessage {
private reconnectTime: boolean[] = [];
private heartbeatInterval = 0;
private hasReadyInit = false;
private hasReadyInitRetryInt:any;
private hasReadyInitRetryCount=0;
public UserId = "";
constructor(public config: MJConfig, public MJApi: MidjourneyApi) {
this.ws = new this.config.WebSocket(this.config.WsBaseUrl);
Expand Down Expand Up @@ -89,10 +91,24 @@ export class WsMessage {
}
//try reconnect
reconnect() {
const that=this;
if(!this.hasReadyInit){
return;
}
this.hasReadyInit=false;
clearInterval(this.hasReadyInitRetryInt)
this.hasReadyInitRetryInt=setInterval(async ()=>{
that.hasReadyInit=true;
console.log('reconnect setInterval',that.config?.ChannelId, that.hasReadyInitRetryCount)
if(that.ws.readyState !== that.ws.OPEN&&that.hasReadyInitRetryCount<3){
that.hasReadyInitRetryCount++
that.reconnect();
await that.onceReady();
}else{
clearInterval(that.hasReadyInitRetryInt)
that.hasReadyInitRetryCount=0;
}
},30*1000)
console.log('-------- reconnect2',this.config?.ChannelId)
this.ws = new this.config.WebSocket(this.config.WsBaseUrl);
this.heartbeatInterval = 0;
Expand Down

0 comments on commit 1478433

Please sign in to comment.