Skip to content

Commit 269eba8

Browse files
committed
Refresh state on each WebSocket connection
1 parent 2e62353 commit 269eba8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/hooks/useLibrespot.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const useLibrespot = (websocketUrl, apiBaseUrl) => {
6262
// (Re)load on initial render or whenever the API endpoint changes.
6363
useEffect(() => {
6464
const fetchStatus = async () => {
65+
console.log("Refreshing state");
6566
const data = await getStatus(apiBaseUrl);
6667
const isStopped = data.stopped || !data.play_origin.length || data.track == null;
6768
setStatus(data); //< TODO: remove long term.
@@ -73,8 +74,11 @@ const useLibrespot = (websocketUrl, apiBaseUrl) => {
7374
setShuffleContext(data.shuffle_context);
7475
setRemotePosition(data.track?.position || 0);
7576
};
76-
fetchStatus();
77-
}, [apiBaseUrl]);
77+
// Refresh state on each (re)connect
78+
if (isConnected){
79+
fetchStatus();
80+
}
81+
}, [apiBaseUrl, isConnected]);
7882

7983
// Call pause or resume depending on the current state of the player
8084
const handlePlayPause = () => {

0 commit comments

Comments
 (0)