Realtime
Subscribe to real-time data changes using WebSockets.
Subscribe to Collection
// Subscribe to all changes in a collection
const unsubscribe = client.collection('messages').onSnapshot((data) => {
console.log('Change event:', data);
// data.type: 'create', 'update', 'delete'
// data.data: the document
});
// Later: stop listening
unsubscribe();Transport Modes
Configure how real-time works:
const client = new BaasClient({
apiBase: 'https://api.novabaas.com',
projectId: 'your-project',
transport: 'auto' // 'auto', 'websocket', 'rest'
});
// 'auto' (default): Uses WebSocket, falls back to REST polling
// 'websocket': WebSocket only
// 'rest': REST with polling for real-timeAuto-Fallback
When WebSocket fails, the SDK automatically falls back to REST polling:
- 3 reconnection attempts with exponential backoff
- Falls back to polling every 5 seconds
- Transparent to your application code