From 2a16dcba5a31a45a12853a15254719c357baae6d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 31 May 2023 20:53:12 +0200 Subject: use an atomic pointer to track the current song Also fix showing finished songs as current playing on new clients. --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'main.go') 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 -- cgit v1.2.3