@@ -16,7 +16,7 @@ import (
1616 librespot "github.com/devgianlu/go-librespot"
1717 "github.com/devgianlu/go-librespot/dh"
1818 devicespb "github.com/devgianlu/go-librespot/proto/spotify/connectstate/devices"
19- "github.com/grandcat/ zeroconf"
19+ "github.com/devgianlu/go-librespot/ zeroconf/discovery "
2020 log "github.com/sirupsen/logrus"
2121)
2222
@@ -27,8 +27,8 @@ type Zeroconf struct {
2727 deviceId string
2828 deviceType devicespb.DeviceType
2929
30- listener net.Listener
31- server * zeroconf. Server
30+ listener net.Listener
31+ discovery discovery. Service
3232
3333 dh * dh.DiffieHellman
3434
@@ -88,9 +88,18 @@ func NewZeroconf(opts Options) (_ *Zeroconf, err error) {
8888 log .Info (fmt .Sprintf ("advertising on network interface %s" , ifaceName ))
8989 }
9090
91- z .server , err = zeroconf .Register (z .deviceName , "_spotify-connect._tcp" , "local." , listenPort , []string {"CPath=/" , "VERSION=1.0" , "Stack=SP" }, ifaces )
92- if err != nil {
93- return nil , fmt .Errorf ("failed registering zeroconf server: %w" , err )
91+ discoveryImpl := opts .DiscoveryImplementation
92+ if discoveryImpl == "" {
93+ discoveryImpl = "builtin"
94+ }
95+
96+ z .discovery = discovery .GetService (discoveryImpl )
97+ if z .discovery == nil {
98+ return nil , fmt .Errorf ("unknown discovery implementation: %s" , discoveryImpl )
99+ }
100+
101+ if err := z .discovery .Register (z .deviceName , "_spotify-connect._tcp" , "local." , listenPort , []string {"CPath=/" , "VERSION=1.0" , "Stack=SP" }, ifaces ); err != nil {
102+ return nil , fmt .Errorf ("failed registering zeroconf service: %w" , err )
94103 }
95104
96105 return z , nil
@@ -105,7 +114,7 @@ func (z *Zeroconf) SetCurrentUser(username string) {
105114// Close stops the zeroconf responder and HTTP listener,
106115// but does not close the last opened session.
107116func (z * Zeroconf ) Close () {
108- z .server .Shutdown ()
117+ z .discovery .Shutdown ()
109118 _ = z .listener .Close ()
110119}
111120
@@ -260,7 +269,7 @@ func (z *Zeroconf) handleAddUser(writer http.ResponseWriter, request *http.Reque
260269type HandleNewRequestFunc func (req NewUserRequest ) bool
261270
262271func (z * Zeroconf ) Serve (handler HandleNewRequestFunc ) error {
263- defer z .server .Shutdown ()
272+ defer z .discovery .Shutdown ()
264273
265274 mux := http .NewServeMux ()
266275 mux .HandleFunc ("/" , func (writer http.ResponseWriter , request * http.Request ) {
0 commit comments