Realtime
Push changes to connected clients instead of polling: one WebSocket stream per channel, authenticated by the user session.
Follow database changes
A “postgres_changes” subscription receives inserts, updates and deletes for a table. Filter on the schema and table, and on a specific event type when your screen does not need the rest.
JavaScript
import { createClient } from '@kuunda/kuunda-js';
const kuunda = createClient(process.env.NEXT_PUBLIC_KUUNDA_URL!, process.env.NEXT_PUBLIC_KUUNDA_ANON_KEY!);
const canal = kuunda
.channel('realtime:mes_taches')
.on('postgres_changes', { event: '*', schema: 'public', table: 'mes_taches' }, (payload) => {
// payload.eventType vaut INSERT, UPDATE ou DELETE
console.log(payload.eventType, payload.new ?? payload.old);
})
.on('broadcast', { event: 'presence' }, (message) => {
console.log(message.payload);
});
await canal.subscribe();Subscribe to the channel once and close it when the screen unmounts.
Broadcast your own messages
A “broadcast” subscription carries your application events — presence, progress, notifications — on a named channel. It is the right tool for what does not come from the database.
Security
The channel applies the same policies as everything else: a client only receives the rows it is allowed to read. The connection authenticates with the user session, or with the anonymous key for public access.
- Never broadcast sensitive data on a public channel: every subscribed client receives it.
- The service key is server-only, Realtime included.
Availability
If the service does not answer, subscriptions fail and the console reports it: plan a fallback (periodic refresh) for critical screens. The sandbox does not provide Realtime.