Skip to content

Commit

Permalink
fix(websocket driver): fix track id passing in event receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasl-dev committed Aug 1, 2021
1 parent fd0f612 commit 1e14e5d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions driver/websocketdriver/event_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ func (e *eventReceiver) start() {
}

type genericEvent struct {
Op string `json:"op,omitempty"`
Type string `json:"type,omitempty"`
GuildID string `json:"guildId,omitempty"`
playerentity.TrackEnd
playerentity.TrackException
playerentity.TrackStart
playerentity.TrackStuck
playerentity.Update
server.WebsocketClosed
server.Stats

Op string `json:"op,omitempty"`
Type string `json:"type,omitempty"`
GuildID string `json:"guildId,omitempty"`
TrackID string `json:"track,omitempty"`
}

func (e *eventReceiver) unmarshal() (event.Event, error) {
Expand All @@ -88,17 +90,25 @@ func (e *eventReceiver) lookupEvent(evt genericEvent) (event.Event, error) {
if evt.Op == "stats" {
return evt.Stats, nil
}
return e.switchEvent(evt)
}

func (e *eventReceiver) switchEvent(evt genericEvent) (event.Event, error) {
switch evt.Type {
case "TrackEndEvent":
evt.TrackEnd.TrackID = evt.TrackID
evt.TrackEnd.GuildID = evt.GuildID
return evt.TrackEnd, nil
case "TrackExceptionEvent":
evt.TrackException.TrackID = evt.TrackID
evt.TrackException.GuildID = evt.GuildID
return evt.TrackException, nil
case "TrackStartEvent":
evt.TrackStart.TrackID = evt.TrackID
evt.TrackStart.GuildID = evt.GuildID
return evt.TrackStart, nil
case "TrackStuckEvent":
evt.TrackStuck.TrackID = evt.TrackID
evt.TrackStuck.GuildID = evt.GuildID
return evt.TrackStuck, nil
case "WebSocketClosedEvent":
Expand Down

0 comments on commit 1e14e5d

Please sign in to comment.