order things
This commit is contained in:
parent
53e288a6f7
commit
bb6e4c6acf
2 changed files with 19 additions and 19 deletions
20
src/api.rs
20
src/api.rs
|
@ -20,16 +20,6 @@ fn greeting(state: &Arc<AppState>) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn websocket_handler(
|
||||
ws: WebSocketUpgrade,
|
||||
// user_agent: Option<TypedHeader<headers::UserAgent>>,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> impl IntoResponse {
|
||||
tracing::debug!("New connection from {addr}");
|
||||
ws.on_upgrade(move |socket| websocket(socket, state, addr))
|
||||
}
|
||||
|
||||
pub async fn websocket(stream: WebSocket, state: Arc<AppState>, who: SocketAddr) {
|
||||
// By splitting, we can send and receive at the same time.
|
||||
let (mut sender, mut receiver) = stream.split();
|
||||
|
@ -66,3 +56,13 @@ pub async fn websocket(stream: WebSocket, state: Arc<AppState>, who: SocketAddr)
|
|||
_ = (&mut recv_task) => send_task.abort(),
|
||||
};
|
||||
}
|
||||
|
||||
pub async fn websocket_handler(
|
||||
ws: WebSocketUpgrade,
|
||||
// user_agent: Option<TypedHeader<headers::UserAgent>>,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> impl IntoResponse {
|
||||
tracing::debug!("New connection from {addr}");
|
||||
ws.on_upgrade(move |socket| websocket(socket, state, addr))
|
||||
}
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -86,6 +86,15 @@ pub struct AppState {
|
|||
games: Mutex<Vec<CAHGame>>,
|
||||
}
|
||||
|
||||
// Include utf-8 file at **compile** time.
|
||||
async fn index() -> Html<&'static str> {
|
||||
Html(std::include_str!("../test_client.html"))
|
||||
}
|
||||
|
||||
async fn spawnclients() -> Html<&'static str> {
|
||||
Html(std::include_str!("../spawnclients.html"))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
tracing_subscriber::registry()
|
||||
|
@ -125,12 +134,3 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Include utf-8 file at **compile** time.
|
||||
async fn index() -> Html<&'static str> {
|
||||
Html(std::include_str!("../test_client.html"))
|
||||
}
|
||||
|
||||
async fn spawnclients() -> Html<&'static str> {
|
||||
Html(std::include_str!("../spawnclients.html"))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue