Skip to content

Realtime

Use Realtime for transient coordination and refresh signals. PostgreSQL remains the durable source of truth.

js
const channel = opencloud.realtime.channel("work-items", {
  broadcast: { ack: true, self: true },
  reconnect: { initialDelayMs: 500, maxDelayMs: 10_000 },
});

channel.onStateChange((state) => {
  status.textContent = state;
});

channel.onBroadcast(({ event, payload }) => {
  if (event === "changed") void refreshFromDatabase(payload);
});

await channel.connect();

After a successful mutation:

js
await channel.broadcast("changed", {
  entity: "work-item",
  id,
});

The logical name must start with a lowercase letter and contain lowercase letters, numbers, or hyphens. The SDK adds the private app:<appId>:<logical-name> boundary.

Close the channel during teardown. Never put secrets or full records in broadcast payloads; send identifiers and reload through RLS.

Self-hosted infrastructure for agent-built applications.