rtc/data_channel/init.rs
1/// Dictionary for configuring properties of an RTCDataChannel.
2///
3/// The `RTCDataChannelInit` dictionary is used to configure the properties of a data channel
4/// when creating it via [`RTCPeerConnection::create_data_channel`].
5///
6/// ## Specifications
7///
8/// * [W3C RTCDataChannelInit Dictionary]
9///
10/// [W3C RTCDataChannelInit Dictionary]: https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit
11/// [`RTCPeerConnection::create_data_channel`]: crate::peer_connection::RTCPeerConnection::create_data_channel
12///
13/// ## Examples
14///
15/// ```
16/// use rtc::data_channel::RTCDataChannelInit;
17///
18/// let init = RTCDataChannelInit {
19/// ordered: false,
20/// max_retransmits: Some(3),
21/// ..Default::default()
22/// };
23/// ```
24#[derive(Default, Clone)]
25pub struct RTCDataChannelInit {
26 /// If set to `false`, data is allowed to be delivered out of order.
27 ///
28 /// The default value of `true` guarantees that data will be delivered in order.
29 /// Setting this to `false` may improve latency at the cost of ordering guarantees.
30 ///
31 /// Corresponds to the `ordered` attribute in the [W3C specification].
32 ///
33 /// [W3C specification]: https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit-ordered
34 pub ordered: bool,
35
36 /// Limits the time (in milliseconds) during which the channel will transmit or retransmit
37 /// data if not acknowledged.
38 ///
39 /// If set, this value may be clamped to the maximum value supported by the user agent.
40 /// This option cannot be used together with `max_retransmits`.
41 ///
42 /// Corresponds to the `maxPacketLifeTime` attribute in the [W3C specification].
43 ///
44 /// [W3C specification]: https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit-maxpacketlifetime
45 pub max_packet_life_time: Option<u16>,
46
47 /// Limits the number of times the channel will retransmit data if not successfully delivered.
48 ///
49 /// If set, this value may be clamped to the maximum value supported by the user agent.
50 /// This option cannot be used together with `max_packet_life_time`.
51 ///
52 /// Corresponds to the `maxRetransmits` attribute in the [W3C specification].
53 ///
54 /// [W3C specification]: https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit-maxretransmits
55 pub max_retransmits: Option<u16>,
56
57 /// The name of the subprotocol used for this channel.
58 ///
59 /// An empty string indicates no subprotocol is being used. The default is an empty string.
60 ///
61 /// Corresponds to the `protocol` attribute in the [W3C specification].
62 ///
63 /// [W3C specification]: https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit-protocol
64 pub protocol: String,
65
66 /// If `Some(id)`, the data channel is negotiated out-of-band with the given stream identifier.
67 ///
68 /// When set to `Some(id)`, the application is responsible for negotiating the channel and
69 /// creating a matching data channel with the same `id` on the remote peer. The data channel
70 /// will not be announced in-band.
71 ///
72 /// When set to `None` (the default), the user agent will announce the channel in-band and
73 /// automatically create a corresponding data channel on the remote peer.
74 ///
75 /// Corresponds to the `negotiated` and `id` attributes in the [W3C specification].
76 ///
77 /// [W3C specification]: https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit-negotiated
78 pub negotiated: Option<u16>,
79}