fix(overlay): reset state when losing connection to the data provider
Some checks failed
deploy / deploy (push) Failing after 18s

This commit is contained in:
Lee 2023-11-16 09:51:40 +00:00
parent 3c5b5be02f
commit 8c50b484cf

@ -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 = { type Handlers = {
[key: string]: (data: any) => void; [key: string]: (data: any) => void;
}; };
@ -65,16 +75,10 @@ const handlers: Handlers = {
// Left the song // Left the song
finished: (data: any) => { finished: (data: any) => {
overlayDataStore.setState({ resetState();
scoreStats: undefined,
songInfo: undefined,
});
}, },
menu: (data: any) => { menu: (data: any) => {
overlayDataStore.setState({ resetState();
scoreStats: undefined,
songInfo: undefined,
});
}, },
// pause & resume // pause & resume
@ -107,6 +111,7 @@ function connectWebSocket() {
console.log( console.log(
"Lost connection to HttpSiraStatus, reconnecting in 5 seconds...", "Lost connection to HttpSiraStatus, reconnecting in 5 seconds...",
); );
resetState();
setTimeout(() => { setTimeout(() => {
connectWebSocket(); connectWebSocket();
}, 5000); // 5 seconds }, 5000); // 5 seconds