Hey! I'd like to know when a user disconnects. Something like this, for example:
client.onRealtimeConnectionLost(() => {
databases.createDocument('main', 'messages', {message: `${currentUser.name} has left the game.`});
I hope my question is clear. Is it possible? If not, could you suggest some efficient workarounds? Thanks!
You might want to ππΌ this issue: https://github.com/appwrite/appwrite/issues/2418
For now, you can implement a heartbeat/pinging approach where the client sends a request every X interval to let the server know it's still around. After Y interval of no responses, the server would determine the user has left/disconnected
Thanks!
Um could you help me a bit more? Basically, a user needs to know if another user is on the same page.
Let's say I wrote an interval function that keeps pinging they're on that page but in what way?
I could have a collection for this. With documents like pageId = {currentlyPresent=["userId1", "userId2"]}
etc and then subscribe to that particular document to get realtime update. But how do I actually detect there are two users concurrently on that page?
I'm sorry if I'm not making any sense but I hope you at least understand what I need.
you could have a presence collection with userId and page. when a user is on the page, a document will be created. the document will be updated as long as they're on the page. after inactivity, the document would be deleted.
The realtime would listen for documents in that collection and then do as needed
Recommended threads
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- i am getting 404 not found in my current...
in my current appwrite i am getting 404 not found from backend side and in frontend getting error of CORS error as backend is not working
- How to create a custom authentication sy...
Iβm looking to create an Appwrite function that first verifies a client using some custom logic, like providing a secret key. Once this verification is complete...