use super::Client;
use crate::dc::ChannelConfig;
impl Client {
#[must_use]
pub fn with_extra_dc(mut self, label: &str, id: u16, cfg: ChannelConfig) -> Self {
debug_assert!(
!self.extra_dcs.iter().any(|c| c.id() == id),
"DC id {} already registered (existing labels: {:?})",
id,
self.extra_dcs.iter().map(|c| c.label()).collect::<Vec<_>>()
);
debug_assert!(
cfg.max_packet_lifetime_ms.is_none() || cfg.max_retransmits.is_none(),
"ChannelConfig invariant violated: max_packet_lifetime_ms and max_retransmits \
cannot both be Some (label={label}, id={id})"
);
let mut entry = cfg;
entry.id = id;
entry.label = label.to_string();
self.extra_dcs.push(entry);
self
}
#[must_use]
pub fn with_chat_dcs(self) -> Self {
self.with_extra_dc("chat-data", 4, ChannelConfig::reliable_ordered())
.with_extra_dc("chat-ctrl", 5, ChannelConfig::unreliable_max_retransmits(0))
}
#[must_use]
pub fn with_voice_dc(self, max_pkt_lifetime_ms: u32) -> Self {
self.with_extra_dc(
"voice",
6,
ChannelConfig::unreliable_max_lifetime(max_pkt_lifetime_ms),
)
}
}
#[cfg(any(test, feature = "test-utils"))]
impl Client {
#[must_use]
pub fn new_for_test() -> Self {
crate::client::test_seed::new_client(crate::propagate::ClientId(u64::MAX))
}
#[must_use]
pub fn dc_config_for(&self, label: &str) -> Option<&ChannelConfig> {
self.extra_dcs.iter().find(|dc| dc.label() == label)
}
#[must_use]
pub fn dc_count(&self) -> usize {
self.extra_dcs.len()
}
}