Expand description
The Celeris realtime client.
One Channel is one WebSocket connection; its segments share that
connection. Credentials come from your own server through a
CredentialProvider, fresh for every connection attempt.
use useceleris_client::{Client, ClientOptions, CredentialProvider, Credentials, read_text, text_payload};
let provider = CredentialProvider::new(|request| async move {
// Ask your own server to sign credentials for request.channel_reference.
Ok(Credentials { payload: String::new(), signature: String::new() })
});
let client = Client::new(ClientOptions::new(provider))?;
let channel = client.channel("room-1")?;
let chat = channel.segment("chat")?;
chat.on_message(|payload, metadata| {
println!("{}: {:?}", metadata.token_reference, read_text(payload));
});
let _subscription = chat.subscribe()?;
channel.connect().await?;
chat.publish(text_payload("hello")).await?;
channel.close().await;Structs§
- Channel
- One WebSocket connection. Every segment of the channel is multiplexed over
it; another
Channel, even for the same reference, is another connection (SEG-01). Obtain one withClient::channel. - Channel
Event Handler - Registers channel-wide listeners. Obtain one with
Channel::events. - Client
- Creates channels. It holds configuration only and does no network work. It is cheap to clone.
- Client
Options - Configures a
Client. Only the credential provider is required;Nonekeeps an option’s default (CONFIG-01). - Credential
Provider - Fetches credentials for one attempt, typically from your own credential endpoint.
- Credential
Request - Describes the attempt that credentials are requested for. Credentials are requested fresh for every attempt, reconnects included (D-001).
- Credentials
- Authorizes one connection attempt. Both values are opaque: the SDK never parses, re-serializes or generates them. A trusted server signs them; a client only passes them on.
- Message
Metadata - Describes a delivery, beside its payload (MSG-01).
- Payload
Codec - Gives a serializer of your choice, such as JSON, MessagePack or protobuf, one shape for both directions. The encoder’s and the decoder’s own errors are returned unchanged: they are yours, not this crate’s.
- Presence
Connection - One connection present in a segment. A token reference can hold several connections.
- Presence
Event - One connection that joined or left one segment (PRES-01).
- Presence
Page - One page of a segment’s presence, every figure exactly as the server sent
it. Past the last page
fromexceedstoandconnectionsis empty; that is not an error. - Recovery
Event - Reports a reconnect. Replay is a bounded window, not a durable log, so gaps and duplicates are always possible after one.
- Registration
- Removes one listener. Call
Registration::removeto remove it; calling it again does nothing. - Segment
- A handle for one segment of a channel. It holds only its id:
subscriptions, listeners and the connection belong to the channel, so any
number of handles for one segment share them. Obtain one with
Channel::segmentorChannel::default_segment. - Server
Error - An error frame from the server, every field exactly as sent (ERR-01). The server keeps the connection open after it sends one.
- Server
Notice - A raw notice from the server: greetings, subscription acknowledgements and refusals, as human-readable prose. It names no segment and no command, so nothing may gate on its content.
- Subscription
- One registered interest. Cancel it when done; dropping it keeps the interest.
Enums§
- Celeris
Error - A failure the SDK detected, or an error frame the server sent.
- Channel
State - Where a channel is in its lifecycle.
- Credential
Reason - Why credentials are requested.
- Server
Error Resource - What an error frame’s resource carries: whatever its type and sub type define, such as the segment that a denial refers to.
- Server
Error Type - The kind of an error frame that the server sent. The set stays open: a type
that a newer server adds still reaches the caller as
ServerErrorType::Other(ERR-01).
Functions§
- read_
text - Decodes a UTF-8 payload. It fails with
CelerisError::Configurationwhen the payload is not valid UTF-8. - text_
payload - Encodes text as UTF-8.
Type Aliases§
- Credential
Future - The future that a credential provider returns.
- Provider
Error - Any error that a credential provider returns. The SDK never inspects it or passes it on.