| Crates.io | saorsa-webrtc |
| lib.rs | saorsa-webrtc |
| version | 0.1.2 |
| created_at | 2025-10-16 07:54:35.840393+00 |
| updated_at | 2025-10-16 10:14:51.41468+00 |
| description | WebRTC implementation over ant-quic transport with DHT-based signaling |
| homepage | https://github.com/dirvine/saorsa-webrtc |
| repository | https://github.com/dirvine/saorsa-webrtc |
| max_upload_size | |
| id | 1885596 |
| size | 319,310 |
A WebRTC implementation over ant-quic transport with pluggable signaling mechanisms.
saorsa-webrtc provides a WebRTC implementation that uses ant-quic as the transport layer instead of traditional ICE/STUN/TURN protocols. This approach leverages QUIC's built-in NAT traversal, post-quantum cryptography, and multiplexing capabilities while maintaining WebRTC's media streaming features.
SignalingTransport traitPeerIdentity traitSignaling Layer (signaling.rs)
SignalingTransport trait for pluggable transport mechanismsMedia Management (media.rs)
Call Management (call.rs)
Transport Integration (transport.rs)
QUIC Bridge (quic_bridge.rs, quic_streams.rs)
The library is generic over two key traits:
pub trait PeerIdentity:
Clone + Debug + Display + Serialize + Deserialize + Send + Sync + 'static
{
fn to_string_repr(&self) -> String;
fn from_string_repr(s: &str) -> anyhow::Result<Self>;
fn unique_id(&self) -> String;
}
pub trait SignalingTransport: Send + Sync {
type PeerId: Clone + Send + Sync + Debug + Display + FromStr;
type Error: std::error::Error + Send + Sync + 'static;
async fn send_message(&self, peer: &Self::PeerId, message: SignalingMessage)
-> Result<(), Self::Error>;
async fn receive_message(&self)
-> Result<(Self::PeerId, SignalingMessage), Self::Error>;
async fn discover_peer_endpoint(&self, peer: &Self::PeerId)
-> Result<Option<SocketAddr>, Self::Error>;
}
This allows the library to work with different peer identity schemes (e.g., FourWordAddress in saorsa-core, gossip IDs in communitas) and different signaling mechanisms (DHT, gossip, centralized servers).
use saorsa_webrtc::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create WebRTC service with string-based peer identity
let service = WebRtcService::<PeerIdentityString, AntQuicTransport>::builder()
.with_identity("alice-bob-charlie-david")
.build()
.await?;
// Start the service
service.start().await?;
// Subscribe to WebRTC events
let mut events = service.subscribe_events();
// Initiate a video call
let call_id = service.initiate_call(
"eve-frank-grace-henry",
MediaConstraints::video_call()
).await?;
// Handle events
while let Ok(event) = events.recv().await {
match event {
WebRtcEvent::IncomingCall { from, call_id, constraints } => {
println!("Incoming call from {}: {:?}", from, constraints);
service.accept_call(&call_id).await?;
}
WebRtcEvent::CallConnected { call_id } => {
println!("Call {} connected", call_id);
}
WebRtcEvent::CallEnded { call_id, reason } => {
println!("Call {} ended: {:?}", call_id, reason);
break;
}
_ => {}
}
}
Ok(())
}
use saorsa_webrtc::prelude::*;
use saorsa_core::FourWordAddress;
// Use DHT-based signaling transport
let service = WebRtcService::<FourWordAddress, DhtSignalingTransport>::builder()
.with_identity(my_four_word_address)
.with_transport(dht_transport)
.build()
.await?;
use saorsa_webrtc::prelude::*;
use communitas::GossipIdentity;
// Use gossip-based rendezvous signaling
let service = WebRtcService::<GossipIdentity, GossipSignalingTransport>::builder()
.with_identity(my_gossip_identity)
.with_transport(gossip_transport)
.build()
.await?;
Implement the SignalingTransport trait for your own signaling mechanism:
use saorsa_webrtc::{SignalingTransport, SignalingMessage};
use async_trait::async_trait;
pub struct MyCustomTransport {
// Your transport state
}
#[async_trait]
impl SignalingTransport for MyCustomTransport {
type PeerId = String;
type Error = MyError;
async fn send_message(&self, peer: &String, message: SignalingMessage)
-> Result<(), MyError>
{
// Your implementation
Ok(())
}
async fn receive_message(&self)
-> Result<(String, SignalingMessage), MyError>
{
// Your implementation
todo!()
}
async fn discover_peer_endpoint(&self, peer: &String)
-> Result<Option<SocketAddr>, MyError>
{
// Your implementation
Ok(None)
}
}
This library depends on:
../ant-quic)Traditional WebRTC uses:
Saorsa WebRTC uses:
This approach provides:
src/
├── lib.rs # Public API and module exports
├── identity.rs # PeerIdentity trait and implementations
├── types.rs # Core data structures (CallId, MediaConstraints, etc.)
├── signaling.rs # Signaling protocol and transport abstraction
├── media.rs # Media stream management
├── call.rs # Call state management
├── service.rs # WebRtcService and builder
├── transport.rs # ant-quic transport adapter
├── quic_bridge.rs # WebRTC to QUIC bridge
└── quic_streams.rs # QUIC media stream management with QoS
Current Status: Core structure implemented, stub implementations in place.
Completed:
PeerIdentity and SignalingTransport traitsIn Progress:
Planned:
This is part of the Saorsa project ecosystem. For contribution guidelines, see the main Saorsa project.
[License information to be added]
Part of the Saorsa Labs ecosystem.