-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to listen to client disconnects? #424
Comments
Why not use ShareDB's built-in presence? |
It doesn't support JSON docs and the idea of transformPresence seemed overly complicated to us. We show cursors of other users as CodeMirror bookmarks so they already flow with the text without need for manual transformation. Wouldn't listening to disconnects be a more generally useful feature as well? |
const connections = {};
const presence = shareDb.getPresence('my-channel');
presence.subscribe();
presence.on('receive', (presenceId, payload) => {
// payload will be the arbitrary metadata you sent (see below)
if (payload) connections[presenceId] = payload;
// payload will be null if the remote presence has been disconnected or destroyed
else delete connections[presenceId]
});
const localPresence = presence.create('some-presence-id');
localPresence.submit({
// Whatever arbitrary metadata you want to send
}); |
Thanks! We switched to the ShareDB presence functionality by using the doc UUID as channel name. The cursors are moving much faster now. The only remaining problem is that the presence information is shared faster than the document edits, so the client inserts the new cursor position in the old version of the text. The next text arrives after that and is inserted to the right of the cursor, so CodeMirror does not move the cursor to the end of the text. Is this the type of problem that the rich-text presence transformation solves? If so, is there a simple way for us to use that feature? |
Yes, this is exactly the problem that
The "simplest" way is obviously to use the You can probably reuse most of the code from If you can get it working for |
Thanks again! We don't have the capacity and knowledge to implement that feature at the moment unfortunately. For now, we approximately fixed the off by one cursors by re-sending the presence again with 1 second delay after every cursor activity. While a collaborator is typing, their cursor is sometimes off by one but after one second it will at least land in the correct spot. It would be great to have doc presence support for string fields of |
It's good to know there's demand for presence in JSON0. I hope to take a crack at implementing it! Tracked also in ottypes/json0#30 |
There is a middleware for listening to new connections but I didn't find any to listen to the event of closed or lost websocket connections.
We would like to use this in a custom presence implementation that stores a dictionary of information about the currently connected users in the document. Users should be removed from the dictionary when they disconnect.
The text was updated successfully, but these errors were encountered: