mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Adding a communication channel between server and clients using SSE
This commit is contained in:
parent
3fc81638c7
commit
2b1a5f579a
15 changed files with 395 additions and 25 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/deluan/navidrome/scanner"
|
||||
"github.com/deluan/navidrome/server"
|
||||
"github.com/deluan/navidrome/server/app"
|
||||
"github.com/deluan/navidrome/server/events"
|
||||
"github.com/deluan/navidrome/server/subsonic"
|
||||
"github.com/google/wire"
|
||||
"sync"
|
||||
|
@ -27,7 +28,8 @@ func CreateServer(musicFolder string) *server.Server {
|
|||
|
||||
func CreateAppRouter() *app.Router {
|
||||
dataStore := persistence.New()
|
||||
router := app.New(dataStore)
|
||||
broker := GetBroker()
|
||||
router := app.New(dataStore, broker)
|
||||
return router
|
||||
}
|
||||
|
||||
|
@ -53,10 +55,16 @@ func createScanner() scanner.Scanner {
|
|||
artworkCache := core.GetImageCache()
|
||||
artwork := core.NewArtwork(dataStore, artworkCache)
|
||||
cacheWarmer := core.NewCacheWarmer(artwork, artworkCache)
|
||||
scannerScanner := scanner.New(dataStore, cacheWarmer)
|
||||
broker := GetBroker()
|
||||
scannerScanner := scanner.New(dataStore, cacheWarmer, broker)
|
||||
return scannerScanner
|
||||
}
|
||||
|
||||
func createBroker() events.Broker {
|
||||
broker := events.NewBroker()
|
||||
return broker
|
||||
}
|
||||
|
||||
// wire_injectors.go:
|
||||
|
||||
var allProviders = wire.NewSet(core.Set, subsonic.New, app.New, persistence.New)
|
||||
|
@ -73,3 +81,16 @@ func GetScanner() scanner.Scanner {
|
|||
})
|
||||
return scannerInstance
|
||||
}
|
||||
|
||||
// Broker must be a Singleton
|
||||
var (
|
||||
onceBroker sync.Once
|
||||
brokerInstance events.Broker
|
||||
)
|
||||
|
||||
func GetBroker() events.Broker {
|
||||
onceBroker.Do(func() {
|
||||
brokerInstance = createBroker()
|
||||
})
|
||||
return brokerInstance
|
||||
}
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/deluan/navidrome/core"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/scanner"
|
||||
"github.com/deluan/navidrome/server"
|
||||
"github.com/deluan/navidrome/server/app"
|
||||
"github.com/deluan/navidrome/server/events"
|
||||
"github.com/deluan/navidrome/server/subsonic"
|
||||
"github.com/google/wire"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var allProviders = wire.NewSet(
|
||||
|
@ -28,7 +30,10 @@ func CreateServer(musicFolder string) *server.Server {
|
|||
}
|
||||
|
||||
func CreateAppRouter() *app.Router {
|
||||
panic(wire.Build(allProviders))
|
||||
panic(wire.Build(
|
||||
allProviders,
|
||||
GetBroker,
|
||||
))
|
||||
}
|
||||
|
||||
func CreateSubsonicAPIRouter() *subsonic.Router {
|
||||
|
@ -54,6 +59,26 @@ func GetScanner() scanner.Scanner {
|
|||
func createScanner() scanner.Scanner {
|
||||
panic(wire.Build(
|
||||
allProviders,
|
||||
GetBroker,
|
||||
scanner.New,
|
||||
))
|
||||
}
|
||||
|
||||
// Broker must be a Singleton
|
||||
var (
|
||||
onceBroker sync.Once
|
||||
brokerInstance events.Broker
|
||||
)
|
||||
|
||||
func GetBroker() events.Broker {
|
||||
onceBroker.Do(func() {
|
||||
brokerInstance = createBroker()
|
||||
})
|
||||
return brokerInstance
|
||||
}
|
||||
|
||||
func createBroker() events.Broker {
|
||||
panic(wire.Build(
|
||||
events.NewBroker,
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue