Struct trillium_channels::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
impl ChannelClient
sourcepub fn broadcast(&self, event: impl Into<ChannelEvent>)
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.
sourcepub async fn send_event(&self, event: impl Into<ChannelEvent>)
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.
sourcepub async fn reply_ok(&self, event: &ChannelEvent, payload: &impl Serialize)
pub async fn reply_ok(&self, event: &ChannelEvent, payload: &impl Serialize)
Send an ok reply in reference to the provided ChannelEvent with the provided response payload.
Note that this sets the event as "phx_reply"
and the payload as
{"status": "ok", "response": response }
, as well as setting the
reference field.
sourcepub async fn reply_error(&self, event: &ChannelEvent, error: &impl Serialize)
pub async fn reply_error(&self, event: &ChannelEvent, error: &impl Serialize)
Send an error reply in reference to the provided ChannelEvent with the provided response payload.
Note that this sets the event as "phx_error"
as well as setting
the reference field.
sourcepub async fn allow_join(&self, event: &ChannelEvent, payload: &impl Serialize)
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.
sourcepub async fn allow_leave(&self, event: &ChannelEvent, payload: &impl Serialize)
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.
sourcepub fn subscriptions(&self) -> &Subscriptions
pub fn subscriptions(&self) -> &Subscriptions
Borrow this client’s subscriptions
Trait Implementations§
source§impl Clone for ChannelClient
impl Clone for ChannelClient
source§fn clone(&self) -> ChannelClient
fn clone(&self) -> ChannelClient
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for ChannelClient
impl !RefUnwindSafe for ChannelClient
impl Send for ChannelClient
impl Sync for ChannelClient
impl Unpin for ChannelClient
impl !UnwindSafe for ChannelClient
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)