Real-time Updates
Cocobase provides real-time features through the db.realtime namespace. All connections use automatic reconnection with exponential backoff built in.Collection Watcher
Watch a collection for live document changes.Basic Usage
Watch with Filters
Project Broadcast
Send and receive messages across all connected clients.Room Chat
Create or join rooms for isolated real-time communication.List Rooms
Multiplayer Games
For multiplayer games use db.realtime.game() which uses the GameClient. See the Multiplayer section for full docs.Auto-Reconnection
All real-time connections automatically reconnect if dropped, using exponential backoff from 1 second up to 30 seconds maximum. No configuration needed.CollectionWatcher API Reference
| Method | Description |
|---|---|
| connect() | Start watching the collection |
| disconnect() | Stop watching |
| onConnected(cb) | Called when connection established |
| onCreate(cb) | Called when document is created |
| onUpdate(cb) | Called when document is updated |
| onDelete(cb) | Called when document is deleted |
| onError(cb) | Called on connection error |
ProjectBroadcast API Reference
| Method | Description |
|---|---|
| connect() | Connect to broadcast channel |
| disconnect() | Disconnect |
| send(data) | Send message to all clients |
| onMessage(cb) | Called when message received |
RoomChat API Reference
| Method | Description |
|---|---|
| create(roomTitle?) | Create a new room |
| join() | Join existing room |
| leave() | Leave the room |
| sendMessage(content) | Send a message |
| on(event, cb) | Listen to room events |
Best Practices
- Always set up event handlers before calling connect()
- Always call disconnect() or leave() when done
- Use filters in CollectionWatcher to reduce events
- Use RoomChat for isolated group communication
- Use ProjectBroadcast for project-wide announcements
