Skip to content

Commit

Permalink
feat: support specifying Zeroconf port
Browse files Browse the repository at this point in the history
Closes #154
  • Loading branch information
devgianlu committed Dec 20, 2024
1 parent 952606d commit 8b1458d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ An example configuration (not required) looks like this:

```yaml
zeroconf_enabled: false # Whether to keep the device discoverable at all times, even if authenticated via other means
zeroconf_port: 0 # The port to use for Zeroconf, 0 for random
credentials:
type: zeroconf
zeroconf:
Expand Down
3 changes: 2 additions & 1 deletion cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (app *App) withAppPlayer(ctx context.Context, appPlayerFunc func(context.Co
}

// start zeroconf server and dispatch
z, err := zeroconf.NewZeroconf(app.cfg.DeviceName, app.deviceId, app.deviceType)
z, err := zeroconf.NewZeroconf(app.cfg.ZeroconfPort, app.cfg.DeviceName, app.deviceId, app.deviceType)
if err != nil {
return fmt.Errorf("failed initializing zeroconf: %w", err)
}
Expand Down Expand Up @@ -359,6 +359,7 @@ type Config struct {
NormalisationPregain float32 `koanf:"normalisation_pregain"`
ExternalVolume bool `koanf:"external_volume"`
ZeroconfEnabled bool `koanf:"zeroconf_enabled"`
ZeroconfPort int `koanf:"zeroconf_port"`
DisableAutoplay bool `koanf:"disable_autoplay"`
Server struct {
Enabled bool `koanf:"enabled"`
Expand Down
5 changes: 5 additions & 0 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
"description": "Whether Zeroconf discovery should always be enabled (even when logging in with credentials)",
"default": false
},
"zeroconf_port": {
"type": "integer",
"description": "The port to use for the Zeroconf service (empty for random)",
"default": 0
},
"credentials": {
"type": "object",
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions zeroconf/zeroconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type NewUserRequest struct {
result chan bool
}

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

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

z.listener, err = net.Listen("tcp", "0.0.0.0:0")
z.listener, err = net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
if err != nil {
return nil, fmt.Errorf("failed starting zeroconf listener: %w", err)
}
Expand Down

0 comments on commit 8b1458d

Please sign in to comment.