Dart SDK - Realtime#
Subscribe to table changes with two transports:
centrifugo- WebSocket to the realtime server. One persistent connection, auto-reconnect with backoff. Recommended for scale.sse- Server-Sent Events stream over plain HTTP.auto(default) - WebSocket via Centrifugo.
Subscribe#
final sub = db.realtime.subscribe(
'messages',
(event) => print('${event.type}: ${event.record}'),
options: const SubscribeOptions(
events: ['INSERT', 'DELETE'], // optional filter
transport: RealtimeTransport.auto, // auto | centrifugo | sse
),
);
// Stop listening
sub.unsubscribe();
DARTevent is a RealtimeEvent:
| Field | Type |
|---|---|
id | String |
type | String - INSERT / UPDATE / DELETE |
table | String |
projectId | String |
record | Map<String, dynamic> |
oldRecord | Map<String, dynamic>? (UPDATE/DELETE) |
createdAt | String? |
How it works#
- The SDK calls
POST /projects/{id}/realtime/connect?table=...and receives a scoped token and channel. - It opens a Centrifugo WebSocket (
{url}/connection/websocket) and sends{"id":1,"connect":{"token":token}}. - The SSE transport reads
/projects/{id}/realtime/events?...directly. - Both transports auto-reconnect with exponential backoff (1s..30s).
Event payload#
{
"id": "uuid",
"type": "INSERT",
"table": "messages",
"project_id": "5c73dab0-...",
"record": { "id": "...", "message": "hello" },
"old_record": null,
"created_at": "2026-10-03T20:47:34Z"
}
JSONNext: Storage.