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

58 lines
2.2 KiB
Rust
Raw Normal View History

2021-02-05 12:21:10 +00:00
//! # WebSocket routes
//!
//! @author Pierre Hubert
use crate::controllers::{calls_controller, conversations_controller, likes_controller, user_ws_actions};
2021-02-05 12:21:10 +00:00
use crate::data::error::Res;
2021-02-05 13:24:00 +00:00
use crate::data::user_ws_request_handler::UserWsRequestHandler;
2021-02-05 12:21:10 +00:00
2021-02-05 13:24:00 +00:00
pub type WsRequestProcess = Box<dyn Fn(&mut UserWsRequestHandler) -> Res>;
2021-02-05 12:21:10 +00:00
/// WebSocket route
2021-02-05 12:25:27 +00:00
pub struct UserWsRoute {
2021-02-05 12:21:10 +00:00
pub route: String,
pub handler: WsRequestProcess,
}
2021-02-05 12:25:27 +00:00
impl UserWsRoute {
pub fn new<H>(route: &str, handler: H) -> UserWsRoute
2021-02-05 13:24:00 +00:00
where H: 'static + Fn(&mut UserWsRequestHandler) -> Res {
2021-02-05 12:25:27 +00:00
UserWsRoute {
2021-02-05 12:21:10 +00:00
route: route.to_string(),
handler: Box::new(handler),
}
}
}
/// Get the list of available WebSocket routes
2021-02-05 12:25:27 +00:00
pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
2021-02-05 12:45:40 +00:00
vec![
2021-02-05 13:24:00 +00:00
// 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),
2021-02-06 09:16:09 +00:00
UserWsRoute::new("$main/register_post", user_ws_actions::register_post),
UserWsRoute::new("$main/unregister_post", user_ws_actions::unregister_post),
2021-02-05 13:24:00 +00:00
2021-02-05 12:45:40 +00:00
// Likes controller
2021-02-08 17:24:28 +00:00
UserWsRoute::new("likes/update", likes_controller::update),
// Conversations controller
UserWsRoute::new("conversations/is_writing", conversations_controller::member_is_writing),
2021-02-08 17:24:28 +00:00
// Calls controller
UserWsRoute::new("calls/config", calls_controller::get_config),
2021-02-10 16:16:52 +00:00
UserWsRoute::new("calls/join", calls_controller::join_call),
2021-02-10 17:04:03 +00:00
UserWsRoute::new("calls/leave", calls_controller::leave_call),
2021-02-10 16:32:14 +00:00
UserWsRoute::new("calls/members", calls_controller::get_members_list),
2021-02-11 17:29:29 +00:00
UserWsRoute::new("calls/signal", calls_controller::on_client_signal),
2021-02-11 18:21:24 +00:00
UserWsRoute::new("calls/mark_ready", calls_controller::mark_user_ready),
2021-02-12 12:32:36 +00:00
UserWsRoute::new("calls/request_offer", calls_controller::request_offer),
2021-02-12 12:52:47 +00:00
UserWsRoute::new("calls/stop_streaming", calls_controller::stop_streaming),
2021-02-05 12:45:40 +00:00
]
2021-02-05 12:21:10 +00:00
}
/// Search for a route
2021-02-05 12:25:27 +00:00
pub fn find_user_ws_route(uri: &str) -> Option<UserWsRoute> {
get_user_ws_routes().into_iter().find(|r| r.route == uri)
2021-02-05 12:21:10 +00:00
}