rtci-host 0.1.0

The host I/O around the sans-I/O rtci WebRTC engine: sockets, timers, STUN/TURN clients, ICE-TCP, mDNS and media, behind a permission gate and a socket factory
Documentation
// Copyright 2026 Brainwires. MIT OR Apache-2.0.

//! The host around the sans-I/O [`rtci`] WebRTC engine: everything a
//! WebRTC implementation needs besides the protocol state machines and the
//! JavaScript bindings.
//!
//! `rtci` runs ICE, DTLS, SCTP, the data channels, SRTP and RTP as state
//! machines that never open a socket, arm a timer or read the clock. This
//! crate gives each [`Peer`] (one `RTCPeerConnection`) its sockets, timers,
//! STUN/TURN clients (UDP, TCP, TLS), ICE-TCP, mDNS, media packetizing and
//! frame assembly, the fake capture devices, and the queue of events for
//! the front end. It was extracted from the Denext-Deno fork's
//! `ext/webrtc`; the fork's built-in extension and the `rtci-ffi` library
//! are its two front ends.
//!
//! Two traits stand between the engine and the network:
//!
//! - [`NetGate`], the permission gate: every address the engine sends to,
//!   every IP it binds on and the machine's interface list are asked of it
//!   first. There is no allowing default ([`DenyAllGate`] refuses all). A
//!   gate may answer later ([`AskGate`]): the engine holds back whatever
//!   needed the answer, and [`Peer::set_remote_description`] /
//!   [`Peer::add_ice_candidate`] finish through an `opdone` event
//!   ([`JsEvent::OpDone`]).
//! - [`NetIo`], the socket factory: the only place sockets are created and
//!   names resolved, each call carrying the [`GateToken`] of the allow it
//!   needs. [`PlainNetIo`] uses the operating system's.
//!
//! # Threading
//!
//! The engine is single-threaded (`Rc` / `RefCell`). It spawns `!Send`
//! tasks on the current thread: run it on a current-thread tokio runtime
//! (as Deno does), or inside a [`tokio::task::LocalSet`].

mod args;
mod ask_gate;
mod certificate;
mod ecn;
mod encoded_frames;
mod error;
mod fake_media;
mod gate;
mod gate_cache;
// wpt100:hdrext
mod header_extensions;
// wpt100:ice
mod ice_transport;
mod log_level;
mod media;
mod media_sink;
mod net;
mod net_io;
mod peer;
mod peer_media;
mod rt;

pub use args::*;
pub use ask_gate::AskGate;
pub use ask_gate::GateRequest;
pub use ask_gate::NO_GATE_REGISTERED;
pub use certificate::CertificateStore;
pub use certificate::certificate_fingerprints;
pub use certificate::certificate_from_pem;
pub use certificate::certificate_to_pem;
pub use certificate::expires_ms;
pub use certificate::generate_certificate;
pub use error::Error;
pub use error::ErrorKind;
pub use error::Result;
pub use gate::DEFAULT_ASK_TIMEOUT;
pub use gate::DenyAllGate;
pub use gate::Direction;
pub use gate::GateToken;
pub use gate::Host;
pub use gate::LocalBoxFuture;
pub use gate::NetGate;
pub use gate::Proto;
pub use gate::Reach;
pub use gate::ReachKind;
pub use gate::Verdict;
pub use ice_transport::IceEvent;
pub use ice_transport::IceTransport;
pub use log_level::engine_log_level;
pub use log_level::is_engine_log_target;
pub use log_level::set_engine_log_level;
pub use net::IceTimeoutsArg;
pub use net::MdnsMode;
pub use net::Network;
pub use net::NetworkArg;
pub use net::NetworkOptions;
pub use net::PortRangeArg;
pub use net::PublicAddress;
pub use net::SharedEndpoint;
pub use net::TcpEndpoint;
pub use net_io::NetIo;
pub use net_io::PlainNetIo;
pub use net_io::UdpOpts;
pub use net_io::mdns_socket;
pub use peer::IceServerSpec;
pub use peer::JsEvent;
pub use peer::PairCandidate;
pub use peer::Payload;
pub use peer::Peer;
pub use peer::PeerDescriptions;
pub use peer::PeerOptions;
pub use peer::SelectedPair;
pub use peer::ServerTransport;
pub use peer::epoch_fields_relative;

/// The media types the front ends pass and receive (transceivers, tracks,
/// codecs, capabilities, frames).
pub mod media_types {
  pub use crate::encoded_frames::ReceivedFrameInfo;
  pub use crate::media::Capabilities;
  pub use crate::media::CodecArg;
  pub use crate::media::EncodingArg;
  pub use crate::media::FakeFrame;
  pub use crate::media::RemoteSection;
  pub use crate::media::SenderFrameInfo;
  pub use crate::media::TrackArg;
  pub use crate::media::TransceiverArg;
  pub use crate::media::TransceiverInfo;
  pub use crate::media::capabilities;
}

/// Whether the fake capture devices are on (`DENO_FAKE_MEDIA_DEVICES=1`).
pub fn fake_media_devices() -> bool {
  fake_media::enabled()
}

#[cfg(test)]
mod tests;