Skip to content

Commit 8b1458d

Browse files
committed
feat: support specifying Zeroconf port
Closes #154
1 parent 952606d commit 8b1458d

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ An example configuration (not required) looks like this:
6262

6363
```yaml
6464
zeroconf_enabled: false # Whether to keep the device discoverable at all times, even if authenticated via other means
65+
zeroconf_port: 0 # The port to use for Zeroconf, 0 for random
6566
credentials:
6667
type: zeroconf
6768
zeroconf:

cmd/daemon/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (app *App) withAppPlayer(ctx context.Context, appPlayerFunc func(context.Co
214214
}
215215

216216
// start zeroconf server and dispatch
217-
z, err := zeroconf.NewZeroconf(app.cfg.DeviceName, app.deviceId, app.deviceType)
217+
z, err := zeroconf.NewZeroconf(app.cfg.ZeroconfPort, app.cfg.DeviceName, app.deviceId, app.deviceType)
218218
if err != nil {
219219
return fmt.Errorf("failed initializing zeroconf: %w", err)
220220
}
@@ -359,6 +359,7 @@ type Config struct {
359359
NormalisationPregain float32 `koanf:"normalisation_pregain"`
360360
ExternalVolume bool `koanf:"external_volume"`
361361
ZeroconfEnabled bool `koanf:"zeroconf_enabled"`
362+
ZeroconfPort int `koanf:"zeroconf_port"`
362363
DisableAutoplay bool `koanf:"disable_autoplay"`
363364
Server struct {
364365
Enabled bool `koanf:"enabled"`

config_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@
134134
"description": "Whether Zeroconf discovery should always be enabled (even when logging in with credentials)",
135135
"default": false
136136
},
137+
"zeroconf_port": {
138+
"type": "integer",
139+
"description": "The port to use for the Zeroconf service (empty for random)",
140+
"default": 0
141+
},
137142
"credentials": {
138143
"type": "object",
139144
"properties": {

zeroconf/zeroconf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type NewUserRequest struct {
4545
result chan bool
4646
}
4747

48-
func NewZeroconf(deviceName, deviceId string, deviceType devicespb.DeviceType) (_ *Zeroconf, err error) {
48+
func NewZeroconf(port int, deviceName, deviceId string, deviceType devicespb.DeviceType) (_ *Zeroconf, err error) {
4949
z := &Zeroconf{deviceId: deviceId, deviceName: deviceName, deviceType: deviceType}
5050
z.reqsChan = make(chan NewUserRequest)
5151

@@ -54,7 +54,7 @@ func NewZeroconf(deviceName, deviceId string, deviceType devicespb.DeviceType) (
5454
return nil, fmt.Errorf("failed initializing diffiehellman: %w", err)
5555
}
5656

57-
z.listener, err = net.Listen("tcp", "0.0.0.0:0")
57+
z.listener, err = net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
5858
if err != nil {
5959
return nil, fmt.Errorf("failed starting zeroconf listener: %w", err)
6060
}

0 commit comments

Comments
 (0)