1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00
comunicapiv3/src/user_ws_routes.rs

58 lines
2.2 KiB
Rust

//! # WebSocket routes
//!
//! @author Pierre Hubert
use crate::controllers::{calls_controller, conversations_controller, likes_controller, user_ws_actions};
use crate::data::error::Res;
use crate::data::user_ws_request_handler::UserWsRequestHandler;
pub type WsRequestProcess = Box<dyn Fn(&mut UserWsRequestHandler) -> Res>;
/// WebSocket route
pub struct UserWsRoute {
pub route: String,
pub handler: WsRequestProcess,
}
impl UserWsRoute {
pub fn new<H>(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<UserWsRoute> {
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),
// Conversations controller
UserWsRoute::new("conversations/is_writing", conversations_controller::member_is_writing),
// 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),
UserWsRoute::new("calls/stop_streaming", calls_controller::stop_streaming),
]
}
/// Search for a route
pub fn find_user_ws_route(uri: &str) -> Option<UserWsRoute> {
get_user_ws_routes().into_iter().find(|r| r.route == uri)
}