fix reconnecting function (stop it from spamming)

This commit is contained in:
janis
2024-02-01 16:07:16 +01:00
parent 82d2db191d
commit bd42e65f31
2 changed files with 18 additions and 18 deletions

View File

@@ -651,15 +651,16 @@ const app = Vue.createApp( {
if ( e.eventPhase == EventSource.CLOSED ) source.close();
if ( e.target.readyState == EventSource.CLOSED ) {
console.log( 'disconnected' );
}
setTimeout( () => {
if ( !self.isReconnecting ) {
console.log( 'disconnected' );
console.log( 'reconnecting...' );
self.isReconnecting = true;
self.tryReconnect();
}
}, 1000 );
}
}, false );
},
tryReconnect() {
@@ -667,7 +668,7 @@ const app = Vue.createApp( {
if ( !this.isReconnecting ) {
clearInterval( int );
} else {
connectToSSESource();
this.connectToNotifier();
}
}, 1000 );
},

View File

@@ -18,6 +18,7 @@ createApp( {
beatDetected: false,
colorThief: null,
lastDispatch: new Date().getTime() - 5000,
isReconnecting: false,
};
},
computed: {
@@ -148,16 +149,14 @@ createApp( {
if ( e.eventPhase == EventSource.CLOSED ) source.close();
if ( e.target.readyState == EventSource.CLOSED ) {
console.log( 'disconnected' );
}
// TODO: Notify about disconnect
setTimeout( () => {
if ( !self.isReconnecting ) {
console.log( 'disconnected' );
self.isReconnecting = true;
self.tryReconnect();
}
}, 1000 );
}
}, false );
},
tryReconnect() {
@@ -165,7 +164,7 @@ createApp( {
if ( !this.isReconnecting ) {
clearInterval( int );
} else {
connectToSSESource();
this.connect();
}
}, 1000 );
},