22 lines
650 B
Rust
22 lines
650 B
Rust
use std::net::SocketAddr;
|
|
|
|
use axum::extract::ws::WebSocketUpgrade;
|
|
use axum::extract::ConnectInfo;
|
|
use axum::response::IntoResponse;
|
|
use axum_extra::{headers, TypedHeader};
|
|
use library::context::Context;
|
|
use macros::ws;
|
|
|
|
use crate::service::websocket_service;
|
|
|
|
#[ws("/ws")]
|
|
pub async fn websocket_handler(
|
|
context: Context,
|
|
ws: WebSocketUpgrade,
|
|
user_agent: Option<TypedHeader<headers::UserAgent>>,
|
|
ConnectInfo(addr): ConnectInfo<SocketAddr>
|
|
) -> impl IntoResponse {
|
|
tracing::info!("`{:?}` at {:?} connected.", user_agent, addr);
|
|
ws.on_upgrade(move |socket| websocket_service::handle_socket(socket, addr, context))
|
|
}
|