//! # WebSocket routes //! //! @author Pierre Hubert use crate::controllers::{calls_controller, likes_controller, user_ws_actions}; use crate::data::error::Res; use crate::data::user_ws_request_handler::UserWsRequestHandler; pub type WsRequestProcess = Box Res>; /// WebSocket route pub struct UserWsRoute { pub route: String, pub handler: WsRequestProcess, } impl UserWsRoute { pub fn new(route: &str, handler: H) -> UserWsRoute where H: 'static + Fn(&mut UserWsRequestHandler) -> Res { UserWsRoute { route: route.to_string(), handler: Box::new(handler), } } } /// Get the list of available WebSocket routes pub fn get_user_ws_routes() -> Vec { vec![ // Main controller UserWsRoute::new("$main/set_incognito", user_ws_actions::set_incognito), UserWsRoute::new("$main/register_conv", user_ws_actions::register_conv), UserWsRoute::new("$main/unregister_conv", user_ws_actions::unregister_conv), UserWsRoute::new("$main/register_post", user_ws_actions::register_post), UserWsRoute::new("$main/unregister_post", user_ws_actions::unregister_post), // Likes controller UserWsRoute::new("likes/update", likes_controller::update), // Calls controller UserWsRoute::new("calls/config", calls_controller::get_config), UserWsRoute::new("calls/join", calls_controller::join_call), UserWsRoute::new("calls/leave", calls_controller::leave_call), UserWsRoute::new("calls/members", calls_controller::get_members_list), UserWsRoute::new("calls/signal", calls_controller::on_client_signal), UserWsRoute::new("calls/mark_ready", calls_controller::mark_user_ready), UserWsRoute::new("calls/request_offer", calls_controller::request_offer), ] } /// Search for a route pub fn find_user_ws_route(uri: &str) -> Option { get_user_ws_routes().into_iter().find(|r| r.route == uri) }