Skip to main content

Client

Struct Client 

Source
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

Source

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

Source

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

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

Source

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

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

Source

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

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

Source

pub fn simplex(&self) -> &Client

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

Source

pub fn now_ms(&self) -> u64

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

Source

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

The communities this client belongs to.

Source

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

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

pub fn close(&self)

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

Source§

impl Client

Source

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.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more