i need practical help implementing presence feature in my project
Hi everyone ๐, i recently read Ian Macartney's blog on how to implement presence feature in Convex apps and it honestly went right above me. I need help breaking down how to go about doing this in my project . ๐
8 Replies
Hey! Thanks for the feedback - I'd love to know a few things to either improve the article or make a new one that's more useful. I'm taking off for today, but would love to know:
- What are you hoping to use it for? Faces, cursors, etc?
- Is there an API you've used and really liked that you with we could provide?
- What is the current status for your project: are you looking to replace existing presence features, or add them?
- How many users do you expect to be in the same "room" or "page" - how many avatars or typing indicators would be getting updated in a given client, ideally?
I've had some follow-up thoughts on ways to implement presence and other features in a more efficient way, and perhaps they could get wrapped up in a library you could use without having to understand how they work under the hood. I'd like to know more what folks want, to make sure I make something useful (though no promises I'll have it super soon, I'm focusing on AI Town currently).
Also open for others to help, but wanted to say hi and thanks in advance for any feedback!
hey @ian I read that you guys are planning on opening up some more of the "system" tables to us users. Could one of those perhaps be used for presence?
Thanks for the reply ๐
I wanna use it to simply signify that a user who is a member of a community (like reddit ) I currently online.
Also, its a new feature i am implementing
The number of users online can grow from 1 to 100
Basically, if a user who is a member of the community is online, i would like to add a green dot on the users avatar to signify they are online....so the online feature is per community
Hi @mikeysee. We'll be opening up Files and Scheduled Functions "system" tables. Presense if/when we do something for would likely be a bit more involved of an API.
ye fair enough. I dont know how your internal system works at all (I guess we will know once you have a self-hosted version) but im guessing maybe you have a central websocket provider rather than per-project one? so maybe it wont be as simple as "useQuery" on a system table
https://stack.convex.dev/presence-with-convex I assume is the Ian post you mentioned? I think the basic idea right now is to do it via polling (ping the server to say "I am here" from the client every 10 seconds or so). Obviously this will have a cost implication as it will cause you to have quite a few function calls.
If you are polling every 10 seconds and a user stays online for 24 hours then its 8640 mutations per day. Thats 259,200 per month. Times by 100 users thats 25 million per month.
Obviously that is worst case, most users arent going to spend anywhere near that long connected. You can also potentially do some sort of "back off" on the polling to reduce the frequency at wich you ping the server depening on how long the user has been connected for
Implementing Presence with Convex
Some patterns for incorporating presence into a web app leveraging Convex, and sharing some tips & utilities I built along the way.
This thread may have some things you may find useful: https://discord.com/channels/1019350475847499849/1151212440789459045/1152366488376836216
Yeah I think a simple โonline/offlineโ by using a beacon with an http action would be a great iteration to reduce the reliance on heartbeats, which can end up using more resources than necessary. Itโs on my todo list!