diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-05-30 11:29:39 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-05-30 11:29:39 +0200 |
| commit | cc922fb33b3e6dac22da4812572eebfcc709af3c (patch) | |
| tree | d1260e8e9c0ef0beda08c7e959ecf77a26c45f63 /wrms.go | |
| parent | 3b1012ed66c8bbc6c550833148cd2fc25aed125b (diff) | |
| download | WRMS-cc922fb33b3e6dac22da4812572eebfcc709af3c.tar.gz WRMS-cc922fb33b3e6dac22da4812572eebfcc709af3c.zip | |
distinguish between search queries
Introduce a new Id field for events to distinguish between
different searches.
Since search result reporting is split up a old search could introduce
results or terminate the current search.
Keep track of a search counter to distinguish between result from the
active search and stale ones.
Allow to add multiple songs from the current search.
Diffstat (limited to 'wrms.go')
| -rw-r--r-- | wrms.go | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -40,11 +40,20 @@ func NewSongFromJson(data []byte) (Song, error) { type Event struct { Event string `json:"cmd"` + Id int `json:"id"` Songs []Song `json:"songs"` } +func newEvent(event string, songs []Song) Event { + return Event{Event: event, Songs: songs} +} + func newNotification(notification string) Event { - return Event{notification, nil} + return Event{Event: notification} +} + +func newSearchResultEvent(id int, songs []Song) Event { + return Event{Event: "search", Id: id, Songs: songs} } type Connection struct { @@ -100,7 +109,7 @@ func (wrms *Wrms) Broadcast(ev Event) { } func (wrms *Wrms) startPlaying() { - wrms.Broadcast(Event{"play", []Song{wrms.CurrentSong}}) + wrms.Broadcast(newEvent("play", []Song{wrms.CurrentSong})) wrms.Player.Play(&wrms.CurrentSong) } @@ -110,7 +119,7 @@ func (wrms *Wrms) AddSong(song Song) { s := &wrms.Songs[len(wrms.Songs)-1] wrms.queue.Add(s) llog.Info("Added song %s (ptr=%p) to Songs", s.Uri, s) - wrms.Broadcast(Event{"add", []Song{song}}) + wrms.Broadcast(newEvent("add", []Song{song})) if startPlayingAgain { wrms.Next() @@ -218,7 +227,7 @@ func (wrms *Wrms) AdjustSongWeight(connId uuid.UUID, songUri string, vote string } wrms.queue.Adjust(s) - wrms.Broadcast(Event{"update", []Song{*s}}) + wrms.Broadcast(newEvent("update", []Song{*s})) break } } |
