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 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.
Sourcepub async fn reject(&self, event: &ChannelEvent, error: &impl Serialize)
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.
Sourcepub async fn mark_channel_errored(
&self,
event: &ChannelEvent,
error: &impl Serialize,
)
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.
Sourcepub 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
pub async fn reply_error(&self, event: &ChannelEvent, error: &impl Serialize)
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.
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