Skip to content

Commit

Permalink
config ice_servers default value
Browse files Browse the repository at this point in the history
  • Loading branch information
hongcha98 committed Aug 27, 2023
1 parent 7a3db18 commit b7282db
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ use webrtc::ice_transport::ice_server::RTCIceServer;
pub struct Config {
#[serde(default = "default_listen")]
pub listen: String,
#[serde(default)]
#[serde(default = "default_ice_servers")]
pub ice_servers: Vec<IceServer>,
}

fn default_listen() -> String {
"0.0.0.0:3000".to_string()
}

fn default_ice_servers() -> Vec<IceServer> {
vec![IceServer {
urls: vec!["stun:stun.l.google.com:19302".to_string()],
username: "".to_string(),
credential: "".to_string(),
credential_type: "".to_string(),
}]
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct IceServer {
#[serde(default)]
Expand All @@ -38,7 +47,6 @@ impl Into<RTCIceServer> for IceServer {
}
}


impl Config {
pub(crate) fn parse() -> Self {
let mut result = fs::read_to_string("config.toml");
Expand All @@ -49,12 +57,7 @@ impl Config {
toml::from_str(cfg.as_str()).expect("config parse error")
} else {
Config {
ice_servers: vec![IceServer {
urls: vec!["stun:stun.l.google.com:19302".to_string()],
username: "".to_string(),
credential: "".to_string(),
credential_type: "".to_string(),
}],
ice_servers: default_ice_servers(),
listen: default_listen(),
}
}
Expand Down

0 comments on commit b7282db

Please sign in to comment.