aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-05-31 20:53:12 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-05-31 20:54:08 +0200
commit2a16dcba5a31a45a12853a15254719c357baae6d (patch)
tree92271c8ce54846e684cd874c8c2008651c3a9778 /main.go
parentd8bdce51c336f3693121202402ee38ff3f12c0e2 (diff)
downloadWRMS-2a16dcba5a31a45a12853a15254719c357baae6d.tar.gz
WRMS-2a16dcba5a31a45a12853a15254719c357baae6d.zip
use an atomic pointer to track the current song
Also fix showing finished songs as current playing on new clients.
Diffstat (limited to 'main.go')
-rw-r--r--main.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/main.go b/main.go
index 0539e1a..53dc440 100644
--- a/main.go
+++ b/main.go
@@ -232,7 +232,11 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) {
initialCmds := [][]byte{}
if wrms.Playing {
- data, err := json.Marshal(newEvent("play", []Song{wrms.CurrentSong}))
+ var songs []Song
+ if currentSong := wrms.CurrentSong.Load(); currentSong != nil {
+ songs = []Song{*currentSong}
+ }
+ data, err := json.Marshal(newEvent("play", songs))
if err != nil {
llog.Error("Encoding the play event failed with %s", err)
return