Skip to content
broadcast send sendReliable
to everyone in the room one peer one peer
delivery best effort: in lab tests 99.6–100% arrived best effort retransmitted until acknowledged
order none promised none promised in order, per peer
size ≤ 1,052 bytes ≤ 1,052 bytes ≤ 64 KiB
sealed no (signed) yes yes
use for frequent state everyone needs: presence, positions, live updates frequent state for one peer messages that must arrive: commands, chat, answers, a state snapshot for a late joiner
Two ways to send in the same room. Left, a broadcast from p1 reaches every peer hop by hop through other peers, and every member can read it. Right, a send from p1 to p6 is sealed end to end; p3 and p7 forward it but cannot read it. Left, broadcast(data): p1 sends to p2 and p3 (hop 1); p2 forwards to p4 and p5, p3 to p7 (hop 2); p4 forwards to p6 (hop 3). Every member can read a broadcast. Right, send(p6, data): the message goes p1 to p3 to p7 to p6, sealed with a lock; it is on its last hop. p3 and p7 forward it but cannot read or change it. broadcast(data) 1 1 2 2 2 3 p1 p2 p3 p4 p5 p6 p7 hop by hop, through peers; every member can read it send(p6, data) 1 2 3 p1 p2 p3 p4 p5 p6 p7 sealed end to end; p3, p7 forward, can't read
broadcast reaches every peer by hops and can be read by all, but is signed by its sender; send goes to one peer, sealed.

Every broadcast is signed by its sender and checked by every peer, so from is the real sender. It is not sealed: everyone in the room can read it. See security and privacy.

Most apps do best with small frequent deltas plus a way to repair gaps: number your messages, and when a receiver sees a gap, ask the sender with sendReliable or fetch it from your server. Sending the full state every few seconds also works.

Channels (0 to 13) are yours: a label that arrives in info.channel, so you can route traffic without parsing it first. The default is 0. A channel outside 0 to 13 throws a RangeError.

import { join } from 'jsflow-sdk';
const CHAT = 0, PRESENCE = 1;
const room = await join({ app: 'pk_…', room: 'team-7' });
room.on('message', (from, data, info) => {
if (info.channel === PRESENCE) applyPresence(from, data);
else if (info.channel === CHAT) addChatLine(from, data);
});
room.broadcast(new Uint8Array([1, 2, 3]), { channel: PRESENCE });
declare function applyPresence(from: number, data: Uint8Array): void;
declare function addChatLine(from: number, data: Uint8Array): void;

Anything over 1,052 bytes does not fit a send or broadcast (they throw a RangeError): use sendReliable, which takes up to 64 KiB (MAX_RELIABLE), and split anything larger into numbered sendReliable chunks. To get something to everyone reliably, send it to each peer, or let your server hold it.

The lab tests ran one sender at 10 messages a second of 150 bytes to 29 receivers, plus reliable messages, with room to spare. Batch what you can: ten 150-byte batches a second costs far less than a hundred tiny messages.

A broadcast sent before any peer is reachable reaches no one. Wait for 'connected', or send the late joiner what it needs when its peer event says it is up (from every peer for set-like state, from one for an ordered history: keeping state in sync). Use sendReliable for that: a broadcast sent the moment a peer comes up is best effort like any other, so send it again later if it matters.

Send errors are thrown synchronously, also by sendReliable (before it returns its promise): a message over its size limit or a channel outside 0 to 13 throws a RangeError, and any send once the room is left, superseded or evicted throws an Error. A sendReliable promise rejects only if the room stops before the message is queued.