pub struct ChannelConn<'a> { /* private fields */ }Expand description
A ChannelConn is a wrapper around a WebSocketConn that also
contains a ChannelClient
It that provides convenient access to functions from the ChannelClient
held in the WebSocketConn’s TypeSet, and dereferences to the
WebSocketConn for other functionality.
Implementations§
Source§impl ChannelConn<'_>
impl ChannelConn<'_>
Sourcepub fn client(&self) -> Option<&ChannelClient>
pub fn client(&self) -> Option<&ChannelClient>
Borrow the channel client
Sourcepub fn conn(&self) -> &WebSocketConn
pub fn conn(&self) -> &WebSocketConn
Borrow the websocket conn
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, response: &impl Serialize)
pub async fn reply_ok(&self, event: &ChannelEvent, response: &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, value: &impl Serialize)
pub async fn allow_join(&self, event: &ChannelEvent, value: &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.
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.
Methods from Deref<Target = WebSocketConn>§
Sourcepub async fn send_string(&mut self, string: String) -> Result<(), Error>
pub async fn send_string(&mut self, string: String) -> Result<(), Error>
send a Message::Text variant
Sourcepub async fn send_bytes(&mut self, bin: Vec<u8>) -> Result<(), Error>
pub async fn send_bytes(&mut self, bin: Vec<u8>) -> Result<(), Error>
send a Message::Binary variant
Sourcepub async fn send(&mut self, message: Message) -> Result<(), Error>
pub async fn send(&mut self, message: Message) -> Result<(), Error>
Sends a Message to the client
Sourcepub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>) -> &mut WebSocketConn
pub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>) -> &mut WebSocketConn
Sets the peer ip for this conn
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
retrieves the path part of the request url, up to and excluding any query component
Sourcepub fn querystring(&self) -> &str
pub fn querystring(&self) -> &str
Retrieves the query component of the path, excluding ?. Returns
an empty string if there is no query component.
Sourcepub fn state<T>(&self) -> Option<&T>
pub fn state<T>(&self) -> Option<&T>
retrieve state from the state set that has been accumulated by
trillium handlers run on the trillium::Conn before it
became a websocket. see trillium::Conn::state for more
information
Sourcepub fn state_mut<T>(&mut self) -> Option<&mut T>
pub fn state_mut<T>(&mut self) -> Option<&mut T>
retrieve a mutable borrow of the state from the state set
Sourcepub fn insert_state<T>(&mut self, state: T) -> Option<T>
pub fn insert_state<T>(&mut self, state: T) -> Option<T>
inserts new state
returns the previously set state of the same type, if any existed
Sourcepub fn state_entry<T>(&mut self) -> Entry<'_, T>
pub fn state_entry<T>(&mut self) -> Entry<'_, T>
Returns an Entry for the state typeset that can be used with functions like
Entry::or_insert, Entry::or_insert_with, Entry::and_modify, and others.
Sourcepub fn take_state<T>(&mut self) -> Option<T>
pub fn take_state<T>(&mut self) -> Option<T>
take some type T out of the state set that has been
accumulated by trillium handlers run on the trillium::Conn
before it became a websocket. see trillium::Conn::take_state
for more information