Skip to content

client.message

This content is for the 0.2.0-alpha.3 version. Switch to the latest version for up-to-date documentation.

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;
}
subscribe<T>(subject: string, handler: (e: MuhkooMessageEvent<T>) => void): MessageSubscription

Subscribe to a pub/sub subject, or to your own user:<id> to receive direct messages. Returns a handle with .unsubscribe().

publish<T>(subject: string, data: T): Promise<void>

Plaintext fan-out to everyone subscribed to subject.

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(): void

Closes every open connection (e.g. on logout).

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.