@@ -17,6 +17,7 @@ import (
1717 "github.com/devgianlu/go-librespot/dh"
1818 devicespb "github.com/devgianlu/go-librespot/proto/spotify/connectstate/devices"
1919 "github.com/grandcat/zeroconf"
20+ log "github.com/sirupsen/logrus"
2021)
2122
2223type Zeroconf struct {
@@ -46,16 +47,29 @@ type NewUserRequest struct {
4647 result chan bool
4748}
4849
49- func NewZeroconf (log librespot.Logger , port int , deviceName , deviceId string , deviceType devicespb.DeviceType , interfacesToAdvertise []string ) (_ * Zeroconf , err error ) {
50- z := & Zeroconf {log : log , deviceId : deviceId , deviceName : deviceName , deviceType : deviceType }
50+ type Options struct {
51+ Log librespot.Logger
52+
53+ Port int
54+
55+ DeviceName string
56+ DeviceId string
57+ DeviceType devicespb.DeviceType
58+
59+ DiscoveryImplementation string
60+ InterfacesToAdvertise []string
61+ }
62+
63+ func NewZeroconf (opts Options ) (_ * Zeroconf , err error ) {
64+ z := & Zeroconf {log : opts .Log , deviceId : opts .DeviceId , deviceName : opts .DeviceName , deviceType : opts .DeviceType }
5165 z .reqsChan = make (chan NewUserRequest )
5266
5367 z .dh , err = dh .NewDiffieHellman ()
5468 if err != nil {
5569 return nil , fmt .Errorf ("failed initializing diffiehellman: %w" , err )
5670 }
5771
58- z .listener , err = net .Listen ("tcp" , fmt .Sprintf ("0.0.0.0:%d" , port ))
72+ z .listener , err = net .Listen ("tcp" , fmt .Sprintf ("0.0.0.0:%d" , opts . Port ))
5973 if err != nil {
6074 return nil , fmt .Errorf ("failed starting zeroconf listener: %w" , err )
6175 }
@@ -64,7 +78,7 @@ func NewZeroconf(log librespot.Logger, port int, deviceName, deviceId string, de
6478 log .Infof ("zeroconf server listening on port %d" , listenPort )
6579
6680 var ifaces []net.Interface
67- for _ , ifaceName := range interfacesToAdvertise {
81+ for _ , ifaceName := range opts . InterfacesToAdvertise {
6882 liface , err := net .InterfaceByName (ifaceName )
6983 if err != nil {
7084 return nil , fmt .Errorf ("failed to get info for network interface %s: %w" , ifaceName , err )
@@ -74,7 +88,7 @@ func NewZeroconf(log librespot.Logger, port int, deviceName, deviceId string, de
7488 log .Info (fmt .Sprintf ("advertising on network interface %s" , ifaceName ))
7589 }
7690
77- z .server , err = zeroconf .Register (deviceName , "_spotify-connect._tcp" , "local." , listenPort , []string {"CPath=/" , "VERSION=1.0" , "Stack=SP" }, ifaces )
91+ z .server , err = zeroconf .Register (z . deviceName , "_spotify-connect._tcp" , "local." , listenPort , []string {"CPath=/" , "VERSION=1.0" , "Stack=SP" }, ifaces )
7892 if err != nil {
7993 return nil , fmt .Errorf ("failed registering zeroconf server: %w" , err )
8094 }
0 commit comments