Rust Libraries
The Rust implementation provides the reference implementation of the MoQ protocol, along with server-side tools and native applications.
Core Libraries
moq-lite
The core pub/sub transport protocol implementing the moq-lite specification.
Features:
- Broadcasts, tracks, groups, and frames
- Built-in concurrency and deduplication
- QUIC stream management
- Prioritization and backpressure
hang
Media-specific encoding/streaming library built on top of moq-lite.
Features:
- Catalog for track discovery
- Container format (timestamp + codec bitstream)
- Support for H.264/265, VP8/9, AV1, AAC, Opus
- CMAF/fMP4 import
Server Tools
moq-relay
A stateless relay server that routes broadcasts between publishers and subscribers.
Features:
- Fan-out to multiple subscribers
- Cross-region clustering
- JWT-based authentication
- HTTP debugging endpoints
moq-token
JWT authentication library and CLI tool for generating tokens.
Features:
- HMAC and RSA/ECDSA signing
- Path-based authorization
- Token generation and verification
- Available as library and CLI
Utilities
moq-native
Opinionated helpers to configure a Quinn QUIC endpoint.
Features:
- TLS certificate management
- QUIC transport configuration
- Connection setup helpers
moq-clock
Timing and clock utilities for synchronization.
libmoq
C bindings for moq-lite via FFI.
Use cases:
- Integrate with C/C++ applications
- Bindings for other languages
- Legacy system integration
CLI Tools
hang-cli
Command-line tool for media operations (binary name: hang).
Features:
- Publish video from files or FFmpeg
- Test and development
- Media server deployments
Installation:
cargo install hang-cliUsage:
# Publish a video file
hang publish video.mp4
# Publish from FFmpeg
ffmpeg -i input.mp4 -f mpegts - | hang publish -moq-token-cli
Command-line tool for JWT token management (binary name: moq-token).
Installation:
cargo install moq-token-cliUsage:
# Generate a key
moq-token --key root.jwk generate
# Sign a token
moq-token --key root.jwk sign \
--root "rooms/123" \
--publish "alice" \
--expires 1735689600See Authentication guide for details.
Installation
From crates.io
Add to your Cargo.toml:
[dependencies]
moq-lite = "0.1"
hang = "0.1"From Source
git clone https://github.com/moq-dev/moq
cd moq/rs
cargo build --releaseUsing Nix
# Build moq-relay
nix build github:moq-dev/moq#moq-relay
# Build hang-cli
nix build github:moq-dev/moq#hang-cliQuick Start
Publishing (Rust)
use moq_lite::*;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to relay
let connection = Connection::connect("https://relay.example.com/demo").await?;
// Create a broadcast
let mut broadcast = BroadcastProducer::new("my-broadcast");
// Create a track
let mut track = broadcast.create_track("chat");
// Publish a group with a frame
let mut group = track.append_group();
group.write(b"Hello, MoQ!")?;
group.close()?;
// Publish to connection
connection.publish(&mut broadcast).await?;
Ok(())
}Subscribing (Rust)
use moq_lite::*;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to relay
let connection = Connection::connect("https://relay.example.com/demo").await?;
// Subscribe to a broadcast
let broadcast = connection.consume("my-broadcast").await?;
// Subscribe to a track
let mut track = broadcast.subscribe("chat").await?;
// Read groups and frames
while let Some(group) = track.next_group().await? {
while let Some(frame) = group.read().await? {
println!("Received: {:?}", frame);
}
}
Ok(())
}API Documentation
Full API documentation is available on docs.rs:
Examples
The repository includes several examples:
- Chat track - Publishing and subscribing to text
- Clock track - Timestamp synchronization
- Video track - Publishing video frames
Next Steps
- Explore moq-lite - Core protocol
- Explore hang - Media library
- Deploy moq-relay - Relay server
- View code examples
- Read API reference