From 63f56d3daed31a6634d98c5fb88b48d4114f8769 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 6 Feb 2021 16:59:27 +0100 Subject: [PATCH] Add RTC config --- config.yaml | 13 ++++++++++++- src/data/config.rs | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 8f4e5ae..0c8e706 100644 --- a/config.yaml +++ b/config.yaml @@ -31,4 +31,15 @@ database: password: pierre # If set to true, every requests made on the database will be shown on the terminal - log_all_queries: true \ No newline at end of file + log-all-queries: true + + +# Video calls configuration +rtc-relay: + ip: ::ffff:127.0.0.1 + token: SecretToken + ice-servers: + - stun:stun.l.google.com:19302 + max-users-per-calls: 10 + allow-video: true + max-users-per-video-calls: 6 \ No newline at end of file diff --git a/src/data/config.rs b/src/data/config.rs index ceead81..e8648c2 100644 --- a/src/data/config.rs +++ b/src/data/config.rs @@ -14,16 +14,27 @@ pub struct DatabaseConfig { pub log_all_queries: bool, } +#[derive(Debug)] +pub struct RtcRelayConfig { + pub ip: String, + pub token: String, + pub ice_servers: Vec, + pub max_users_per_calls: u64, + pub allow_video: bool, + pub max_users_per_video_calls: u64, +} + #[derive(Debug)] pub struct Config { pub port: i32, pub listen_address: String, pub storage_url: String, pub storage_path: String, - pub database: DatabaseConfig, pub proxy: Option, pub force_https: bool, pub verbose_mode: bool, + pub database: DatabaseConfig, + pub rtc_relay: Option, } /// Globally available configuration @@ -34,6 +45,10 @@ impl Config { parsed[name].as_i64().expect(format!("{} is missing (int)", name).as_str()) as i32 } + fn yaml_u64(parsed: &Yaml, name: &str) -> u64 { + parsed[name].as_i64().expect(format!("{} is missing (int)", name).as_str()) as u64 + } + fn yaml_str(parsed: &Yaml, name: &str) -> String { parsed[name].as_str().expect(format!("{} is missing (str)", name).as_str()).to_string() } @@ -61,7 +76,20 @@ impl Config { name: Config::yaml_str(parsed_db, "name"), username: Config::yaml_str(parsed_db, "username"), password: Config::yaml_str(parsed_db, "password"), - log_all_queries: Config::yaml_bool(parsed_db, "log_all_queries"), + log_all_queries: Config::yaml_bool(parsed_db, "log-all-queries"), + }; + + let parsed_rtc = &parsed["rtc-relay"]; + let rtc_config = match parsed_rtc.is_badvalue() { + true => None, + false => Some(RtcRelayConfig { + 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(), + max_users_per_calls: Config::yaml_u64(parsed_rtc, "max-users-per-calls"), + allow_video: Config::yaml_bool(parsed_rtc, "allow-video"), + max_users_per_video_calls: Config::yaml_u64(parsed_rtc, "max-users-per-video-calls"), + }) }; let proxy = Config::yaml_str(parsed, "proxy"); @@ -73,8 +101,6 @@ impl Config { storage_url: Config::yaml_str(parsed, "storage-url"), storage_path: Config::yaml_str(parsed, "storage-path"), - database: database_conf, - proxy: match proxy.as_ref() { "none" => None, s => Some(s.to_string()) @@ -83,6 +109,10 @@ impl Config { force_https: Config::yaml_bool(parsed, "force-https"), verbose_mode: Config::yaml_bool(parsed, "verbose-mode"), + + database: database_conf, + + rtc_relay: rtc_config, }; // Save new configuration in memory