Skip to content

Commit 4a1e5dc

Browse files
committed
feat: add context_uri to WebSocket events
See #199
1 parent 9b19c32 commit 4a1e5dc

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

API.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The websocket endpoint is available at `/events`. The following events are emitt
1313
- `active`: The device has become active
1414
- `inactive`: The device has become inactive
1515
- `metadata`: A new track was loaded, the following metadata is available:
16+
- `context_uri`: The context URI
1617
- `uri`: Track URI
1718
- `name`: Track name
1819
- `artist_names`: List of track artist names
@@ -21,21 +22,26 @@ The websocket endpoint is available at `/events`. The following events are emitt
2122
- `position`: Track position in milliseconds
2223
- `duration`: Track duration in milliseconds
2324
- `will_play`: The player is about to play the specified track
25+
- `context_uri`: The context URI
2426
- `uri`: The track URI
2527
- `play_origin`: Who started the playback
2628
- `playing`: The current track is playing
29+
- `context_uri`: The context URI
2730
- `uri`: The track URI
2831
- `resume`: Was this resumed from paused playback?
2932
- `play_origin`: Who started the playback
3033
- `not_playing`: The current track has finished playing
34+
- `context_uri`: The context URI
3135
- `uri`: The track URI
3236
- `play_origin`: Who started the playback
3337
- `paused`: The current track is paused
38+
- `context_uri`: The context URI
3439
- `uri`: The track URI
3540
- `play_origin`: Who started the playback
3641
- `stopped`: The current context is empty, nothing more to play
3742
- `play_origin`: Who started the playback
3843
- `seek`: The current track was seeked, the following data is provided:
44+
- `context_uri`: The context URI
3945
- `uri`: The track URI
4046
- `position`: Track position in milliseconds
4147
- `duration`: Track duration in milliseconds

cmd/daemon/api_server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,26 @@ type ApiEventDataMetadata ApiResponseStatusTrack
234234
type ApiEventDataVolume ApiResponseVolume
235235

236236
type ApiEventDataPlaying struct {
237+
ContextUri string `json:"context_uri"`
237238
Uri string `json:"uri"`
238239
Resume bool `json:"resume"`
239240
PlayOrigin string `json:"play_origin"`
240241
}
241242

242243
type ApiEventDataWillPlay struct {
244+
ContextUri string `json:"context_uri"`
243245
Uri string `json:"uri"`
244246
PlayOrigin string `json:"play_origin"`
245247
}
246248

247249
type ApiEventDataNotPlaying struct {
250+
ContextUri string `json:"context_uri"`
248251
Uri string `json:"uri"`
249252
PlayOrigin string `json:"play_origin"`
250253
}
251254

252255
type ApiEventDataPaused struct {
256+
ContextUri string `json:"context_uri"`
253257
Uri string `json:"uri"`
254258
PlayOrigin string `json:"play_origin"`
255259
}
@@ -259,6 +263,7 @@ type ApiEventDataStopped struct {
259263
}
260264

261265
type ApiEventDataSeek struct {
266+
ContextUri string `json:"context_uri"`
262267
Uri string `json:"uri"`
263268
Position int `json:"position"`
264269
Duration int `json:"duration"`

cmd/daemon/controls.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (p *AppPlayer) handlePlayerEvent(ctx context.Context, ev *player.Event) {
9696
p.app.server.Emit(&ApiEvent{
9797
Type: ApiEventTypePlaying,
9898
Data: ApiEventDataPlaying{
99+
ContextUri: p.state.player.ContextUri,
99100
Uri: p.state.player.Track.Uri,
100101
Resume: false,
101102
PlayOrigin: p.state.playOrigin(),
@@ -112,6 +113,7 @@ func (p *AppPlayer) handlePlayerEvent(ctx context.Context, ev *player.Event) {
112113
p.app.server.Emit(&ApiEvent{
113114
Type: ApiEventTypePlaying,
114115
Data: ApiEventDataPlaying{
116+
ContextUri: p.state.player.ContextUri,
115117
Uri: p.state.player.Track.Uri,
116118
Resume: true,
117119
PlayOrigin: p.state.playOrigin(),
@@ -135,6 +137,7 @@ func (p *AppPlayer) handlePlayerEvent(ctx context.Context, ev *player.Event) {
135137
p.app.server.Emit(&ApiEvent{
136138
Type: ApiEventTypePaused,
137139
Data: ApiEventDataPaused{
140+
ContextUri: p.state.player.ContextUri,
138141
Uri: p.state.player.Track.Uri,
139142
PlayOrigin: p.state.playOrigin(),
140143
},
@@ -145,6 +148,7 @@ func (p *AppPlayer) handlePlayerEvent(ctx context.Context, ev *player.Event) {
145148
p.app.server.Emit(&ApiEvent{
146149
Type: ApiEventTypeNotPlaying,
147150
Data: ApiEventDataNotPlaying{
151+
ContextUri: p.state.player.ContextUri,
148152
Uri: p.state.player.Track.Uri,
149153
PlayOrigin: p.state.playOrigin(),
150154
},
@@ -269,6 +273,7 @@ func (p *AppPlayer) loadCurrentTrack(ctx context.Context, paused, drop bool) err
269273
p.app.server.Emit(&ApiEvent{
270274
Type: ApiEventTypeWillPlay,
271275
Data: ApiEventDataWillPlay{
276+
ContextUri: p.state.player.ContextUri,
272277
Uri: spotId.Uri(),
273278
PlayOrigin: p.state.playOrigin(),
274279
},
@@ -476,6 +481,7 @@ func (p *AppPlayer) seek(ctx context.Context, position int64) error {
476481
p.app.server.Emit(&ApiEvent{
477482
Type: ApiEventTypeSeek,
478483
Data: ApiEventDataSeek{
484+
ContextUri: p.state.player.ContextUri,
479485
Uri: p.state.player.Track.Uri,
480486
Position: int(position),
481487
Duration: int(p.primaryStream.Media.Duration()),

0 commit comments

Comments
 (0)