Skip to main content

Module websocket

Module websocket 

Source
Available on crate feature websocket only.
Expand description

ChatStreamEnable / ChatStreamDisable and the ephemeral events they turn on, as a jmap_websocket extension (draft-atwood-jmap-chat-wss-00 §Ephemeral Chat Events).

  • The deployment keeps one ChatEventHub and publishes every ChatTypingEvent and ChatPresenceEvent to it, one per recipient account (the event’s accountId).
  • For each WebSocket connection it builds a ChatStreamHandler with the connection’s caller and accounts, and registers it with Connection::with_extension next to advertising urn:ietf:params:jmap:chat:websocket.

The handler keeps the connection’s EphemeralSubscription. For each published event it checks, at delivery time, the subscription’s chatIds / contactIds scope, should_deliver_typing or project_presence, and the draft’s rate limits (ChatStreamLimits), then queues the frame with ExtensionSender::try_send, which drops it if the client is too slow (“events above this rate MAY be silently dropped”).

Credential expiry is the deployment’s: “A server that does not close the connection when credentials expire SHOULD NOT deliver further ephemeral events on that connection” (§Authentication and Identity). The handler does not know when credentials expire; close the connection then.

use std::sync::Arc;
use jmap_chat_server::ChatBackend;
use jmap_chat_server::websocket::{ChatEventHub, ChatStreamHandler};
use jmap_types::Id;
use jmap_websocket::server::{Connection, DispatcherHandler};

/// Called once per accepted connection; `hub` is the server's.
fn wire<B: ChatBackend<CallerCtx = ()>>(
    backend: Arc<B>,
    hub: &ChatEventHub,
    connection: Connection<DispatcherHandler<()>>,
) -> Connection<DispatcherHandler<()>> {
    let chat = ChatStreamHandler::new(backend, (), [Id::from("acct-owner")], hub);
    connection.with_extension(chat)
}

Structs§

ChatEventHub
The server-wide source of ephemeral Chat events: the deployment publishes each event here once, and every connection’s ChatStreamHandler decides whether its client receives it.
ChatStreamHandler
The ChatStreamEnable / ChatStreamDisable handler of one WebSocket connection; see the module docs.
ChatStreamLimits
The outbound rate limits a ChatStreamHandler applies, per connection.