Broadcast / Pub-Sub
Publish messages to named channels and deliver them to every online subscriber in real time. Ideal for announcements, live feeds, and collaborative features.
Core concepts
- Channel, A named topic string (e.g.
announcements,room:lobby). Channels are created implicitly on first subscribe. - Publisher, Any connected user can publish to a channel they're subscribed to.
- Subscriber, Users subscribe via a REST API call. Online subscribers receive broadcasts instantly over WebSocket.
- History, Messages are persisted with a 7-day TTL and retrievable via the REST API.
Quick start
// 1. Subscribe to a channel
await client.subscribeBroadcast('announcements');
// 2. Listen for incoming broadcasts
client.onBroadcast(msg => {
console.log(msg.channelId, msg.publisherId, msg.plaintext);
});
// 3. Publish a message
const { broadcastId } = await client.publishBroadcast(
'announcements',
'Version 2.0 is live!'
);
// 4. Unsubscribe when done
await client.unsubscribeBroadcast('announcements');BroadcastMessage object
| Field | Type | Description |
|---|---|---|
broadcastId | string | Unique broadcast message ID |
channelId | string | Channel the message was published to |
publisherId | string | User ID of the publisher |
timestamp | number | Unix timestamp (ms) |
plaintext | string | Message content |
sequenceNumber | number | Monotonically increasing channel sequence |
Quotas & limits
Each plan defines a maximum number of broadcast channels and broadcast messages per month. See the pricing page for details.