Skip to content

zaun_client::Client · Struct

pub struct Client { … }

A Zaun client. Clones share one SimpleX client and one driver; methods may be called from any thread, and block until the host answers or the timeout passes.

pub fn set_presence(&self, status: PresenceStatus, activity: Option<Activity>) -> Result<()>

Sets this member’s status and activity in every community: Online, Idle, Dnd or Invisible (everyone else sees Offline). The host shows at most one change per 3 s; the latest call wins and is sent again after each reconnection.

Error::Closed once the client stopped.

pub fn builder<impl AsRef<Path>>(dir: impl AsRef<Path>) -> ClientBuilder

A client whose SimpleX store and community state live in dir.

pub fn events(&self) -> impl Iterator<Item = Event> + Send + 'static

The events, blocking for the next one; ends when the client stops.

pub fn next_event(&self, timeout: Duration) -> Option<Event>

The next event, or None when none arrives within timeout or the client stopped.

pub fn simplex(&self) -> &Client

The SimpleX client underneath, for what Zaun does not wrap.

pub fn now_ms(&self) -> u64

Milliseconds since the epoch, from the same clock the sessions use.

pub fn communities(&self) -> Vec<Community>

The communities this client belongs to.

pub fn community(&self, id: CommunityId) -> Community

The community id, as an object that acts for itself.

pub fn join(&self, link: &str, display_name: &str) -> Result<Community>

Joins a community with an invitation link (zaun://join/…) under display_name, and returns it once the host admitted this member and its cache loaded (Event::Ready still comes). A member pending approval is admitted later, by a moderator.

Error::BadLink, a refusal (expired, used up, banned), or a timeout.

pub fn create_community(&self, host_address: &str, host_key: PublicKey, name: &str, display_name: &str) -> Result<Community>

Creates a community named name on the host at host_address whose public key is host_key (what zaun-host id prints), as its owner display_name. The community’s root key is made here and kept in <dir>/zaun/<community>/root.key (mode 0600): it is the community’s identity, so back it up. The host must allow the creation.

The host refused (creation closed) or did not answer.

pub fn create_community_with_root(&self, host_address: &str, host_key: PublicKey, name: &str, display_name: &str, root: SecretKey) -> Result<Community>

create_community with a root key made beforehand, so its community id (protocol::crypto::community_id) can be allow-listed on the host first.

As create_community.

pub fn command<B>(&self, community: CommunityId, channel: Option<ChannelId>, body: B) -> Result<<B as >::Response>

Sends any command and decodes its answer: the escape hatch for every command without a typed method. channel is the envelope’s channel, for channel commands.

Error::Refused with the host’s error, Error::UnknownCommunity, or a timeout.

pub fn command_named(&self, community: CommunityId, channel: Option<ChannelId>, name: &str, body: Value) -> Result<Value>

Sends the command called name ("channel.update", …) with its body as JSON (the specification’s field names) and answers the response body as JSON: command for a program that picks commands at run time. The body is checked as that command’s type before it is sent. session.hello and signals are not sent this way.

Error::Protocol for an unknown name or a body that does not fit it; then as command.

pub fn close(&self)

Stops the driver and the SimpleX client after saving state. Other clones stop too.

pub fn moderate_voice(&self, community: CommunityId, action: Moderate) -> Result<()>

Server-mutes, server-deafens, moves or disconnects a member in voice (voice.moderate; MUTE_MEMBERS, DEAFEN_MEMBERS, MOVE_MEMBERS).

The host refused (missing permission, rank) or did not answer.

Clone

Full rustdoc page