servo_media_webrtc/
datachannel.rs

1use crate::WebRtcError;
2
3use uuid::Uuid;
4
5pub type DataChannelId = usize;
6
7#[derive(Debug)]
8pub enum DataChannelMessage {
9    Text(String),
10    Binary(Vec<u8>),
11}
12
13#[derive(Debug)]
14pub enum DataChannelState {
15    Connecting,
16    Open,
17    Closing,
18    Closed,
19    __Unknown(i32),
20}
21
22pub enum DataChannelEvent {
23    NewChannel,
24    Open,
25    Close,
26    Error(WebRtcError),
27    OnMessage(DataChannelMessage),
28    StateChange(DataChannelState),
29}
30
31// https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit
32// plus `label`
33pub struct DataChannelInit {
34    pub label: String,
35    pub ordered: bool,
36    pub max_packet_life_time: Option<u16>,
37    pub max_retransmits: Option<u16>,
38    pub protocol: String,
39    pub negotiated: bool,
40    pub id: Option<u16>,
41}
42
43impl Default for DataChannelInit {
44    fn default() -> DataChannelInit {
45        DataChannelInit {
46            label: Uuid::new_v4().to_string(),
47            ordered: true,
48            max_packet_life_time: None,
49            max_retransmits: None,
50            protocol: String::new(),
51            negotiated: false,
52            id: None,
53        }
54    }
55}