Expand description
Live audio and video over iroh.
A Node publishes and subscribes to broadcasts at paths, over a direct
session with a peer or an attached media relay. [node] re-exports
iroh-live-node, the layer under the facade, and moq_net the moq-net it
builds on. media and rooms gather the media and rooms crates, each behind
its feature.
The moq crates are pinned to a git rev of moq-dev/moq main, so this crate
is not on crates.io yet.
The node takes any path. iroh-live ships one convention,
layout::LiveLayout, which publishes a peer’s broadcasts at
<root>/<peer>/<name> (the root is live by default) and lets each peer
publish only under its own id. An application with its own scheme passes
its own paths and policy, see NodeConfig::with_policy.
A BroadcastTicket names a peer and the path it publishes at, whatever
the layout. Node::subscribe_ticket grants the ticket’s publisher that
one path while the subscription lives, so a viewer needs no layout.
This publishes a test pattern and plays someone else’s broadcast:
use iroh::protocol::Router;
use iroh_live::{
BroadcastTicket, EndpointConfig, Node,
layout::LiveLayout,
media::{
LocalBroadcast, PlayerConfig, SubscriptionExt, VideoEncoding, VideoRendition,
VideoSource, video,
},
};
let layout = LiveLayout::default();
let endpoint = EndpointConfig::from_env()?.bind().await?;
let node = Node::new(endpoint.clone(), layout.config());
// Accepts the peers that read the broadcast. Keep the router alive.
let router = node.mount(Router::builder(endpoint)).spawn();
// Created in the node's route table: peers read it without a copy.
let broadcast: LocalBroadcast = layout.publish(&node, "studio")?;
let source = VideoSource::test_pattern(
video::Size::new(1280, 720),
video::FrameRate::new(30, 1).expect("a valid rate"),
)?;
broadcast.set_video(
source,
VideoEncoding::ladder([VideoRendition::p360(), VideoRendition::p720()]),
)?;
println!("share {}", layout.ticket(node.id(), "studio")?);
let subscription = node.subscribe_ticket(&ticket).await?;
let player = subscription.remote_broadcast().play(PlayerConfig::default())?;
let mut frames = player.video_frames();
while let Some(frame) = frames.next().await {
// hand `frame` to a renderer
}
// Shuts the node down and every mounted service, then closes the endpoint.
router.shutdown().await?;EndpointConfig::apply composes with your own endpoint builder, and
calls::Calls places and answers one-to-one calls over a layout.
The main types:
Node: the node, mounted on the application’s router withNode::mount.layout::LiveLayout: the<root>/<peer>/<name>path convention.BroadcastTicket: a publisher’s endpoint id and the path of a broadcast.calls::Calls: one-to-one calls.RoomsNode: a node that serves live broadcasts and rooms, bound in one call.LocalBroadcast: a broadcast this node publishes, frommedia.RemoteBroadcast: a broadcast this node plays, frommedia.
The futures differ in what dropping them leaves behind:
| Future | Cancellation safe | Dropping it |
|---|---|---|
EndpointConfig::bind | yes | nothing is bound |
Node::subscribe, Node::subscribe_ticket | yes | abandons the wait, and a dial it started continues for other callers |
calls::Calls::call, calls::Calls::answer | yes | hangs up |
EndpointConfig::apply | yes | the builder is lost, nothing is bound |
Node::shutdown | no, idempotent | call again to finish |
Node::shutdown does not close the endpoint. Whoever binds it closes
it, directly or through Router::shutdown.
media, [node] and rooms list their own futures.
No public call takes a deadline. Bound a wait with tokio::time::timeout.
Each call returns the error of the crate that runs it: [node::Error] from
the node and the layout, EndpointError from EndpointConfig,
media::Error from sources, publishing and playback, rooms::Error from
rooms, and calls::Error from calls. Each one converts into Error, so
? works in a function that returns it.
Only crypto-aws-lc-rs is on by default. crypto-rind, crypto-ring and
crypto-aws-lc-rs pick the rustls backend that iroh and moq share, see
crypto_provider. With more than one on, ring wins over aws-lc-rs and
both over rind, so crypto-rind needs default features off. The default
moves to crypto-rind once rind releases per-path QUIC keys.
player builds the receive side of media, publisher the send side,
and media both. Device features turn on their side: capture, file
and rpicam imply publisher, playback, render and record imply
player. pipewire, pulseaudio and the hardware codecs apply to
whichever side is on; pipewire with publisher also builds device
capture.
full is the usual app set, and rooms re-exports iroh-live-rooms
and adds RoomsNode.
Without a side the crate is the node, the layout, calls and endpoint
setup.
Re-exports§
pub use iroh_live_node as node;pub use iroh_live_node::moq_net;pub use iroh_live_rooms as rooms;pub use moq_json as json;
Modules§
- calls
- One-to-one calls over a layout’s call path.
- layout
- The
<root>/<peer>/<name>path layout. - media
- Sources, broadcasts and players, with the codec stacks they sit on.
Structs§
- Broadcast
Ticket - A publisher’s endpoint id and the path of one of its broadcasts.
- Connect
Options - How to dial a peer with
Node::connect_with. - Endpoint
Config - An endpoint with
MoqPreset, a key and mDNS. - Grant
- What a session may subscribe to from this node, and publish into it.
- Minimal
Preset - An iroh preset that sets only the crypto provider.
- MoqPreset
- iroh’s N0 preset with BBR3 congestion control.
- Network
Path - One open network path of a
Session, as returned bySession::network_paths. - Network
Sample - One reading of the link a broadcast arrives over.
- Node
- A MoQ node on an iroh endpoint.
- Node
Config - The configuration of a
Node. - Publication
- A published broadcast.
- Relay
Config - How to attach to a media relay.
- Relay
Link - A media relay this node stays attached to.
- Rooms
Node - A node that serves both live broadcasts and rooms, with its router.
- Serving
Link - The link serving a subscription, and its latest reading.
- Session
- A direct session with a peer.
- Subscription
- A path resolved in a route table.
- Unpublish
OnDrop - A
Publicationthat is unpublished when this guard drops. - Value
Error - An error from a value track: a
moq_json::Errorthat?can convert. - Value
Reader - A reader of a latest-value JSON track that follows its
Subscription. - Value
Writer - Writes a latest-value JSON track, stamping each update with the time it is made.
Enums§
- Congestion
- A QUIC congestion controller.
- Endpoint
Error - An error from
EndpointConfig::from_envorEndpointConfig::bind. - Error
- An error from the node, the endpoint, rooms, calls, or the media.
- Link
Kind - What kind of link a session or a media relay attachment is.
- Mdns
- How an endpoint uses mDNS on the local network.
- Network
Path Kind - The kind of address a
NetworkPathgoes to. - Reach
- How
Node::subscribereaches a path the route table has no route to yet. - Relay
Status - The state of a relay link.
Functions§
- crypto_
provider - Returns the rustls crypto provider for iroh’s and moq’s TLS.
- load_
or_ create_ secret_ key - Loads the secret key stored at
path, or generates one and stores it there.
Type Aliases§
- Audience
- Who may see a publication.