useceleris_client/lib.rs
1//! The Celeris realtime client.
2//!
3//! One [`Channel`] is one WebSocket connection; its segments share that
4//! connection. Credentials come from your own server through a
5//! [`CredentialProvider`], fresh for every connection attempt.
6//!
7//! ```no_run
8//! use useceleris_client::{Client, ClientOptions, CredentialProvider, Credentials, read_text, text_payload};
9//!
10//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
11//! let provider = CredentialProvider::new(|request| async move {
12//! // Ask your own server to sign credentials for request.channel_reference.
13//! # let _ = request;
14//! Ok(Credentials { payload: String::new(), signature: String::new() })
15//! });
16//!
17//! let client = Client::new(ClientOptions::new(provider))?;
18//! let channel = client.channel("room-1")?;
19//! let chat = channel.segment("chat")?;
20//!
21//! chat.on_message(|payload, metadata| {
22//! println!("{}: {:?}", metadata.token_reference, read_text(payload));
23//! });
24//!
25//! let _subscription = chat.subscribe()?;
26//! channel.connect().await?;
27//! chat.publish(text_payload("hello")).await?;
28//! channel.close().await;
29//! # Ok(())
30//! # }
31//! ```
32
33mod channel;
34mod client;
35mod command_queue;
36mod connection;
37mod connection_url;
38mod constants;
39mod credentials;
40mod decode;
41mod encode;
42mod errors;
43mod events;
44mod heartbeat;
45mod identifiers;
46mod messages;
47mod ordered_map;
48mod payload;
49mod random;
50mod reconnect;
51mod routing;
52mod segment;
53mod values;
54
55#[cfg(test)]
56mod tests;
57
58/// Compiles every code block of the README, so it cannot drift from the API.
59#[doc = include_str!("../README.md")]
60#[cfg(doctest)]
61pub struct ReadmeDoctests;
62
63pub use channel::Channel;
64pub use client::{Client, ClientOptions};
65pub use credentials::{
66 CredentialFuture, CredentialProvider, CredentialReason, CredentialRequest, Credentials,
67 ProviderError,
68};
69pub use errors::{CelerisError, ServerError, ServerErrorResource, ServerErrorType};
70pub use events::{ChannelEventHandler, Registration};
71pub use payload::{PayloadCodec, read_text, text_payload};
72pub use segment::{Segment, Subscription};
73pub use values::{
74 ChannelState, MessageMetadata, PresenceConnection, PresenceEvent, PresencePage, RecoveryEvent,
75 ServerNotice,
76};