Skip to content

Commit

Permalink
fix recursive reconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3orblade committed Feb 9, 2024
1 parent 463ab38 commit 2d463e2
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/ts/lib/api/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Dispatcher {
return;
};

window.clearTimeout(this.timeoutStream);

const request = new Commands.StreamRequest();
request.setToken(authStore.token);

Expand All @@ -60,28 +62,31 @@ class Dispatcher {
this.stream.on('status', (status) => {
if (status.code) {
console.error('[Dispatcher.stream] Restarting', status);
this.listenEvents();
this.reconnect();
};
});

this.stream.on('end', () => {
console.error('[Dispatcher.stream] end, restarting');
this.reconnect();
});
};

let t = 3;
if (this.reconnects == 20) {
t = 5;
};
if (this.reconnects == 40) {
t = 60;
this.reconnects = 0;
};
reconnect () {
let t = 3;
if (this.reconnects == 20) {
t = 5;
};
if (this.reconnects == 40) {
t = 60;
this.reconnects = 0;
};

window.clearTimeout(this.timeoutStream);
this.timeoutStream = window.setTimeout(() => {
this.listenEvents();
this.reconnects++;
}, t * 1000);
});
window.clearTimeout(this.timeoutStream);
this.timeoutStream = window.setTimeout(() => {
this.listenEvents();
this.reconnects++;
}, t * 1000);
};

eventType (v: number): string {
Expand Down

0 comments on commit 2d463e2

Please sign in to comment.