Ahmet
Ahmet3mo ago

Is it possible to listen for subscribe/unsubscribe events for queries and trigger an action?

For example, for a convex query like api.messages.list, I want to be able to query the users who are listening to it at that time. I can update the lastOnline value for each user periodically and track it with this, but this will cause an absurd number of function calls. Since the client connects to the backend via websocket, this information is actually available in the backend. But I couldn't find how to access it and trigger an action in case of disconnect.
3 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
lee
lee3mo ago
not the way you describe, but here's an article on the pattern: https://stack.convex.dev/presence-with-convex
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.
Ahmet
AhmetOP3mo ago
Yes, this is the same logic as updating the lastOnline value. Currently we have an application with 10k clients on supabase and their online status needs to be monitored 24/7. Since api call is unlimited in Supabase, such a heartbeat style solution is not a problem. But it would cause extra cost in convex.

Did you find this page helpful?