pub struct RealtimeClient { /* private fields */ }realtime and (crate features realtime or webhooks) only.Expand description
Async WebSocket client for the Radion realtime API.
Owns the connection lifecycle: it transparently reconnects with exponential
backoff after unexpected drops, restores subscriptions on reconnect, and
fans inbound channel frames out to events and
per-subscription streams.
Usually reached as Radion::realtime, but can be
constructed standalone with RealtimeClient::new.
Implementations§
Source§impl RealtimeClient
impl RealtimeClient
Sourcepub fn new(options: RealtimeOptions) -> Self
pub fn new(options: RealtimeOptions) -> Self
Construct a standalone realtime client.
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Open the connection.
Resolves once the socket is established. Calling it again after a successful connect is a no-op.
§Errors
Returns an error if the first connection attempt fails.
Sourcepub async fn subscribe(
&self,
subscription: Subscription,
) -> Result<ChannelEventStream>
pub async fn subscribe( &self, subscription: Subscription, ) -> Result<ChannelEventStream>
Subscribe to a channel, returning a stream of its events.
The subscription is resent automatically after a reconnect. The returned
stream yields only events for this subscription’s id; use
events for the firehose across all subscriptions.
§Errors
Returns RadionError::Connection if the subscription is missing a
filter its channel requires, or if the client has been closed.
Sourcepub async fn unsubscribe(&self, id: impl Into<String>) -> Result<()>
pub async fn unsubscribe(&self, id: impl Into<String>) -> Result<()>
Unsubscribe by subscription id.
§Errors
Returns RadionError::Connection if the client has been closed.
Sourcepub fn events(&self) -> ChannelEventStream
pub fn events(&self) -> ChannelEventStream
Stream of every channel event across all subscriptions (the firehose).
Sourcepub fn lifecycle(&self) -> LifecycleStream
pub fn lifecycle(&self) -> LifecycleStream
Stream of connection lifecycle events.