Real-time Collaborative Cursors (Raw WebSocket)

Real-time Collaborative Cursors (Raw WebSocket)

Demonstrates real-time cursor tracking and collaborative canvas using raw WebSocket handlers instead of RivetKit's higher-level WebSocket abstraction.

Features

  • Raw WebSocket handlers: Use onWebsocket for low-level WebSocket control and custom protocols
  • Real-time cursor tracking: Broadcast cursor positions to all connected users instantly
  • Persistent canvas state: Text labels automatically saved in actor state across sessions
  • Multiple rooms: Each room is a separate actor instance with isolated state

Implementation

This example demonstrates low-level WebSocket handling for real-time collaboration:

  • Actor Definition (src/backend/registry.ts): Uses raw onWebsocket handler for custom WebSocket protocol implementation

Resources

Read more about WebSockets, state, and events.