diff --git a/contrib/spotifyd.conf b/contrib/spotifyd.conf index ac037e0e..205a0b93 100644 --- a/contrib/spotifyd.conf +++ b/contrib/spotifyd.conf @@ -56,6 +56,10 @@ # zeroconf port need to be allowed through any active firewall. #zeroconf_port = 1234 +# The ip addresses that `spotifyd` advertises via mDNS. By default, the addresses +# of all interfaces are advertised. +#zeroconf_ip = ["192.168.0.10"] + #-------# # AUDIO # #-------# diff --git a/docs/src/configuration/auth.md b/docs/src/configuration/auth.md index 97cb22d7..d4eff99b 100644 --- a/docs/src/configuration/auth.md +++ b/docs/src/configuration/auth.md @@ -11,6 +11,8 @@ For this to work, you need to make sure that your firewall isn't blocking the di - `5353 UDP`: MDNS service advertisement - A zeroconf port which uses TCP. By default, it is randomly chosen, but if you want to, you can configure it with the `--zeroconf-port` cli option / `zeroconf_port` config value. +By default, `spotifyd` advertises the addresses of all interfaces. On hosts with many of them, clients may pick one that they cannot reach, in which case you can limit the advertisement with the `--zeroconf-ip` cli option / `zeroconf_ip` config value. + If you don't want discovery, because you're using one of the methods below, you can disable it via the `--disable-discovery` cli option / `disable_discovery = true` config value. > __Note:__ By default, the last active session will be remembered and reconnected once the service is restarted. diff --git a/src/config.rs b/src/config.rs index 5ce23f30..b6ad9170 100644 --- a/src/config.rs +++ b/src/config.rs @@ -25,6 +25,7 @@ use std::{ borrow::Cow, convert::TryInto, fs, + net::IpAddr, path::{Path, PathBuf}, str::FromStr, }; @@ -339,6 +340,10 @@ pub struct SharedConfigValues { #[arg(long)] zeroconf_port: Option, + /// The ip addresses to advertise for the Spotify Connect discovery + #[arg(long, value_name = "IP", value_delimiter = ',')] + zeroconf_ip: Option>, + /// The proxy used to connect to spotify's servers #[arg(long, value_name = "URL")] proxy: Option, @@ -583,6 +588,7 @@ impl SharedConfigValues { on_song_change_hook, disable_discovery, zeroconf_port, + zeroconf_ip, proxy, device_type, max_cache_size, @@ -634,6 +640,7 @@ pub(crate) struct SpotifydConfig { pub(crate) shell: String, pub(crate) discovery: bool, pub(crate) zeroconf_port: Option, + pub(crate) zeroconf_ip: Option>, pub(crate) device_type: LSDeviceType, #[cfg(feature = "dbus_mpris")] pub(crate) mpris: MprisConfig, @@ -757,6 +764,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig { shell, discovery: !config.shared_config.disable_discovery.unwrap_or(false), zeroconf_port: config.shared_config.zeroconf_port, + zeroconf_ip: config.shared_config.zeroconf_ip, device_type, #[cfg(unix)] pid, diff --git a/src/setup.rs b/src/setup.rs index 52d5acff..9cc76de5 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -76,6 +76,7 @@ pub(crate) fn initial_state( let backend = config.backend.clone(); let zeroconf_port = config.zeroconf_port.unwrap_or(0); + let zeroconf_ip = config.zeroconf_ip.unwrap_or_default(); let creds = if let Some(creds) = config.oauth_cache.as_ref().and_then(|c| c.credentials()) { info!( @@ -105,6 +106,7 @@ pub(crate) fn initial_state( .name(config.device_name.clone()) .device_type(config.device_type) .port(zeroconf_port) + .zeroconf_ip(zeroconf_ip.clone()) .launch() { Ok(discovery_stream) => break Some(discovery_stream),