Appearance
Realtime
Live state (playback preemption, chat, calls, live streams, listening sessions, notifications, studio progress, assistant replies) is pushed over Socket.IO v4. REST stays the source of truth; sockets carry commands that need an instant answer and events you'd otherwise poll for.
Namespaces
| Namespace | For | Reference |
|---|---|---|
/playback | Device lease, preemption, event ingest, queue updates | Playback |
/chat | Encrypted envelopes, receipts, typing, presence | Messaging |
/call | Ringing, accept and decline, participants, upgrades | Calls |
/live | Joining streams, chat, reactions, gifts, viewers | Live streaming |
/together | Session sync, shared queue, host controls | Listen together |
/notify | Inbox items and badge counts | Notifications |
/studio | Upload progress and live studio stats | Studio |
/assistant | Streamed assistant replies and proposed actions | AI assistant |
Nothing lives on the default namespace /; connecting to it is refused.
Connecting
Read the realtime host from realtime.url in GET /v1/client/config rather than hard-coding it, then append the namespace path. Sockets take a realtime token (audience plemuz-realtime), not the REST access token. Pass it in the handshake:
ts
import { io } from "socket.io-client";
const { data: config } = await (await fetch("https://api.plemuz.com/v1/client/config")).json();
const chat = io(`${config.realtime.url}/chat`, {
auth: { token: realtimeToken },
transports: ["websocket"],
});
chat.on("connect_error", (err) => {
// err.data?.code, such as "UNAUTHENTICATED"
});On connect, every socket joins the person's own room automatically. A namespace may join more rooms (for example the calls you're in); other rooms are joined with a command such as stream:join or studio:join, after the server checks you may be there.
Keeping the token fresh
The server disconnects a socket when its token expires. Renew it on the open connection, before expiry, with auth:refresh:
ts
chat.emit("auth:refresh", { token: newRealtimeToken }, (ack) => {
if (ack.ok) console.log("valid until", ack.data.expiresAt);
});The new token must belong to the same person; otherwise the answer is FORBIDDEN.
Naming
| Direction | Form | Examples |
|---|---|---|
| Client → server (commands) | resource:verb | lease:claim, message:send, stream:join |
| Server → client (facts) | resource:verbed | playback:preempted, chat:sent, badge:updated |
Commands ask for something and always get an acknowledgement. Server events state what already happened, in the past tense, and are never acknowledged.
Acknowledgements
Every command takes a callback and gets exactly one acknowledgement in this shape:
ts
type Ack<T> =
| { ok: true; data: T }
| {
ok: false;
error: {
code: string; // Same codes as REST, see Errors
message: string; // The safe-to-show title
retryable: boolean;
actions?: NextAction[];
};
};ts
playback.emit("lease:claim", { deviceId }, (ack) => {
if (!ack.ok) return handle(ack.error);
start(ack.data.fencingToken);
});An unknown event is acknowledged with NOT_FOUND, a malformed payload with VALIDATION_FAILED, and too many commands with RATE_LIMITED.
Limits
- Payloads up to 1 MB.
- 60 commands per 10 seconds per socket and event by default; some namespaces set their own (see Rate limits).
- Origins are checked on upgrade for browsers; native apps send no origin.
Reconnecting
Socket.IO reconnects for you. After a reconnect, refetch state over REST (for example the queue version or the unread count) and rejoin rooms you joined by command; events sent while you were away aren't replayed.