From 8e8bab03d5eb787b4efd564a5ebdbe1a7eeaec6d Mon Sep 17 00:00:00 2001 From: Sasha Hilton Date: Tue, 30 Jan 2018 21:38:54 +0100 Subject: [PATCH] Add zeroconf-port option --- src/discovery.rs | 5 +++-- src/main.rs | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/discovery.rs b/src/discovery.rs index fc168d5c..e39c1738 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -194,14 +194,15 @@ pub struct DiscoveryStream { _svc: mdns::Service, } -pub fn discovery(handle: &Handle, config: ConnectConfig, device_id: String) +pub fn discovery(handle: &Handle, config: ConnectConfig, device_id: String, port: u16) -> io::Result { let (discovery, creds_rx) = Discovery::new(config.clone(), device_id); let serve = { let http = Http::new(); - http.serve_addr_handle(&"0.0.0.0:0".parse().unwrap(), &handle, move || Ok(discovery.clone())).unwrap() + debug!("Zeroconf server listening on 0.0.0.0:{}", port); + http.serve_addr_handle(&format!("0.0.0.0:{}", port).parse().unwrap(), &handle, move || Ok(discovery.clone())).unwrap() }; let addr = serve.incoming_ref().local_addr(); let server_future = { diff --git a/src/main.rs b/src/main.rs index 85131ee9..fd3f1c2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,7 @@ struct Setup { connect_config: ConnectConfig, credentials: Option, enable_discovery: bool, + zeroconf_port: u16, } fn setup(args: &[String]) -> Setup { @@ -99,7 +100,8 @@ fn setup(args: &[String]) -> Setup { .optopt("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND") .optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE") .optopt("", "mixer", "Mixer to use", "MIXER") - .optopt("", "initial-volume", "Initial volume in %, once connected (must be from 0 to 100)", "VOLUME"); + .optopt("", "initial-volume", "Initial volume in %, once connected (must be from 0 to 100)", "VOLUME") + .optopt("z", "zeroconf-port", "The port the internal server advertised over zeroconf uses.", "ZEROCONF_PORT"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -160,6 +162,17 @@ fn setup(args: &[String]) -> Setup { } debug!("Volume \"{}\" !", initial_volume); + let zeroconf_port: u16; + if matches.opt_present("zeroconf-port") && matches.opt_str("zeroconf-port").unwrap().parse::().is_ok() { + let z = matches.opt_str("zeroconf-port").unwrap().parse::().unwrap(); + match z { + z if z >= 1024 => { zeroconf_port = z } + _ => { zeroconf_port = 0 } + } + } else { + zeroconf_port = 0 + } + let name = matches.opt_str("name").unwrap(); let use_audio_cache = !matches.opt_present("disable-audio-cache"); @@ -221,6 +234,7 @@ fn setup(args: &[String]) -> Setup { credentials: credentials, device: device, enable_discovery: enable_discovery, + zeroconf_port: zeroconf_port, mixer: mixer, } } @@ -269,7 +283,7 @@ impl Main { let config = task.connect_config.clone(); let device_id = task.session_config.device_id.clone(); - task.discovery = Some(discovery(&handle, config, device_id).unwrap()); + task.discovery = Some(discovery(&handle, config, device_id, setup.zeroconf_port).unwrap()); } if let Some(credentials) = setup.credentials {