Skip to main content

Crate useceleris_client

Crate useceleris_client 

Source
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 with Client::channel.
ChannelEventHandler
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.
ClientOptions
Configures a Client. Only the credential provider is required; None keeps an option’s default (CONFIG-01).
CredentialProvider
Fetches credentials for one attempt, typically from your own credential endpoint.
CredentialRequest
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.
MessageMetadata
Describes a delivery, beside its payload (MSG-01).
PayloadCodec
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.
PresenceConnection
One connection present in a segment. A token reference can hold several connections.
PresenceEvent
One connection that joined or left one segment (PRES-01).
PresencePage
One page of a segment’s presence, every figure exactly as the server sent it. Past the last page from exceeds to and connections is empty; that is not an error.
RecoveryEvent
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::remove to 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::segment or Channel::default_segment.
ServerError
An error frame from the server, every field exactly as sent (ERR-01). The server keeps the connection open after it sends one.
ServerNotice
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§

CelerisError
A failure the SDK detected, or an error frame the server sent.
ChannelState
Where a channel is in its lifecycle.
CredentialReason
Why credentials are requested.
ServerErrorResource
What an error frame’s resource carries: whatever its type and sub type define, such as the segment that a denial refers to.
ServerErrorType
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::Configuration when the payload is not valid UTF-8.
text_payload
Encodes text as UTF-8.

Type Aliases§

CredentialFuture
The future that a credential provider returns.
ProviderError
Any error that a credential provider returns. The SDK never inspects it or passes it on.