fix webrtc and login
This commit is contained in:
@@ -50,6 +50,10 @@ host = "0.0.0.0"
|
||||
tcp_port = 8080
|
||||
# WebRTC ICE/Media UDP multiplexing port
|
||||
udp_port = 8080
|
||||
# Public IPv4 address advertised by ICE when behind NAT (forward udp_port to this server).
|
||||
# external_ip = "203.0.113.1"
|
||||
# STUN servers used when external_ip is absent; set [] to disable discovery.
|
||||
# stun_servers = ["stun:stun.l.google.com:19302"]
|
||||
|
||||
# Optional native HTTPS (omit this section to keep plain HTTP behind a proxy).
|
||||
# [network.tls]
|
||||
@@ -110,9 +114,17 @@ pub struct NetworkConfig {
|
||||
pub tcp_port: u16,
|
||||
pub udp_port: u16,
|
||||
#[serde(default)]
|
||||
pub external_ip: Option<Ipv4Addr>,
|
||||
#[serde(default = "default_stun_servers")]
|
||||
pub stun_servers: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub tls: Option<TlsConfig>,
|
||||
}
|
||||
|
||||
fn default_stun_servers() -> Vec<String> {
|
||||
vec!["stun:stun.l.google.com:19302".to_string()]
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct TlsConfig {
|
||||
pub cert_path: std::path::PathBuf,
|
||||
@@ -170,3 +182,38 @@ impl AppConfig {
|
||||
Self::load()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{AppConfig, DEFAULT_CONFIG_TOML};
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
#[test]
|
||||
fn external_ip_is_optional_and_accepts_public_ipv4() {
|
||||
let default: AppConfig = toml::from_str(DEFAULT_CONFIG_TOML).unwrap();
|
||||
assert_eq!(default.network.external_ip, None);
|
||||
assert_eq!(default.network.stun_servers, vec!["stun:stun.l.google.com:19302"]);
|
||||
|
||||
let configured = DEFAULT_CONFIG_TOML.replace(
|
||||
"# external_ip = \"203.0.113.1\"",
|
||||
"external_ip = \"203.0.113.1\"",
|
||||
);
|
||||
let config: AppConfig = toml::from_str(&configured).unwrap();
|
||||
assert_eq!(config.network.external_ip, Some(Ipv4Addr::new(203, 0, 113, 1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stun_servers_can_be_disabled_or_replaced() {
|
||||
for (value, expected) in [
|
||||
("[]", vec![]),
|
||||
("[\"stun:example.org:3478\"]", vec!["stun:example.org:3478"]),
|
||||
] {
|
||||
let text = DEFAULT_CONFIG_TOML.replace(
|
||||
"# stun_servers = [\"stun:stun.l.google.com:19302\"]",
|
||||
&format!("stun_servers = {value}"),
|
||||
);
|
||||
let config: AppConfig = toml::from_str(&text).unwrap();
|
||||
assert_eq!(config.network.stun_servers, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user