contactor 0.1.0-alpha.1

A distributed, eventual persisted, websockets framework.
Documentation
use std::sync::Arc;

use axum::{
    extract::{ws::WebSocketUpgrade, Path, State},
    response::IntoResponse,
};

use crate::relay::RelayNode;

pub struct AppState {
    pub node: Arc<RelayNode>,
}

pub async fn ws_handler(
    ws: WebSocketUpgrade,
    State(state): State<Arc<AppState>>,
    Path(room_name): Path<String>,
) -> impl IntoResponse {
    ws.on_upgrade(move |socket| {
        let node = state.node.clone();
        let room_name = room_name.clone();
        async move {
            node.handle_upgrade(socket, room_name).await;
        }
    })
}