From 8c50b484cf04340cbd1561a1993825b6c8e79beb Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 16 Nov 2023 09:51:40 +0000 Subject: [PATCH] fix(overlay): reset state when losing connection to the data provider --- src/lib/overlay/httpSiraStatus.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/overlay/httpSiraStatus.ts b/src/lib/overlay/httpSiraStatus.ts index 470e375..acb46d8 100644 --- a/src/lib/overlay/httpSiraStatus.ts +++ b/src/lib/overlay/httpSiraStatus.ts @@ -34,6 +34,16 @@ async function loadIntoSong(data: any) { }); } +/** + * Reset the state of the overlay + */ +function resetState() { + overlayDataStore.setState({ + scoreStats: undefined, + songInfo: undefined, + }); +} + type Handlers = { [key: string]: (data: any) => void; }; @@ -65,16 +75,10 @@ const handlers: Handlers = { // Left the song finished: (data: any) => { - overlayDataStore.setState({ - scoreStats: undefined, - songInfo: undefined, - }); + resetState(); }, menu: (data: any) => { - overlayDataStore.setState({ - scoreStats: undefined, - songInfo: undefined, - }); + resetState(); }, // pause & resume @@ -107,6 +111,7 @@ function connectWebSocket() { console.log( "Lost connection to HttpSiraStatus, reconnecting in 5 seconds...", ); + resetState(); setTimeout(() => { connectWebSocket(); }, 5000); // 5 seconds