oops
This commit is contained in:
parent
840a839541
commit
53e288a6f7
2 changed files with 18 additions and 17 deletions
20
src/api.rs
20
src/api.rs
|
@ -1,6 +1,12 @@
|
|||
use crate::AppState;
|
||||
use axum::extract::ws::{Message, WebSocket};
|
||||
use futures::{sink::SinkExt, stream::StreamExt};
|
||||
use axum::{
|
||||
extract::{
|
||||
ws::{Message, WebSocket},
|
||||
ConnectInfo, State, WebSocketUpgrade,
|
||||
},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
pub mod message_handler;
|
||||
use crate::message_handler::*;
|
||||
|
@ -14,6 +20,16 @@ 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();
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
use crate::api::{greeting, Message, SocketAddr};
|
||||
use crate::websocket;
|
||||
use crate::AppState;
|
||||
use crate::Arc;
|
||||
use crate::CAHGame;
|
||||
use crate::CAHPlayer;
|
||||
use axum::{
|
||||
extract::{ConnectInfo, State, WebSocketUpgrade},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// New game request structure
|
||||
|
@ -31,16 +26,6 @@ pub struct GameJoinRequest {
|
|||
pub player: CAHPlayer,
|
||||
}
|
||||
|
||||
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 message_handler(message: Message, state: &Arc<AppState>, who: SocketAddr) {
|
||||
let tx = &state.tx;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue