Expand description
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 (DenyAllGaterefuses all). A gate may answer later (AskGate): the engine holds back whatever needed the answer, andPeer::set_remote_description/Peer::add_ice_candidatefinish through anopdoneevent (JsEvent::OpDone).NetIo, the socket factory: the only place sockets are created and names resolved, each call carrying theGateTokenof the allow it needs.PlainNetIouses 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.
Modules§
- media_
types - The media types the front ends pass and receive (transceivers, tracks, codecs, capabilities, frames).
Structs§
- AskGate
- An asynchronous gate answered by ticket. Deny by default: until
AskGate::attachevery question is refused at once (NO_GATE_REGISTERED). Once attached, each question the engine asks queues aGateRequest(AskGate::take_requests) and runs the notifier (AskGate::set_notify);AskGate::answerdelivers the verdict. An answer is remembered and reused for the same question from any connection on this gate (NetGate::decide). - Candidate
Arg RTCIceCandidateInit.- Certificate
Info - An
RTCCertificatefor the front end’s JavaScript. - Certificate
Store - The
RTCCertificates of a realm, by id: each holds a key and an X.509 certificate for the DTLS handshakes of the connections given it. The front end removes an entry when itsRTCCertificateis garbage collected; a connection keeps its own copy. - Config
Arg RTCConfiguration, as the front end’s JavaScript passes it.- Created
Channel - A created data channel: its engine handle and its stream id, when assigned.
- Data
Channel Arg createDataChannel(label, init).- Deny
AllGate - Refuses everything.
- Error
- A failure of an
rtci-hostcall: its kind and message. - Fingerprint
Info - One
RTCDtlsFingerprint. - Gate
Request - One question for the front end: the
gaterequestevent. - Gate
Token - Proof that the gate allowed a
Reach: everyNetIocall that creates a socket or resolves a name takes one. Only the engine mints them (there is no public constructor), from an allow for theReachthe call is for, so aNetIoimplementation may checkGateToken::reachagainst its arguments. - IceServer
Arg - One
RTCIceServer. - IceServer
Spec - A STUN or TURN server URL from
RTCConfiguration.iceServers, parsed and permission-checked by the constructor. - IceTimeouts
Arg - IceTransport
- Keygen
Arg generateCertificate’s algorithm (WebCrypto’s dictionaries).- Network
- Network
Arg - Network
Options - Pair
Candidate - One candidate of
SelectedPair, with the fields JavaScript needs to build theRTCIceCandidate(a peer-reflexive remote candidate is exposed without its address, so it can’t be found among the signalled ones). - Payload
- A received payload’s bytes (a data channel message, an RTP packet, a frame). Serializes as bytes.
- Peer
- Peer
Descriptions - The four description slots of a connection, each
(type, sdp). - Peer
Options - Options for
Peer::new, fromRTCConfiguration. - Plain
NetIo - The operating system’s sockets and resolver, unrouted.
- Port
Range Arg - Public
Address - A public address and the private one it maps to (
None: every private address). - Reach
- One thing the engine wants to reach.
- Selected
Pair - The ICE agent’s selected candidate pair.
- Shared
Endpoint - One of a shared port’s sockets.
- TcpEndpoint
- One of an ICE-TCP network’s listeners.
- UdpOpts
- How
NetIo::bind_udpbinds.
Enums§
- Direction
- Whether a
Reachsends to an address or binds one. - Error
Kind - Which exception a failure is, as the W3C WebRTC specs name them.
- Host
- A host a
Reachnames: a name (an ICE server URL’s host, before DNS) or an IP address. - IceEvent
- An event for JavaScript, delivered in batches by
op_webrtc_ice_next_events. - JsEvent
- An event for JavaScript, delivered in batches by
Peer::next_events. Data channels are named by their engine handle (channel), which exists before the SCTP stream id does. - Mdns
Mode - What a connection does with mDNS
.localhost candidates. - Proto
- The transport of a
Reach. - Reach
Kind - Why the engine asks (for logs and prompts; a gate may also decide on
it). The engine’s cache of asked answers ignores the kind: an answer for
one kind is reused for another with the same direction, transport, host,
port and
resolved_from. - Server
Transport - How a STUN/TURN client reaches its server.
- Verdict
- A gate’s answer.
Constants§
- DEFAULT_
ASK_ TIMEOUT - How long the engine waits for an asked answer by default
(
NetGate::ask_timeout). - NO_
GATE_ REGISTERED - The refusal for every question asked before
AskGate::attach.
Traits§
- NetGate
- The net permission gate. There is no allowing default: every
Peer,NetworkandIceTransportis given one, andDenyAllGaterefuses everything. - NetIo
- The socket factory.
Functions§
- certificate_
fingerprints - The certificate’s fingerprints, in each algorithm the engine computes.
- certificate_
from_ pem - The inverse of
certificate_to_pem; anything else is aSyntaxError. - certificate_
to_ pem Deno.webrtc.exportCertificate: the key and certificate as PEM, with theexpirestime, to keep a server’s DTLS fingerprint across restarts.- check_
ice_ servers - Asks
gatefor each server’s host and port before DNS (ReachKind::IceServer); the first refusal is aErrorKind::NotCapableerror. - engine_
log_ level - The engine’s log level (off by default: its outcomes are
RTCPeerConnectionevents). A host’s logger shows engine records at or above it, and no others. - epoch_
fields_ relative - One stats dictionary with its epoch fields made relative to
wall_ms, the wall clock (milliseconds since the epoch) when the report was asked for: JavaScript adds the Performance time of that moment, so the timestamps areDOMHighResTimeStamps onperformance.timeOrigin’s timeline (W3C webrtc-stats, hr-time) whatever the wall clock does. - expires_
ms - The W3C
expires, a DOMTimeStamp: whole milliseconds since the epoch. - fake_
media_ devices - Whether the fake capture devices are on (
DENO_FAKE_MEDIA_DEVICES=1). - generate_
certificate - The DTLS key: ECDSA P-256 (what browsers default to), or RSASSA-PKCS1-v1_5
with SHA-256 and the public exponent 65537 (WebCrypto’s algorithm
dictionaries, as
generateCertificatetakes them). CPU-heavy for RSA: call it off the engine’s thread. - is_
engine_ log_ target - Whether a log record comes from the WebRTC engine (the
rtciandrtci_*crates), whose recordsset_engine_log_levelgoverns. This crate’s own records (rtci_host::*) are not the engine’s: they follow the host’s log filter, as they did inside the Deno extension. - mdns_
socket - Finishes an mDNS socket (IPv4, UDP): reuse options and the bind on
0.0.0.0:5353unlessbound(a socket handed out bound already, as a sandbox broker does), non-blocking, multicast TTL 255 with loopback, and the mDNS group joined on each non-loopback IPv4 address ofhosts(on the default interface when none joins). ForNetIo::bind_mdnsimplementations. - needs_
tls - Whether any server needs TLS (
turns:/stuns:): the front end then buildsPeerOptions::tls. - parse_
ice_ servers - Parses every URL of
RTCConfiguration.iceServers(the W3CSyntaxError/InvalidAccessErrorchecks); no gate is asked. - set_
engine_ log_ level - Sets the engine’s log level by name:
off,error,warn,info,debugortrace(aErrorKind::Typeerror for any other).
Type Aliases§
- Local
BoxFuture - A boxed,
!Sendfuture (the engine is single-threaded). - Result
Resultwith this crate’sError.