Expand description
A PeerDriver as a task of its own, driven through channels (feature peer): what an
application with its own threads or tasks uses instead of stepping the driver itself.
task splits a driver into three parts:
PeerTask, the loop:PeerTask::spawnruns it on the driver’s runtime, orPeerTask::runis awaited where the application wants it (Runtime::block_onon an OS thread of its own, as reachmydevice’s transport thread does);PeerHandle(cloneable), the commands:PeerHandle::callruns a closure on the driver inside the loop and hands back its result (signalling, data channels, media: the wholeRTCPeerConnectionAPI throughPeerDriver::pc_mut), andPeerHandle::shutdownends it in order (PeerDriver::shutdown). Each has a_blockingform for a thread outside any runtime;PeerEvents, what the loop reports: the connection’s events, the driver’s own, and what the connection reads (RTP, RTCP, data channel messages), in order (PeerTaskEvent), withrecv(async) andrecv_blocking.
The channels are async-channel’s: executor-agnostic, usable from tokio, smol, or a plain
thread. Events are unbounded (the loop never waits for the application); an application
that stops reading lets them pile up.
let (task, handle, events) = rtci_stream_driver::task::task(driver);
let _join = task.spawn();
let offer = handle.call(|d| {
let offer = d.pc_mut().create_offer(None)?;
let now = d.runtime().now();
d.pc_mut().set_local_description(now, offer.clone())?;
Ok::<_, rtci::shared::error::Error>(offer)
}).await??;
while let Some(event) = events.recv().await { /* PeerTaskEvent::Connection(...), ... */ }Structs§
- Peer
Events - What a driver run as a task reports, in order.
- Peer
Handle - The commands of a driver run as a task: cloneable, usable from any thread.
- Peer
Task - The loop of a driver run as a task (see the module documentation).
- Task
Ended - The loop ended: the command was not carried out.
Enums§
- Peer
Task Event - Something the loop reports (
PeerEvents).
Functions§
- task
- Splits
driverinto its loop, its commands and its events (see the module documentation). The loop waits at most 20 ms per step when nothing happens (PeerTask::with_step_wait).