#[derive(Debug, Clone, Default)]
pub struct IceServer {
pub urls: Vec<String>,
pub username: String,
pub password: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContinualGatheringPolicy {
GatherOnce,
GatherContinually,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IceTransportsType {
All,
Relay,
NoHost,
None,
}
#[derive(Debug, Clone)]
pub struct RtcConfiguration {
pub ice_servers: Vec<IceServer>,
pub continual_gathering_policy: ContinualGatheringPolicy,
pub ice_transport_type: IceTransportsType,
}
impl Default for RtcConfiguration {
fn default() -> Self {
Self {
ice_servers: Vec::new(),
continual_gathering_policy: ContinualGatheringPolicy::GatherContinually,
ice_transport_type: IceTransportsType::All,
}
}
}
impl RtcConfiguration {
pub(crate) fn to_json(&self) -> String {
let urls: Vec<String> = self
.ice_servers
.iter()
.flat_map(|s| s.urls.iter())
.map(|u| format!("\"{}\"", u.replace(['"', '\\'], "")))
.collect();
format!("{{\"iceServers\":[{{\"urls\":[{}]}}]}}", urls.join(","))
}
}