Publishing
Your server sends events to channels with its secret. Browsers can't publish: they send client events to each other at most.
- Node
- PHP
- Python
await realtime.publish( 'private-orders-42', 'updated', { status: 'paid' } );
$realtime->publish( 'private-orders-42', 'updated', [ 'status' => 'paid' ] );
// Laravel: an event that implements ShouldBroadcast, on PrivateChannel( 'orders.42' )
broadcast( new OrderPaid( $order ) )->toOthers();
realtime.publish("private-orders-42", "updated", {"status": "paid"})
await realtime.apublish("private-orders-42", "updated", {"status": "paid"}) # from async code: FastAPI, Starlette, Django's async views
| Argument | |
|---|---|
channels | one name, or up to 100 |
event | any name but realtime:… |
data | anything JSON takes, up to 10 KB |
except (Python except_tab) | a tab (the browser's rt.tab, sent with the request that caused it), which doesn't get it back. Laravel's toOthers() takes it from the request's X-Socket-ID header |
seal | false sends a private or presence channel's data in plain |
- Sealed by default: a private or presence channel's data goes sealed with its key, a copy each. Public channels' data goes in plain, together.
- A refusal throws a
RealtimeErrorwith the server'scodeand HTTPstatus(errors); Laravel's broadcasting throws aBroadcastException. Publish after your own work is saved: a failed publish is a missed live update, not a lost change.
Several events at once, and what a channel holds now:
- Node
- PHP
- Python
await realtime.publishBatch( [
{ channels: 'private-orders-42', event: 'updated', data: { status: 'paid' } },
{ channels: 'orders', event: 'count', data: { open: 7 } },
] ); // 10 events a request
const info = await realtime.channelInfo( 'presence-room-7' ); // { subscriptions, members: { count, list } }
$realtime->publishBatch( [
[ 'channels' => 'private-orders-42', 'event' => 'updated', 'data' => [ 'status' => 'paid' ] ],
[ 'channels' => 'orders', 'event' => 'count', 'data' => [ 'open' => 7 ] ],
] ); // 10 events a request
$info = $realtime->channelInfo( 'presence-room-7' ); // [ 'subscriptions' => …, 'members' => [ 'count' => …, 'list' => … ] ]
realtime.publish_batch([
{"channels": "private-orders-42", "event": "updated", "data": {"status": "paid"}},
{"channels": "orders", "event": "count", "data": {"open": 7}},
]) # 10 events a request
info = realtime.channel_info("presence-room-7") # {"subscriptions": …, "members": {"count": …, "list": …}}