pub struct ChannelContext {
pub identifier: String,
/* private fields */
}Expand description
Per-subscription context handed to a Channel’s lifecycle callbacks. It
carries the ActionCable identifier, an outbound sink to this connection,
and the pub/sub backend, so a channel can transmit, stream_from, read
params, and stop_all_streams (Rails ActionCable::Channel).
Fields§
§identifier: StringThe raw ActionCable subscription identifier (a JSON string).
Implementations§
Source§impl ChannelContext
impl ChannelContext
Sourcepub fn for_test(
identifier: impl Into<String>,
) -> (Self, UnboundedReceiver<String>)
pub fn for_test( identifier: impl Into<String>, ) -> (Self, UnboundedReceiver<String>)
A context wired to a fresh channel and in-memory pub/sub, returning the
receiving end so tests can observe transmit/stream_from output.
Sourcepub fn params(&self) -> Value
pub fn params(&self) -> Value
The subscription params: the parsed ActionCable identifier JSON (e.g.
{ "channel": "ChatChannel", "room": "42" }), or Null if unparseable.
Sourcepub fn transmit(&self, message: Value)
pub fn transmit(&self, message: Value)
Send a message to just this connection (Rails transmit). Wrapped as an
ActionCable ServerMessage carrying this subscription’s identifier.
Sourcepub async fn stream_from(&self, stream: &str)
pub async fn stream_from(&self, stream: &str)
Subscribe this connection to stream: anything published to it (e.g. via
Cable::broadcast) is forwarded to the client (Rails stream_from).
Sourcepub async fn stop_all_streams(&self)
pub async fn stop_all_streams(&self)
Stop forwarding every stream this connection subscribed to (Rails
stop_all_streams).