pub struct Client {
inner: Arc<RwLock<ClientInner>>,
shutdown: CancellationToken,
run_active: Arc<AtomicBool>,
}Expand description
Centrifugo realtime client with auto-reconnect; clones share state.
Fields§
§inner: Arc<RwLock<ClientInner>>§shutdown: CancellationToken§run_active: Arc<AtomicBool>Implementations§
Source§impl Client
impl Client
Sourcepub async fn subscribe(
&self,
config: SubscriptionConfig,
) -> Result<Subscription, Error>
pub async fn subscribe( &self, config: SubscriptionConfig, ) -> Result<Subscription, Error>
Registers a subscription and starts it immediately when connected.
§Errors
Returns an error if the channel is already subscribed or the server rejects the subscribe command.
Sourcepub async fn unsubscribe(&self, channel: &str) -> Result<(), Error>
pub async fn unsubscribe(&self, channel: &str) -> Result<(), Error>
Removes the subscription for channel from the server and client.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn presence(&self, channel: &str) -> Result<PresenceResult, Error>
pub async fn presence(&self, channel: &str) -> Result<PresenceResult, Error>
Queries presence information for channel.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn presence_stats(
&self,
channel: &str,
) -> Result<PresenceStats, Error>
pub async fn presence_stats( &self, channel: &str, ) -> Result<PresenceStats, Error>
Queries aggregate presence statistics for channel.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn history(
&self,
channel: &str,
limit: i32,
since: Option<StreamPosition>,
reverse: bool,
) -> Result<HistoryResult, Error>
pub async fn history( &self, channel: &str, limit: i32, since: Option<StreamPosition>, reverse: bool, ) -> Result<HistoryResult, Error>
Queries publication history for channel.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn publish(&self, channel: &str, data: Vec<u8>) -> Result<(), Error>
pub async fn publish(&self, channel: &str, data: Vec<u8>) -> Result<(), Error>
Publishes data to channel.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn rpc(&self, method: &str, data: Vec<u8>) -> Result<RpcResult, Error>
pub async fn rpc(&self, method: &str, data: Vec<u8>) -> Result<RpcResult, Error>
Calls the named server RPC method.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn send(&self, data: Vec<u8>) -> Result<(), Error>
pub async fn send(&self, data: Vec<u8>) -> Result<(), Error>
Sends asynchronous data to the server without publishing it.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub async fn sub_refresh(
&self,
channel: &str,
token: &str,
) -> Result<SubRefreshResult, Error>
pub async fn sub_refresh( &self, channel: &str, token: &str, ) -> Result<SubRefreshResult, Error>
Refreshes the subscription token for channel.
§Errors
Returns an error if the client is disconnected or the command fails.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Stops the background connection loop and closes the active transport.
pub(super) async fn subscribe_internal( &self, channel: &str, ) -> Result<SubscribeResult, Error>
async fn send_extract<P, T>(
&self,
cmd: Command,
label: &'static str,
extract: impl FnOnce(Reply) -> Option<P>,
) -> Result<T, Error>where
P: Into<T>,
async fn send_void(&self, cmd: Command) -> Result<(), Error>
async fn send_command(&self, cmd: Command) -> Result<Reply, Error>
Source§impl Client
impl Client
pub(super) async fn handle_reply( &self, reply: Reply, transport: &mut Transport, ) -> Result<Option<DisconnectAdvice>, Error>
pub(super) async fn build_recovery_subs( &self, ) -> FastMap<String, SubscribeRequest>
pub(super) async fn process_server_subs( &self, subs: impl IntoIterator<Item = (String, SubscribeResult)>, )
pub(super) async fn resubscribe_all(&self)
async fn handle_push(&self, push: Push) -> Option<DisconnectAdvice>
async fn handle_push_publication(&self, channel: &str, pub_: Publication)
async fn handle_push_unsubscribe(&self, channel: &str, unsub: Unsubscribe)
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> Self
pub fn new(config: ClientConfig) -> Self
Creates a disconnected client with shared connection state.
Sourcepub async fn events(&self) -> Receiver<ClientEvent>
pub async fn events(&self) -> Receiver<ClientEvent>
Replaces the client event receiver and returns the new receiver; install before Self::connect.
Sourcepub async fn state(&self) -> ClientState
pub async fn state(&self) -> ClientState
Returns the current connection lifecycle state.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Returns whether the client completed the Centrifugo handshake.
Sourcepub fn connect(&self)
pub fn connect(&self)
Spawns a background task that maintains the connection with auto-reconnect.
Sourcepub async fn run(&self)
pub async fn run(&self)
Maintains the connection and reconnects until Self::disconnect is called.
async fn emit_client_event(&self, event: ClientEvent)
async fn emit_subscription_event(&self, channel: &str, event: SubscriptionEvent)
async fn connection_config(&self) -> Result<Option<ClientConfig>, Error>
async fn establish_connection( &self, config: &ClientConfig, ) -> Result<(Transport, ConnectResult), Error>
async fn connect_and_run(&self) -> Result<ConnectionExit, Error>
async fn begin_refresh( &self, transport: &mut Transport, ) -> Result<Option<PendingRefresh>, Error>
async fn finish_refresh( &self, refresh: PendingRefresh, reply: Reply, ) -> Result<Option<Instant>, Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more