fix(server): remove misleading "Agent not available" warning.

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2025-03-05 14:11:44 -08:00
parent dc4e091622
commit a04167672c
8 changed files with 97 additions and 35 deletions

View file

@ -53,13 +53,20 @@ func newPlayTracker(ds model.DataStore, broker events.Broker) *playTracker {
m := cache.NewSimpleCache[string, NowPlayingInfo]()
p := &playTracker{ds: ds, playMap: m, broker: broker}
p.scrobblers = make(map[string]Scrobbler)
var enabled []string
for name, constructor := range constructors {
s := constructor(ds)
if s == nil {
log.Debug("Scrobbler not available. Missing configuration?", "name", name)
continue
}
enabled = append(enabled, name)
if conf.Server.DevEnableBufferedScrobble {
s = newBufferedScrobbler(ds, s, name)
}
p.scrobblers[name] = s
}
log.Debug("List of scrobblers enabled", "names", enabled)
return p
}

View file

@ -35,9 +35,12 @@ var _ = Describe("PlayTracker", func() {
ctx = request.WithPlayer(ctx, model.Player{ScrobbleEnabled: true})
ds = &tests.MockDataStore{}
fake = fakeScrobbler{Authorized: true}
Register("fake", func(ds model.DataStore) Scrobbler {
Register("fake", func(model.DataStore) Scrobbler {
return &fake
})
Register("disabled", func(model.DataStore) Scrobbler {
return nil
})
tracker = newPlayTracker(ds, events.GetBroker())
track = model.MediaFile{
@ -61,6 +64,11 @@ var _ = Describe("PlayTracker", func() {
_ = ds.Album(ctx).(*tests.MockAlbumRepo).Put(&album)
})
It("does not register disabled scrobblers", func() {
Expect(tracker.(*playTracker).scrobblers).To(HaveKey("fake"))
Expect(tracker.(*playTracker).scrobblers).ToNot(HaveKey("disabled"))
})
Describe("NowPlaying", func() {
It("sends track to agent", func() {
err := tracker.NowPlaying(ctx, "player-1", "player-one", "123")