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.eventPhase == EventSource.CLOSED ) source.close();
if ( e.target.readyState == EventSource.CLOSED ) { 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 );
} }
setTimeout( () => {
if ( !self.isReconnecting ) {
self.isReconnecting = true;
self.tryReconnect();
}
}, 1000 );
}, false ); }, false );
}, },
tryReconnect() { tryReconnect() {
@@ -667,7 +668,7 @@ const app = Vue.createApp( {
if ( !this.isReconnecting ) { if ( !this.isReconnecting ) {
clearInterval( int ); clearInterval( int );
} else { } else {
connectToSSESource(); this.connectToNotifier();
} }
}, 1000 ); }, 1000 );
}, },

View File

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