pub struct Calls { /* private fields */ }Expand description
The call service of a node.
Cheap to clone. See the module for the protocol.
§Examples
use iroh_live::{calls::Calls, layout::LiveLayout};
use moq_net::broadcast;
let (calls, side): (Calls, broadcast::Producer) = Calls::new(&node, &LiveLayout::default())?;
let call = calls.call(peer).await?;
// Fill `side` with tracks and read the peer's side from the call.Implementations§
Source§impl Calls
impl Calls
Sourcepub fn new<B>(node: &Node, layout: &LiveLayout) -> Result<(Self, B), Error>
pub fn new<B>(node: &Node, layout: &LiveLayout) -> Result<(Self, B), Error>
Publishes this node’s call side at <root>/<its id>/call and starts the service.
Returns the service with the side, which is visible to nobody until a
peer is rung. One side serves every call in turn, so a camera and a
preview keep running between calls. B is built from the route
table’s broadcast::Producer before the path is announced: a
LocalBroadcast, or the producer itself.
For a LocalBroadcast, dropping the side ends every call and
closed resolves. A bare producer has to be closed by
the application.
Each node’s policy has to let the other publish at
<root>/<peer id>/call, as LiveLayout::policy does. Otherwise
call and answer fail with
NotGranted.
§Errors
Fails with Error::Node if the side is already published or B
cannot be built.
§Panics
Panics when called outside a Tokio runtime.
Sourcepub fn ring(&self, peer: EndpointId)
pub fn ring(&self, peer: EndpointId)
Rings peer: offers it this node’s side, and dials it if no session exists.
Non-blocking and idempotent. The peer sees the side appear in its route table.
§Panics
Panics when called outside a Tokio runtime.
Sourcepub async fn call(&self, peer: EndpointId) -> Result<Call, Error>
pub async fn call(&self, peer: EndpointId) -> Result<Call, Error>
Calls peer: rings it, waits until it answers, and subscribes to its side.
Waits as long as the peer takes to answer, so bound it with a timeout. Dropping the future hangs up.
§Errors
Fails with Error::AlreadyInCall if a call with peer exists,
Error::NotAnswered if the session ends first, and Error::Node
otherwise, holding NotGranted
if the session’s grant does not let the peer publish its side.
Sourcepub async fn answer(&self, peer: EndpointId) -> Result<Call, Error>
pub async fn answer(&self, peer: EndpointId) -> Result<Call, Error>
Answers the call of peer: rings it back, and subscribes to its side.
Dropping the future hangs up.
§Errors
Fails with Error::NotRinging if peer is not calling, and as
call otherwise.
Sourcepub fn ringing(&self) -> Direct<BTreeSet<EndpointId>>
pub fn ringing(&self) -> Direct<BTreeSet<EndpointId>>
Returns the peers that ring this node now, as they change.
These are the peers whose side is visible, in no call, and not hung up
on since they last offered their side. A peer leaves the set when it
withdraws its side before an answer, and when this node answers or
calls it. Call::ended reports how a call in progress ends.
Sourcepub fn ticket(&self) -> BroadcastTicket
pub fn ticket(&self) -> BroadcastTicket
Sourcepub async fn next_ring(&self) -> Option<EndpointId>
pub async fn next_ring(&self) -> Option<EndpointId>
Waits until a peer rings, and returns the first that does.
Returns a peer that rings already at once. Returns None once the
service ends. Cancellation safe.