Skip to main content

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

Game Client

The GameClient supports WebSocket-based game rooms. Use db.realtime.game() to connect:

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

ProjectBroadcast API Reference

RoomChat API Reference

Best Practices

  1. Always set up event handlers before calling connect()
  2. Always call disconnect() or leave() when done
  3. Use filters in CollectionWatcher to reduce events
  4. Use RoomChat for isolated group communication
  5. Use ProjectBroadcast for project-wide announcements