Shared Cursors

Ephemeral cursor presence with latest-state delivery

const rtc = OpenRTC({ apiKey });
const space = await rtc.spaces.join('portfolio-cursors');
const cursors = space.state<{ x: number; y: number }>('cursor');

cursors.watch(({ peerId, value }) => renderCursor(peerId, value));
window.onpointermove = ({ clientX: x, clientY: y }) => cursors.set({ x, y });

state() keeps only the newest queued value for each peer and sends the current value to new connections. A null value removes a disconnected peer's cursor. The space is live-only: ordinary visitors create no durable room membership or product-auth principal.

For React, buffer incoming positions in a ref and commit them at most once per animation frame. Send at 10–15 Hz rather than on every browser pointer event. On teardown, unsubscribe the watcher and await space.leave().