Skip to main content

ChannelClient

Struct ChannelClient 

Source
pub struct ChannelClient { /* private fields */ }
Expand description

§Communicate with the connected client.

Note that although each client is unique and represents a specific websocket connection, the ChannelClient can be cloned and moved elsewhere if needed and any updates to the topic subscriptions will be kept synchronized across clones.

Implementations§

Source§

impl ChannelClient

Source

pub fn broadcast(&self, event: impl Into<ChannelEvent>)

Send a ChannelEvent to all connected clients. Note that these messages will only reach clients that subscribe to the event’s topic.

Source

pub async fn send_event(&self, event: impl Into<ChannelEvent>)

Send a ChannelEvent to this specific client. Note that this message will only be received if the client subscribes to the event’s topic.

Source

pub async fn reply_ok(&self, event: &ChannelEvent, payload: &impl Serialize)

Send a phx_reply with status "ok" and the provided response payload. The reply preserves the request’s references and does not require a topic subscription.

Source

pub async fn reject(&self, event: &ChannelEvent, error: &impl Serialize)

Reject a join or push with a phx_reply with status "error".

The reply preserves the request’s references and reaches the client even if it has not joined the topic. This does not change its subscriptions.

Source

pub async fn mark_channel_errored( &self, event: &ChannelEvent, error: &impl Serialize, )

Mark the client’s channel for this event’s topic as errored, by sending a phx_error.

The Phoenix JavaScript client treats this as a crashed channel and rejoins it. The event is only delivered if the client subscribes to the topic. To reject an individual join or push, use Self::reject instead.

Source

pub async fn reply_error(&self, event: &ChannelEvent, error: &impl Serialize)

👎Deprecated since 0.5.0:

to refuse a join or push, use reject; to put the client’s channel in an error state, use mark_channel_errored

Mark the client’s channel for this event’s topic as errored.

Source

pub async fn allow_join(&self, event: &ChannelEvent, payload: &impl Serialize)

Join a topic, sending an ok reply with the provided optional value. This sends an ok reply to the client as well as adding the topic to the client’s subscriptions.

Use &() as the payload if no payload is needed.

Source

pub async fn allow_leave(&self, event: &ChannelEvent, payload: &impl Serialize)

Leave a topic as requested by the provided channel event, including the optional payload. This sends an ok reply to the client as well as removing the channel from the client’s subscriptions.

Use &() as the payload if no payload is needed.

Source

pub fn subscriptions(&self) -> &Subscriptions

Borrow this client’s subscriptions

Trait Implementations§

Source§

impl Clone for ChannelClient

Source§

fn clone(&self) -> Self

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
Source§

impl Debug for ChannelClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.