1use serde::{Deserialize, Serialize};
2use std::sync::Arc;
3
4#[derive(Debug, Clone, Copy)]
6pub enum BackendModule {
7 #[cfg(feature = "backend-libdatachannel")]
9 LibDataChannel,
10
11 #[cfg(feature = "backend-go-pion")]
13 GoPion,
14}
15
16impl Default for BackendModule {
17 #[allow(unreachable_code)]
18 fn default() -> Self {
19 #[cfg(feature = "backend-libdatachannel")]
20 return Self::LibDataChannel;
21 #[cfg(feature = "backend-go-pion")]
22 Self::GoPion
23 }
24}
25
26#[derive(Default)]
28pub struct HubConfig {
29 pub backend_module: BackendModule,
31
32 pub signal_config: Arc<tx5_signal::SignalConfig>,
34
35 pub webrtc_connect_timeout: std::time::Duration,
42
43 pub danger_force_signal_relay: bool,
45
46 pub danger_deny_signal_relay: bool,
48}
49
50#[derive(Debug, Clone, Default, Serialize, Deserialize)]
52#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
53pub enum CredentialType {
54 #[default]
56 Password,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, Default)]
61#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
62#[serde(rename_all = "camelCase")]
63pub struct IceServers {
64 pub urls: Vec<String>,
66
67 #[serde(default, skip_serializing_if = "Option::is_none")]
69 pub username: Option<String>,
70
71 #[serde(default, skip_serializing_if = "Option::is_none")]
73 pub credential: Option<String>,
74
75 #[serde(default, skip_serializing_if = "Option::is_none")]
77 pub credential_type: Option<CredentialType>,
78}
79
80#[derive(Debug, Clone, Default, Serialize, Deserialize)]
82#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
83#[serde(rename_all = "camelCase")]
84pub enum TransportPolicy {
85 #[default]
87 All,
88 Relay,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize, Default)]
97#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
98#[serde(rename_all = "camelCase")]
99pub struct WebRtcConfig {
100 pub ice_servers: Vec<IceServers>,
102
103 #[serde(default)]
105 pub ice_transport_policy: TransportPolicy,
106}
107
108#[cfg(feature = "backend-go-pion")]
109impl WebRtcConfig {
110 pub fn to_go_buf(&self) -> std::io::Result<tx5_go_pion::GoBuf> {
112 serde_json::to_vec(self)
113 .map_err(|e| {
114 std::io::Error::other(format!(
115 "failed to serialize WebRtcConfig: {}",
116 e
117 ))
118 })?
119 .try_into()
120 }
121}