Create space for multiple routes

This commit is contained in:
Tangent Wantwight 2020-06-09 23:48:53 -04:00
parent ea2770105a
commit 4391ad521d
2 changed files with 18 additions and 16 deletions

View file

@ -18,8 +18,9 @@ import {} from "./net/LoopbackServer";
*/
Select(".GameCanvas").forEachCanvas((c, cx, keys) => {
const connection = new Connection<KeyName[], Data>("ws://localhost:9090/");
const connection = new Connection<KeyName[], Data>("ws://localhost:9090/base2020.ws");
new Main(c, cx, keys, connection.socket);
c.focus();
});
BindTests();

View file

@ -12,7 +12,7 @@ use serde_json::{from_str, to_string};
use std::net::ToSocketAddrs;
use stream::FuturesUnordered;
use structopt::StructOpt;
use warp::{serve, ws, ws::Ws, Filter};
use warp::{path, serve, ws, ws::Ws, Filter};
use ws::{Message, WebSocket};
pub mod net;
@ -46,13 +46,16 @@ async fn main() -> Result<()> {
})
});
// assemble routes
let routes = path!("base2020.ws").and(socket_handler);
let addrs = args
.listen
.to_socket_addrs()
.context("Couldn't parse the listen address")?;
let servers = FuturesUnordered::new();
for addr in addrs {
let (_, server) = serve(socket_handler.clone()).try_bind_ephemeral(addr)?;
let (_, server) = serve(routes.clone()).try_bind_ephemeral(addr)?;
servers.push(server);
}
@ -72,19 +75,17 @@ async fn handle_socket(game_server: Handle, websocket: WebSocket) -> Result<()>
)
});
let mut source = source
.map_err(Into::into)
.try_filter_map(|msg| {
ready(match msg.to_str() {
Ok(json) => from_str::<ClientMessage>(json)
.context("Parsing JSON")
.map(Some),
Err(()) => {
debug!("Non-text message {:?}", &msg);
Ok(None)
}
})
});
let mut source = source.map_err(Into::into).try_filter_map(|msg| {
ready(match msg.to_str() {
Ok(json) => from_str::<ClientMessage>(json)
.context("Parsing JSON")
.map(Some),
Err(()) => {
debug!("Non-text message {:?}", &msg);
Ok(None)
}
})
});
run_client(game_server, &mut source, &mut sink).await
}