client.message
See the Messaging guide for usage. All methods require a configured app key (websockets are ticket-authorized).
interface MuhkooMessageEvent<T = unknown> { subject: string; from: string; data: T;}
interface MessageSubscription { subject: string; unsubscribe(): void;}Methods
Section titled “Methods”subscribe(subject, handler)
Section titled “subscribe(subject, handler)”subscribe<T>(subject: string, handler: (e: MuhkooMessageEvent<T>) => void): MessageSubscriptionSubscribe to a pub/sub subject, or to your own user:<id> to receive direct
messages. Returns a handle with .unsubscribe().
publish(subject, data)
Section titled “publish(subject, data)”publish<T>(subject: string, data: T): Promise<void>Plaintext fan-out to everyone subscribed to subject.
send(target, payload)
Section titled “send(target, payload)”send<T>(target: string, payload: T): Promise<void>End-to-end-encrypted direct message. target must be user:<id>; throws
otherwise. Delivered in the recipient’s inbox space — they must be subscribed
and online.
disconnect()
Section titled “disconnect()”disconnect(): voidCloses every open connection (e.g. on logout).
A room is a shared space: group end-to-end-encrypted messaging plus room-scoped file storage.
const roomId = await client.message.createRoom(); // mint a private room idconst room = client.message.room(roomId); // open a handlecreateRoom() mints the id server-side, and that is not incidental: the id
is a 64-hex string embedding the space Durable Object’s class hash, which the
accelerator validates on every later request. A client-generated id is rejected.
room(id) opens a handle without connecting — the websocket is not opened until
you actually use it, so constructing handles is cheap.
For group channels with names, roles and invite links, prefer
client.space.
Group channels
Section titled “Group channels”For group messaging with persisted history and space-scoped file sharing,
use client.space channels (createChannel /
joinChannel), which add a name registry, history, and keeper-admitted
membership.