diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index 61821da..2343c55 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -56,4 +56,5 @@ pub mod language_settings_api; pub mod security_settings_api; pub mod account_image_settings_api; pub mod res_create_custom_emoji; -pub mod res_get_ws_token; \ No newline at end of file +pub mod res_get_ws_token; +pub mod user_calls_config; \ No newline at end of file diff --git a/src/api_data/user_calls_config.rs b/src/api_data/user_calls_config.rs new file mode 100644 index 0000000..fbeb28b --- /dev/null +++ b/src/api_data/user_calls_config.rs @@ -0,0 +1,19 @@ +//! # User side calls configuration +//! +//! @author Pierre Hubert + +use serde::Serialize; + +use crate::data::config::RtcRelayConfig; + +#[derive(Serialize)] +#[allow(non_snake_case)] +pub struct UserCallsConfig { + iceServers: Vec, +} + +impl UserCallsConfig { + pub fn new(conf: &RtcRelayConfig) -> Self { + Self { iceServers: conf.ice_servers.clone() } + } +} \ No newline at end of file diff --git a/src/controllers/calls_controller.rs b/src/controllers/calls_controller.rs index b5c9893..62eb468 100644 --- a/src/controllers/calls_controller.rs +++ b/src/controllers/calls_controller.rs @@ -4,13 +4,29 @@ use std::collections::HashMap; +use crate::api_data::user_calls_config::UserCallsConfig; use crate::controllers::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; +use crate::data::config::conf; +use crate::data::error::ExecError; use crate::data::http_request_handler::HttpRequestHandler; +use crate::data::user_ws_request_handler::UserWsRequestHandler; /// Get legacy call configuration pub fn get_legacy_config(r: &mut HttpRequestHandler) -> RequestResult { let mut map = HashMap::new(); map.insert("enabled", false); r.set_response(map) +} + +/// Get calls configuration +pub fn get_config(r: &mut UserWsRequestHandler) -> RequestResult { + // TODO : check whether the user is the member of a call or not + + if let Some(conf) = conf().rtc_relay.as_ref() + { + return r.set_response(UserCallsConfig::new(conf)); + } + + r.internal_error(ExecError::boxed_new("Missing calls configuration!")) } \ No newline at end of file diff --git a/src/controllers/rtc_relay_controller.rs b/src/controllers/rtc_relay_controller.rs index 72c0fbd..2884411 100644 --- a/src/controllers/rtc_relay_controller.rs +++ b/src/controllers/rtc_relay_controller.rs @@ -79,6 +79,8 @@ impl StreamHandler Vec { UserWsRoute::new("$main/unregister_post", user_ws_actions::unregister_post), // Likes controller - UserWsRoute::new("likes/update", likes_controller::update) + UserWsRoute::new("likes/update", likes_controller::update), + + // Calls controller + UserWsRoute::new("calls/config", calls_controller::get_config), ] }