From b7a0208e71d1ec77690634931cac51d64f54dcf6 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sat, 16 Oct 2021 17:45:25 +0200 Subject: [PATCH] Add "enabled" fields --- config.yaml | 3 +++ src/controllers/calls_controller.rs | 8 +++++--- src/controllers/rtc_relay_controller.rs | 2 +- src/data/config.rs | 11 +++++++++++ src/helpers/calls_helper.rs | 4 ++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/config.yaml b/config.yaml index 71f003e..75bbd8a 100644 --- a/config.yaml +++ b/config.yaml @@ -41,6 +41,8 @@ verbose-mode: true # Independent push notification service information independent-push-service: + enabled: true + # Server access (to create clients and push notifications) control-url: http://localhost:4500/ control-token: BADTOKENTOCHANGE @@ -62,6 +64,7 @@ database: # Video calls configuration rtc-relay: + enabled: true ip: 127.0.0.1 token: SecretToken ice-servers: diff --git a/src/controllers/calls_controller.rs b/src/controllers/calls_controller.rs index 71953b9..d502b0a 100644 --- a/src/controllers/calls_controller.rs +++ b/src/controllers/calls_controller.rs @@ -94,9 +94,11 @@ pub fn get_config(r: &mut UserWsRequestHandler) -> RequestResult { r.forbidden("You do not belong to any call yet!".to_string())?; } - if let Some(conf) = conf().rtc_relay.as_ref() - { - return r.set_response(UserCallsConfig::new(conf)); + if conf().is_rtc_relay_enabled() { + 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!")) diff --git a/src/controllers/rtc_relay_controller.rs b/src/controllers/rtc_relay_controller.rs index 136bb35..e736aa5 100644 --- a/src/controllers/rtc_relay_controller.rs +++ b/src/controllers/rtc_relay_controller.rs @@ -237,7 +237,7 @@ pub async fn open_ws(req: actix_web::HttpRequest, let ip = req.peer_addr().unwrap(); // Check if video calls are enabled - if conf().rtc_relay.is_none() { + if !conf().is_rtc_relay_enabled() { eprintln!("A relay from {} tried to connect to the server but the relay is disabled!", ip); return Ok(actix_web::HttpResponse::BadRequest().body("RTC Relay not configured!")); } diff --git a/src/data/config.rs b/src/data/config.rs index a4f5c78..8f6835c 100644 --- a/src/data/config.rs +++ b/src/data/config.rs @@ -18,6 +18,7 @@ pub struct DatabaseConfig { #[derive(Debug)] pub struct RtcRelayConfig { + pub enabled: bool, pub ip: String, pub token: String, pub ice_servers: Vec, @@ -28,6 +29,7 @@ pub struct RtcRelayConfig { #[derive(Debug)] pub struct IndependentPushService { + pub enabled: bool, pub control_url: String, pub control_token: String, pub public_url: String, @@ -115,6 +117,7 @@ impl Config { let rtc_config = match parsed_rtc.is_badvalue() { true => None, false => Some(RtcRelayConfig { + enabled: Config::yaml_bool(parsed_rtc, "enabled"), ip: Config::yaml_str(parsed_rtc, "ip"), token: Config::yaml_str(parsed_rtc, "token"), ice_servers: parsed_rtc["ice-servers"].as_vec().unwrap().iter().map(|f| f.as_str().unwrap().to_string()).collect(), @@ -130,6 +133,7 @@ impl Config { let independent_push_service = match parsed_independent_push_service.is_badvalue() { true => None, false => Some(IndependentPushService { + enabled: Config::yaml_bool(parsed_independent_push_service, "enabled"), control_url: Config::yaml_str(parsed_independent_push_service, "control-url"), control_token: Config::yaml_str(parsed_independent_push_service, "control-token"), public_url: Config::yaml_str(parsed_independent_push_service, "public-url"), @@ -190,9 +194,16 @@ impl Config { format!("{}:{}", self.listen_address, self.port) } + /// Check if rtc relay is enabled + pub fn is_rtc_relay_enabled(&self) -> bool { + self.rtc_relay.is_some() + && self.rtc_relay.as_ref().unwrap().enabled + } + /// Check if independent push notifications service is enabled pub fn is_independent_push_notifications_service_enabled(&self) -> bool { self.independent_push_service.is_some() + && self.independent_push_service.as_ref().unwrap().enabled } } diff --git a/src/helpers/calls_helper.rs b/src/helpers/calls_helper.rs index 7e5eedd..7d36d6e 100644 --- a/src/helpers/calls_helper.rs +++ b/src/helpers/calls_helper.rs @@ -8,6 +8,10 @@ use crate::data::conversation::Conversation; /// Check out whether a conversation can make a call or not pub fn can_have_call(conv: &Conversation) -> bool { + if !conf().is_rtc_relay_enabled() { + return false; + } + if let Some(conf) = &conf().rtc_relay { return conv.members.len() > 1 && conf.max_users_per_calls >= conv.members.len() as u64