Presence Metadata
Using metadata for names, colors, avatars, and custom status fields.
Presence metadata is the information each user broadcasts about themselves: their name, avatar, color, status, or any custom data your app needs. It's stored per-user per-room and automatically distributed to everyone in the room.
Setting initial metadata
Pass metadata to <FlockProvider>:
Every other user in the room will see this in usePresence() immediately when you join.
Reading others' metadata
Updating your own metadata
useMyPresence returns [yourMetadata, updateFn]. The updater function sends a partial patch — only the fields you provide change:
The update is optimistic — me.status changes immediately in your own UI, and other users see the change after the server round-trip.
Custom fields
UserMetadata accepts any extra fields beyond the built-in name, color, and avatar:
Other users see these in their usePresence() data:
User colors
A common pattern is to assign each user a color when they first connect. Pick from a palette based on their user ID so the same user always gets the same color:
Presence vs. cursor data
Presence and cursors are separate channels:
- Presence is who's in the room and their metadata. It persists until the user leaves (or the TTL expires). Use it for names, colors, avatars, and slow-changing state.
- Cursors are live position updates throttled to ~20/sec. Use them for tracking mouse position, not for general state.
If you need to share fast-changing state that isn't a position, presence metadata is the right place for it. The server merges updates without replacing the full metadata object, so frequent partial updates are fine.
Persistence across reconnects
Metadata is stored in Redis (when configured) and persists across short disconnects. When a user reconnects, the client re-joins with the same userId and metadata, so other users see a clean re-join rather than losing the user's color and name.