Skip to main content

Module calls

Module calls 

Source
Expand description

One-to-one calls over a layout’s call path.

Calls publishes this node’s side of its calls at <root>/<its id>/call and offers it to nobody until ring adds a peer to its audience. A peer learns it is called when that path appears in its route table, and answers by ringing back and subscribing to the caller’s side. Two peers that ring each other at once resolve into one Call on each side.

A peer that was hung up on rings again only once it withdraws its side and offers it anew. Publishing the side again without a withdrawal in between is no new offer, since the route table lists the path throughout.

use iroh_live::{Node, calls::Calls, layout::LiveLayout};
use moq_net::broadcast;

let (calls, _side): (Calls, broadcast::Producer) = Calls::new(&node, &LiveLayout::default())?;

// Place a call: ring, wait for the peer to answer, subscribe.
let call = tokio::time::timeout(std::time::Duration::from_secs(30), calls.call(peer)).await??;

// Take the first call that rings.
let peer = calls.next_ring().await.ok_or("the call service ended")?;
let answered = calls.answer(peer).await?;
// Ends with the reason once the peer hangs up.
let reason = answered.ended().await;

Calls::call and Calls::answer are cancellation safe: dropping the future hangs up. Call::ended and Calls::closed lose nothing when dropped.

Structs§

Call
A call in progress.
Calls
The call service of a node.

Enums§

Error
An error from Calls.
HangUpReason
Why a call ended.

Constants§

CALL
The broadcast name of a call side, as irl call and the Android demo use it.