use crate::data_channel::internal::RTCDataChannelInternal;
use crate::data_channel::{RTCDataChannelId, RTCDataChannelState, StreamId};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RTCClosedDataChannel {
id: RTCDataChannelId,
stream_id: Option<StreamId>,
label: String,
protocol: String,
ordered: bool,
max_packet_life_time: Option<u16>,
max_retransmits: Option<u16>,
negotiated: bool,
priority: u16,
buffered_amount: u64,
buffered_amount_low_threshold: u32,
}
pub const MAX_KEPT_CLOSED_DATA_CHANNELS: usize = 64;
impl RTCClosedDataChannel {
pub(crate) fn of(channel: &RTCDataChannelInternal) -> Self {
Self {
id: channel.id,
stream_id: channel.stream_id,
label: channel.label().to_owned(),
protocol: channel.protocol().to_owned(),
ordered: channel.ordered,
max_packet_life_time: channel.max_packet_life_time,
max_retransmits: channel.max_retransmits,
negotiated: channel.negotiated,
priority: channel.priority,
buffered_amount: channel
.bytes_queued
.saturating_sub(channel.bytes_dequeued_at_close.unwrap_or(0)),
buffered_amount_low_threshold: channel.buffered_amount_low_threshold,
}
}
pub fn id(&self) -> RTCDataChannelId {
self.id
}
pub fn stream_id(&self) -> Option<StreamId> {
self.stream_id
}
pub fn label(&self) -> &str {
&self.label
}
pub fn protocol(&self) -> &str {
&self.protocol
}
pub fn ordered(&self) -> bool {
self.ordered
}
pub fn max_packet_life_time(&self) -> Option<u16> {
self.max_packet_life_time
}
pub fn max_retransmits(&self) -> Option<u16> {
self.max_retransmits
}
pub fn negotiated(&self) -> bool {
self.negotiated
}
pub fn priority(&self) -> u16 {
self.priority
}
pub fn ready_state(&self) -> RTCDataChannelState {
RTCDataChannelState::Closed
}
pub fn buffered_amount(&self) -> u64 {
self.buffered_amount
}
pub fn buffered_amount_low_threshold(&self) -> u32 {
self.buffered_amount_low_threshold
}
}