Struct Client
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.
Methods
Section titled “Methods”set_presence
Section titled “set_presence”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.
Errors
Section titled “Errors”Error::Closed once the client stopped.
builder
Section titled “builder”pub fn builder<impl AsRef<Path>>(dir: impl AsRef<Path>) -> ClientBuilderA client whose SimpleX store and community state live in dir.
events
Section titled “events”pub fn events(&self) -> impl Iterator<Item = Event> + Send + 'staticThe events, blocking for the next one; ends when the client stops.
next_event
Section titled “next_event”pub fn next_event(&self, timeout: Duration) -> Option<Event>The next event, or None when none arrives within timeout or the client stopped.
simplex
Section titled “simplex”pub fn simplex(&self) -> &ClientThe SimpleX client underneath, for what Zaun does not wrap.
now_ms
Section titled “now_ms”pub fn now_ms(&self) -> u64Milliseconds since the epoch, from the same clock the sessions use.
communities
Section titled “communities”pub fn communities(&self) -> Vec<Community>The communities this client belongs to.
community
Section titled “community”pub fn community(&self, id: CommunityId) -> CommunityThe 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.
Errors
Section titled “Errors”Error::BadLink, a refusal (expired, used up, banned), or a timeout.
create_community
Section titled “create_community”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.
Errors
Section titled “Errors”The host refused (creation closed) or did not answer.
create_community_with_root
Section titled “create_community_with_root”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.
Errors
Section titled “Errors”As create_community.
command
Section titled “command”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.
Errors
Section titled “Errors”Error::Refused with the host’s error, Error::UnknownCommunity, or a timeout.
command_named
Section titled “command_named”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.
Errors
Section titled “Errors”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.
moderate_voice
Section titled “moderate_voice”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).
Errors
Section titled “Errors”The host refused (missing permission, rank) or did not answer.
Trait implementations
Section titled “Trait implementations”Clone