With Presence, you can store a temporary string, boolean, number, or JSON object on a user. Use it to build mouse cursors, shared highlighting, draggable effects, or any other feature that doesn't require long-term persistence.
By design, presence has two rules:
- A user can only write to their own keys, but can read from anyone else in the Room.
- Presence keys expire.
Once you have a room setup, you can start using presence:
By default, presence keys expire in 1 minute unless updated. But you can set this timeout yourself, up to 3 days:
set function returns an object containing the values for every user in the room. Each key of the object is a user id corresponding to the ones given in your Auth Webhook.
You can load the most up-to-date values with the
But most of the time, you can listen for incremental updates via the room:
As a helper, you can also get exactly where this update is coming from:
By default, Presence keys expire when you leave the room.
Using Presence to see who's in the room
As the name implies, presence is the way you see who's in a room in Room Service. To accomplish this, just store a boolean value for the user.