Skip to main content

rtc_datachannel/
lib.rs

1#![warn(rust_2018_idioms)]
2#![warn(missing_docs)]
3#![allow(dead_code)]
4
5//! WebRTC data channels over SCTP.
6//!
7//! The Data Channel Establishment Protocol ([RFC 8832]) and the SCTP-based data channel
8//! layer ([RFC 8831]): the `DATA_CHANNEL_OPEN` handshake, the reliability and ordering
9//! parameters, and the payload protocol identifiers that distinguish string from binary
10//! messages.
11//!
12//! # Structure
13//!
14//! * [`data_channel`] — one channel's state and its read/write surface over an SCTP
15//!   stream, including partial-reliability settings (`maxPacketLifeTime`,
16//!   `maxRetransmits`).
17//! * [`message`] — the DCEP messages themselves: `DataChannelOpen`, `DataChannelAck`, and
18//!   the channel-type encoding.
19//!
20//! # Example
21//!
22//! ```
23//! use bytes::Bytes;
24//! use rtc_datachannel::message::message_channel_open::{ChannelType, DataChannelOpen};
25//! use rtc_datachannel::message::{Message, message_type::MessageType};
26//! use shared::marshal::{Marshal, Unmarshal};
27//!
28//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
29//! let open = Message::DataChannelOpen(DataChannelOpen {
30//!     channel_type: ChannelType::PartialReliableRexmit,
31//!     priority: 256,
32//!     reliability_parameter: 3, // give up after 3 retransmissions
33//!     label: b"chat".to_vec(),
34//!     protocol: Vec::new(),
35//! });
36//! assert_eq!(open.message_type(), MessageType::DataChannelOpen);
37//!
38//! let encoded = open.marshal()?;
39//! let mut buf = Bytes::from(encoded.to_vec());
40//! assert_eq!(Message::unmarshal(&mut buf)?, open);
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! Most applications do not depend on this crate directly — the
46//! [`rtc`](https://docs.rs/rtc) crate layers it over [`rtc-sctp`] and exposes
47//! `RTCDataChannel`.
48//!
49//! [RFC 8832]: https://datatracker.ietf.org/doc/html/rfc8832
50//! [RFC 8831]: https://datatracker.ietf.org/doc/html/rfc8831
51//! [`rtc-sctp`]: https://docs.rs/rtc-sctp
52
53/// One data channel's state and its read/write surface over an SCTP stream.
54pub mod data_channel;
55/// The DCEP messages exchanged to open, acknowledge and close a channel.
56pub mod message;