From 1f8be2478f97feab79d55cbd4b3d73624733d49a Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 22 Jul 2023 14:47:03 +0200 Subject: propagate the time bonus to the client and apply it when adding new songs --- web/client.html | 9 +++++++++ wrms.go | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/web/client.html b/web/client.html index 15f3a33..51ddf3b 100644 --- a/web/client.html +++ b/web/client.html @@ -92,6 +92,7 @@ } } + let timeBonus = 0.0; let isAdmin = false; let searchId = 0; let songs = []; @@ -213,6 +214,11 @@ } function handleAdd(added) { + if (timeBonus != 0) { + for (song of songs) { + song.weight += timeBonus + } + } songs = songs.concat(added); renderPlaylist(); } @@ -279,6 +285,9 @@ console.log("Received Event: ", message); const cmd = JSON.parse(message.data); switch (cmd.cmd) { + case "timeBonus": + timeBonus = cmd.timeBonus; + break; case "add": handleAdd(cmd.songs) break; diff --git a/wrms.go b/wrms.go index f6784c8..02b0860 100644 --- a/wrms.go +++ b/wrms.go @@ -226,7 +226,13 @@ func (wrms *Wrms) initConn(conn *Connection) error { curEventId := wrms.eventId.Load() conn.nextEvent = curEventId + 1 - initialCmds := []Event{} + initialCmds := []interface{}{} + + if wrms.Config.timeBonus != 0 { + ev := map[string]any{"cmd": "timeBonus", "timeBonus": wrms.Config.timeBonus} + initialCmds = append(initialCmds, ev) + } + if wrms.playing { var songs []Song if currentSong := wrms.CurrentSong.Load(); currentSong != nil { -- cgit v1.2.3