Merge pull request #109 from librespot-org/zeroconf_port

Add zeroconf-port option
This commit is contained in:
Sasha Hilton 2018-01-30 23:19:29 +01:00 committed by GitHub
commit 3efe499737
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -194,14 +194,15 @@ pub struct DiscoveryStream {
_svc: mdns::Service, _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<DiscoveryStream> -> io::Result<DiscoveryStream>
{ {
let (discovery, creds_rx) = Discovery::new(config.clone(), device_id); let (discovery, creds_rx) = Discovery::new(config.clone(), device_id);
let serve = { let serve = {
let http = Http::new(); 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 addr = serve.incoming_ref().local_addr();
let server_future = { let server_future = {

View file

@ -81,6 +81,7 @@ struct Setup {
connect_config: ConnectConfig, connect_config: ConnectConfig,
credentials: Option<Credentials>, credentials: Option<Credentials>,
enable_discovery: bool, enable_discovery: bool,
zeroconf_port: u16,
} }
fn setup(args: &[String]) -> Setup { 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("", "backend", "Audio backend to use. Use '?' to list options", "BACKEND")
.optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE") .optopt("", "device", "Audio device to use. Use '?' to list options", "DEVICE")
.optopt("", "mixer", "Mixer to use", "MIXER") .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..]) { let matches = match opts.parse(&args[1..]) {
Ok(m) => m, Ok(m) => m,
@ -160,6 +162,17 @@ fn setup(args: &[String]) -> Setup {
} }
debug!("Volume \"{}\" !", initial_volume); debug!("Volume \"{}\" !", initial_volume);
let zeroconf_port: u16;
if matches.opt_present("zeroconf-port") && matches.opt_str("zeroconf-port").unwrap().parse::<u16>().is_ok() {
let z = matches.opt_str("zeroconf-port").unwrap().parse::<u16>().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 name = matches.opt_str("name").unwrap();
let use_audio_cache = !matches.opt_present("disable-audio-cache"); let use_audio_cache = !matches.opt_present("disable-audio-cache");
@ -221,6 +234,7 @@ fn setup(args: &[String]) -> Setup {
credentials: credentials, credentials: credentials,
device: device, device: device,
enable_discovery: enable_discovery, enable_discovery: enable_discovery,
zeroconf_port: zeroconf_port,
mixer: mixer, mixer: mixer,
} }
} }
@ -269,7 +283,7 @@ impl Main {
let config = task.connect_config.clone(); let config = task.connect_config.clone();
let device_id = task.session_config.device_id.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 { if let Some(credentials) = setup.credentials {