mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #109 from librespot-org/zeroconf_port
Add zeroconf-port option
This commit is contained in:
commit
3efe499737
2 changed files with 19 additions and 4 deletions
|
@ -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<DiscoveryStream>
|
||||
{
|
||||
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 = {
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -81,6 +81,7 @@ struct Setup {
|
|||
connect_config: ConnectConfig,
|
||||
credentials: Option<Credentials>,
|
||||
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::<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 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 {
|
||||
|
|
Loading…
Reference in a new issue