Overview
RTC is a pure Rust implementation of WebRTC using a sans-I/O architecture. Unlike traditional WebRTC libraries, RTC separates protocol logic from I/O operations, giving you complete control over networking, threading, and async runtime integration.
What is Sans-I/O?
Sans-I/O (without I/O) is a design pattern where the library handles protocol logic but you control all I/O operations. Instead of the library performing network reads and writes directly, you feed it network data and it tells you what to send.
Benefits:
- ๐ Runtime Independent - Works with tokio, async-std, smol, or blocking I/O
- ๐ฏ Full Control - You control threading, scheduling, and I/O multiplexing
- ๐งช Testable - Protocol logic can be tested without real network I/O
- ๐ Flexible - Easy integration with existing networking code
Sans-I/O Event Loop Pattern
The sans-I/O architecture uses a simple event loop with six core methods:
Core API Methods
poll_write()- Get outgoing network packets to send via UDPpoll_event()- Process connection state changes and notificationspoll_read()- Get incoming application messages (RTP, RTCP, data)poll_timeout()- Get next timer deadline for retransmissions/keepaliveshandle_read()- Feed incoming network packets into the connectionhandle_timeout()- Notify about timer expiration
Additional methods for external control:
- handle_write() - Queue application messages (RTP/RTCP/data) for sending
- handle_event() - Inject external events into the connection
Event Loop Example
use RTCPeerConnection;
use RTCConfigurationBuilder;
use ;
use RTCPeerConnectionState;
use RTCMessage;
use RTCSessionDescription;
use ;
use Protocol;
use ;
use UdpSocket;
use BytesMut;
async
Features
- โ ICE (Interactive Connectivity Establishment) - NAT traversal with STUN/TURN
- โ DTLS (Datagram Transport Layer Security) - Encryption for media and data
- โ SCTP (Stream Control Transmission Protocol) - Reliable data channels
- โ RTP/RTCP - Real-time media transport and control
- โ SDP (Session Description Protocol) - Offer/answer negotiation
- โ Data Channels - Bidirectional peer-to-peer data transfer
- โ Media Tracks - Audio/video transmission
- โ Trickle ICE - Progressive candidate gathering
- โ Simulcast & SVC - Scalable video coding
More Examples
The repository includes comprehensive examples demonstrating various use cases:
- data-channels-offer-answer - Complete data channel setup with signaling
- reflect - Echo server that reflects media back to sender
- save-to-disk-vpx - Receive and save VP8/VP9 video
- play-from-disk-vpx - Send VP8/VP9 video from disk
Run an example:
Architecture
RTC is built from composable crates, each implementing a specific protocol:
RTC Crates
Dependency Graph
Protocol Stack
Common Use Cases
Data Channels
use RTCDataChannelInit;
Media Tracks
use MediaStreamTrack;
use ;
Signaling
WebRTC requires an external signaling channel (e.g., WebSocket, HTTP) to exchange offers and answers:
Specification Compliance
This implementation follows these specifications:
- W3C WebRTC 1.0 - Main WebRTC API specification
- RFC 8829 - JSEP: JavaScript Session Establishment Protocol
- RFC 8866 - SDP: Session Description Protocol
- RFC 8445 - ICE: Interactive Connectivity Establishment
- RFC 6347 - DTLS: Datagram Transport Layer Security
- RFC 8831 - WebRTC Data Channels
- RFC 3550 - RTP: Real-time Transport Protocol
Documentation
- API Documentation - Complete API reference
- Examples - Working code examples
- Sans-I/O Pattern - Detailed explanation of the sans-I/O design
- WebRTC for the Curious - Comprehensive WebRTC guide
Building and Testing
# Build the library
# Run tests
# Build documentation
# Run examples
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under either of:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Acknowledgments
Special thanks to all contributors and the WebRTC-rs community for making this project possible.