pub struct Client { /* private fields */ }Expand description
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.
Implementations§
Source§impl Client
impl Client
Sourcepub fn set_presence(
&self,
status: PresenceStatus,
activity: Option<Activity>,
) -> Result<()>
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
Error::Closed once the client stopped.
Source§impl Client
impl Client
Sourcepub fn builder(dir: impl AsRef<Path>) -> ClientBuilder
pub fn builder(dir: impl AsRef<Path>) -> ClientBuilder
A client whose SimpleX store and community state live in dir.
Sourcepub fn events(&self) -> impl Iterator<Item = Event> + Send + 'static
pub fn events(&self) -> impl Iterator<Item = Event> + Send + 'static
The events, blocking for the next one; ends when the client stops.
Sourcepub fn next_event(&self, timeout: Duration) -> Option<Event>
pub fn next_event(&self, timeout: Duration) -> Option<Event>
The next event, or None when none arrives within timeout or the client stopped.
Sourcepub fn now_ms(&self) -> u64
pub fn now_ms(&self) -> u64
Milliseconds since the epoch, from the same clock the sessions use.
Sourcepub fn communities(&self) -> Vec<Community>
pub fn communities(&self) -> Vec<Community>
The communities this client belongs to.
Sourcepub fn community(&self, id: CommunityId) -> Community
pub fn community(&self, id: CommunityId) -> Community
The community id, as an object that acts for itself.
Sourcepub fn join(&self, link: &str, display_name: &str) -> Result<Community>
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
Error::BadLink, a refusal (expired, used up, banned), or a timeout.
Sourcepub fn create_community(
&self,
host_address: &str,
host_key: PublicKey,
name: &str,
display_name: &str,
) -> Result<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
The host refused (creation closed) or did not answer.
Sourcepub fn create_community_with_root(
&self,
host_address: &str,
host_key: PublicKey,
name: &str,
display_name: &str,
root: SecretKey,
) -> Result<Community>
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
As create_community.
Sourcepub fn command<B>(
&self,
community: CommunityId,
channel: Option<ChannelId>,
body: B,
) -> Result<B::Response>where
B: Body + Send + 'static,
B::Response: DeserializeOwned,
pub fn command<B>(
&self,
community: CommunityId,
channel: Option<ChannelId>,
body: B,
) -> Result<B::Response>where
B: Body + Send + 'static,
B::Response: DeserializeOwned,
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
Error::Refused with the host’s error, Error::UnknownCommunity, or a timeout.
Sourcepub fn command_named(
&self,
community: CommunityId,
channel: Option<ChannelId>,
name: &str,
body: Value,
) -> Result<Value>
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
Error::Protocol for an unknown name or a body that does not fit it; then as
command.
Source§impl Client
impl Client
Sourcepub fn moderate_voice(
&self,
community: CommunityId,
action: Moderate,
) -> Result<()>
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
The host refused (missing permission, rank) or did not answer.