diff --git a/frontend/src/client/appleMusic/index.js b/frontend/src/client/appleMusic/index.js index 13bf7f1..49bfd70 100644 --- a/frontend/src/client/appleMusic/index.js +++ b/frontend/src/client/appleMusic/index.js @@ -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 ); } - setTimeout( () => { - if ( !self.isReconnecting ) { - 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 ); }, diff --git a/frontend/src/client/showcase.js b/frontend/src/client/showcase.js index fc99d19..60f0242 100644 --- a/frontend/src/client/showcase.js +++ b/frontend/src/client/showcase.js @@ -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' ); + 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 ); }, tryReconnect() { @@ -165,7 +164,7 @@ createApp( { if ( !this.isReconnecting ) { clearInterval( int ); } else { - connectToSSESource(); + this.connect(); } }, 1000 ); },