order things

This commit is contained in:
Adam 2024-05-04 02:49:17 -04:00
parent 53e288a6f7
commit bb6e4c6acf
2 changed files with 19 additions and 19 deletions

View file

@ -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) { pub async fn websocket(stream: WebSocket, state: Arc<AppState>, who: SocketAddr) {
// By splitting, we can send and receive at the same time. // By splitting, we can send and receive at the same time.
let (mut sender, mut receiver) = stream.split(); 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(), _ = (&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))
}

View file

@ -86,6 +86,15 @@ pub struct AppState {
games: Mutex<Vec<CAHGame>>, 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] #[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
tracing_subscriber::registry() tracing_subscriber::registry()
@ -125,12 +134,3 @@ async fn main() -> Result<(), Box<dyn Error>> {
Ok(()) 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"))
}