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
- RealtimeResponseEvent Typescript Bug
Hello, could you please fix RealtimeResposneEvent, the one in realtime.ts have timestamp: string, but the one in client.ts have timestamp: number, and it causes...
- Realtime Docs are outdated
The Realtime docs are outdated.
- Fine grained permissions for webRTC hand...
Hi, I am building a WebRTC P2P app for a university project and have hit a security limitation regarding permissions for anonymous users. The Architecture: We ...