Skip to content

Commit

Permalink
Fix: Better reconnect handling in Live View if invalid data where rec…
Browse files Browse the repository at this point in the history
…eived
  • Loading branch information
tbnobody committed Sep 2, 2023
1 parent 6127fbe commit 986d67a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions webapp/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,13 @@ export default defineComponent({
console.log(event);
if (event.data != "{}") {
this.liveData = JSON.parse(event.data);
this.dataLoading = false;
this.heartCheck(); // Reset heartbeat detection
} else {
// Sometimes it does not recover automatically so have to force a reconnect
this.closeSocket();
this.heartCheck(10); // Reconnect faster
}
this.dataLoading = false;
this.heartCheck(); // Reset heartbeat detection
};
this.socket.onopen = function (event) {
Expand All @@ -512,7 +516,7 @@ export default defineComponent({
}, 1000);
},
// Send heartbeat packets regularly * 59s Send a heartbeat
heartCheck() {
heartCheck(duration: number = 59) {
this.heartInterval && clearTimeout(this.heartInterval);
this.heartInterval = setInterval(() => {
if (this.socket.readyState === 1) {
Expand All @@ -521,7 +525,7 @@ export default defineComponent({
} else {
this.initSocket(); // Breakpoint reconnection 5 Time
}
}, 59 * 1000);
}, duration * 1000);
},
/** To break off websocket Connect */
closeSocket() {
Expand Down

0 comments on commit 986d67a

Please sign in to comment.