Skip to main content

rtci_host/
lib.rs

1// Copyright 2026 Brainwires. MIT OR Apache-2.0.
2
3//! The host around the sans-I/O [`rtci`] WebRTC engine: everything a
4//! WebRTC implementation needs besides the protocol state machines and the
5//! JavaScript bindings.
6//!
7//! `rtci` runs ICE, DTLS, SCTP, the data channels, SRTP and RTP as state
8//! machines that never open a socket, arm a timer or read the clock. This
9//! crate gives each [`Peer`] (one `RTCPeerConnection`) its sockets, timers,
10//! STUN/TURN clients (UDP, TCP, TLS), ICE-TCP, mDNS, media packetizing and
11//! frame assembly, the fake capture devices, and the queue of events for
12//! the front end. It was extracted from the Denext-Deno fork's
13//! `ext/webrtc`; the fork's built-in extension and the `rtci-ffi` library
14//! are its two front ends.
15//!
16//! Two traits stand between the engine and the network:
17//!
18//! - [`NetGate`], the permission gate: every address the engine sends to,
19//!   every IP it binds on and the machine's interface list are asked of it
20//!   first. There is no allowing default ([`DenyAllGate`] refuses all). A
21//!   gate may answer later ([`AskGate`]): the engine holds back whatever
22//!   needed the answer, and [`Peer::set_remote_description`] /
23//!   [`Peer::add_ice_candidate`] finish through an `opdone` event
24//!   ([`JsEvent::OpDone`]).
25//! - [`NetIo`], the socket factory: the only place sockets are created and
26//!   names resolved, each call carrying the [`GateToken`] of the allow it
27//!   needs. [`PlainNetIo`] uses the operating system's.
28//!
29//! # Threading
30//!
31//! The engine is single-threaded (`Rc` / `RefCell`). It spawns `!Send`
32//! tasks on the current thread: run it on a current-thread tokio runtime
33//! (as Deno does), or inside a [`tokio::task::LocalSet`].
34
35mod args;
36mod ask_gate;
37mod certificate;
38mod ecn;
39mod encoded_frames;
40mod error;
41mod fake_media;
42mod gate;
43mod gate_cache;
44// wpt100:hdrext
45mod header_extensions;
46// wpt100:ice
47mod ice_transport;
48mod log_level;
49mod media;
50mod media_sink;
51mod net;
52mod net_io;
53mod peer;
54mod peer_media;
55mod rt;
56
57pub use args::*;
58pub use ask_gate::AskGate;
59pub use ask_gate::GateRequest;
60pub use ask_gate::NO_GATE_REGISTERED;
61pub use certificate::CertificateStore;
62pub use certificate::certificate_fingerprints;
63pub use certificate::certificate_from_pem;
64pub use certificate::certificate_to_pem;
65pub use certificate::expires_ms;
66pub use certificate::generate_certificate;
67pub use error::Error;
68pub use error::ErrorKind;
69pub use error::Result;
70pub use gate::DEFAULT_ASK_TIMEOUT;
71pub use gate::DenyAllGate;
72pub use gate::Direction;
73pub use gate::GateToken;
74pub use gate::Host;
75pub use gate::LocalBoxFuture;
76pub use gate::NetGate;
77pub use gate::Proto;
78pub use gate::Reach;
79pub use gate::ReachKind;
80pub use gate::Verdict;
81pub use ice_transport::IceEvent;
82pub use ice_transport::IceTransport;
83pub use log_level::engine_log_level;
84pub use log_level::is_engine_log_target;
85pub use log_level::set_engine_log_level;
86pub use net::IceTimeoutsArg;
87pub use net::MdnsMode;
88pub use net::Network;
89pub use net::NetworkArg;
90pub use net::NetworkOptions;
91pub use net::PortRangeArg;
92pub use net::PublicAddress;
93pub use net::SharedEndpoint;
94pub use net::TcpEndpoint;
95pub use net_io::NetIo;
96pub use net_io::PlainNetIo;
97pub use net_io::UdpOpts;
98pub use net_io::mdns_socket;
99pub use peer::IceServerSpec;
100pub use peer::JsEvent;
101pub use peer::PairCandidate;
102pub use peer::Payload;
103pub use peer::Peer;
104pub use peer::PeerDescriptions;
105pub use peer::PeerOptions;
106pub use peer::SelectedPair;
107pub use peer::ServerTransport;
108pub use peer::epoch_fields_relative;
109
110/// The media types the front ends pass and receive (transceivers, tracks,
111/// codecs, capabilities, frames).
112pub mod media_types {
113  pub use crate::encoded_frames::ReceivedFrameInfo;
114  pub use crate::media::Capabilities;
115  pub use crate::media::CodecArg;
116  pub use crate::media::EncodingArg;
117  pub use crate::media::FakeFrame;
118  pub use crate::media::RemoteSection;
119  pub use crate::media::SenderFrameInfo;
120  pub use crate::media::TrackArg;
121  pub use crate::media::TransceiverArg;
122  pub use crate::media::TransceiverInfo;
123  pub use crate::media::capabilities;
124}
125
126/// Whether the fake capture devices are on (`DENO_FAKE_MEDIA_DEVICES=1`).
127pub fn fake_media_devices() -> bool {
128  fake_media::enabled()
129}
130
131#[cfg(test)]
132mod tests;