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
ChatEventHuband publishes everyChatTypingEventandChatPresenceEventto it, one per recipient account (the event’saccountId). - For each WebSocket connection it builds a
ChatStreamHandlerwith the connection’s caller and accounts, and registers it withConnection::with_extensionnext to advertisingurn: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§
- Chat
Event Hub - The server-wide source of ephemeral Chat events: the deployment
publishes each event here once, and every connection’s
ChatStreamHandlerdecides whether its client receives it. - Chat
Stream Handler - The
ChatStreamEnable/ChatStreamDisablehandler of one WebSocket connection; see the module docs. - Chat
Stream Limits - The outbound rate limits a
ChatStreamHandlerapplies, per connection.