Fix: Better reconnect handling in Live View if invalid data where received

This commit is contained in:
Thomas Basler 2023-09-02 12:22:55 +02:00
parent 6127fbe940
commit 986d67a3d0

View File

@ -487,9 +487,13 @@ export default defineComponent({
console.log(event); console.log(event);
if (event.data != "{}") { if (event.data != "{}") {
this.liveData = JSON.parse(event.data); this.liveData = JSON.parse(event.data);
}
this.dataLoading = false; this.dataLoading = false;
this.heartCheck(); // Reset heartbeat detection 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.socket.onopen = function (event) { this.socket.onopen = function (event) {
@ -512,7 +516,7 @@ export default defineComponent({
}, 1000); }, 1000);
}, },
// Send heartbeat packets regularly * 59s Send a heartbeat // Send heartbeat packets regularly * 59s Send a heartbeat
heartCheck() { heartCheck(duration: number = 59) {
this.heartInterval && clearTimeout(this.heartInterval); this.heartInterval && clearTimeout(this.heartInterval);
this.heartInterval = setInterval(() => { this.heartInterval = setInterval(() => {
if (this.socket.readyState === 1) { if (this.socket.readyState === 1) {
@ -521,7 +525,7 @@ export default defineComponent({
} else { } else {
this.initSocket(); // Breakpoint reconnection 5 Time this.initSocket(); // Breakpoint reconnection 5 Time
} }
}, 59 * 1000); }, duration * 1000);
}, },
/** To break off websocket Connect */ /** To break off websocket Connect */
closeSocket() { closeSocket() {