Move relay_server into a subcommand
This commit is contained in:
parent
f3aa76243f
commit
98f7f446f9
3 changed files with 24 additions and 9 deletions
1
src/commands/mod.rs
Normal file
1
src/commands/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod relay;
|
|
@ -1,8 +1,3 @@
|
||||||
extern crate futures;
|
|
||||||
extern crate hyper;
|
|
||||||
extern crate webmetro;
|
|
||||||
|
|
||||||
use std::env::args;
|
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
|
@ -10,6 +5,7 @@ use std::sync::{
|
||||||
Mutex
|
Mutex
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use futures::{
|
use futures::{
|
||||||
Future,
|
Future,
|
||||||
Stream,
|
Stream,
|
||||||
|
@ -112,8 +108,19 @@ impl Service for RelayServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn args() -> App<'static, 'static> {
|
||||||
|
SubCommand::with_name("relay")
|
||||||
|
.about("Hosts an HTTP-based relay server")
|
||||||
|
.arg(Arg::with_name("listen")
|
||||||
|
.help("The address:port to listen to")
|
||||||
|
.required(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(args: &ArgMatches) {
|
||||||
let single_channel = Channel::new();
|
let single_channel = Channel::new();
|
||||||
let addr = args().nth(1).expect("Need binding address+port").to_socket_addrs().unwrap().next().unwrap();
|
|
||||||
|
let addr_str = args.value_of("listen").unwrap();
|
||||||
|
let addr = addr_str.to_socket_addrs().expect("parsing bind address").next().expect("resolving bind address");
|
||||||
|
|
||||||
Http::new().bind(&addr, move || Ok(RelayServer(single_channel.clone()))).unwrap().run().unwrap();
|
Http::new().bind(&addr, move || Ok(RelayServer(single_channel.clone()))).unwrap().run().unwrap();
|
||||||
}
|
}
|
11
src/main.rs
11
src/main.rs
|
@ -1,7 +1,12 @@
|
||||||
#[macro_use]
|
#[macro_use] extern crate clap;
|
||||||
extern crate clap;
|
extern crate futures;
|
||||||
|
extern crate hyper;
|
||||||
|
extern crate webmetro;
|
||||||
|
|
||||||
|
mod commands;
|
||||||
|
|
||||||
use clap::{App, AppSettings};
|
use clap::{App, AppSettings};
|
||||||
|
use commands::{relay};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = App::new("webmetro")
|
let args = App::new("webmetro")
|
||||||
|
@ -9,9 +14,11 @@ fn main() {
|
||||||
.about("Utilities for broadcasting & relaying live WebM video/audio streams")
|
.about("Utilities for broadcasting & relaying live WebM video/audio streams")
|
||||||
.setting(AppSettings::SubcommandRequired)
|
.setting(AppSettings::SubcommandRequired)
|
||||||
.setting(AppSettings::VersionlessSubcommands)
|
.setting(AppSettings::VersionlessSubcommands)
|
||||||
|
.subcommand(relay::args())
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match args.subcommand() {
|
match args.subcommand() {
|
||||||
|
("relay", Some(sub_args)) => relay::run(sub_args),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue