Struct trillium_channels::ChannelConn
source · 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 StateSet, 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 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>§
pub 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
pub 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
pub fn stopper(&self) -> Stopper
pub fn stopper(&self) -> Stopper
retrieve a clone of the server’s [Stopper
]
pub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>)
pub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>)
Sets the peer ip for this conn
pub fn path(&self) -> &str
pub fn path(&self) -> &str
retrieves the path part of the request url, up to and excluding any query component
pub 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.
pub fn state<T>(&self) -> Option<&T>where
T: 'static,
pub fn state<T>(&self) -> Option<&T>where
T: 'static,
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
pub fn state_mut<T>(&mut self) -> Option<&mut T>where
T: 'static,
pub fn state_mut<T>(&mut self) -> Option<&mut T>where
T: 'static,
retrieve a mutable borrow of the state from the state set
pub fn set_state<T>(&mut self, state: T)
👎Deprecated: use WebsocketConn::insert_state
pub fn set_state<T>(&mut self, state: T)
see [insert_state
]
pub 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
pub fn take_state<T>(&mut self) -> Option<T>where
T: 'static,
pub fn take_state<T>(&mut self) -> Option<T>where
T: 'static,
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
pub fn take_inbound_stream(
&mut self,
) -> Option<impl Stream<Item = Result<Message, Error>>>
pub fn take_inbound_stream( &mut self, ) -> Option<impl Stream<Item = Result<Message, Error>>>
take the inbound Message stream from this conn
pub fn inbound_stream(
&mut self,
) -> Option<impl Stream<Item = Result<Message, Error>>>
pub fn inbound_stream( &mut self, ) -> Option<impl Stream<Item = Result<Message, Error>>>
borrow the inbound Message stream from this conn