Presence in Convex
I wrote a little presence component that you can use directly in your Convex apps, or copy the code to change as you see fit: https://www.convex.dev/components/presence.
It's written in such a way that subscription updates within a "room" are only sent whenever someone joins/leaves, not on every heartbeat. It also shares the same cached subscription for everyone in the room so only issues a single database read. I've set it up so it marks a user as offline immediately whenever they lose visibility state or close the browser tab, but it also disconnects them after a timeout if the connection fails somehow.
Demo: https://presence.previews.convex.dev/
Source code: https://github.com/get-convex/presence/
GitHub
GitHub - get-convex/presence: Convex presence component
Convex presence component. Contribute to get-convex/presence development by creating an account on GitHub.

3 Replies
It's great to see Convex engineers building components for plug n play features! This is so fun!
I'm building a private company app, and I can see this being useful to track active users, where the entire app is the "room".
been waiting for this one 🙏 😍 , going to use it everywhere ^^