-
Notifications
You must be signed in to change notification settings - Fork 450
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
transformPresence is not a function #423
Comments
I've also faced this challenge, and have yet to do a proper implementation. Here's what I got so far: import { type } from 'ot-json0';
type.transformPresence = function (presence, op, isOwnOp) {
if (!presence) {
return null;
}
//console.log('TODO transform presence.');
// Draw from https://github.com/datavis-tech/json0/tree/master/lib
//
//var start = presence.index;
//var end = presence.index + presence.length;
//var delta = new richText.Delta(op);
//start = delta.transformPosition(start, !isOwnOp);
//end = delta.transformPosition(end, !isOwnOp);
//return Object.assign({}, presence, {
// index: start,
// length: end - start
//});
return presence;
};
export { type }; This just makes it so ShareDB does not error, but it does not transform the presence properly. Also tracked in ottypes/json0#30 |
Long story short:
Pasting here for reference: json.transformPresence = function(presence, op, isOwnOp) {
// Don't transform path-only presence objects.
if(!presence.t) return presence;
for (var i = 0; i < op.length; i++) {
var c = op[i];
// convert old string ops to use subtype for backwards compatibility
if (c.si != null || c.sd != null) {
convertFromText(c);
}
// Transform against subtype ops.
if (c.t && c.t === presence.t && json.pathMatches(c.p, presence.p)) {
presence = Object.assign({}, presence, {
s: subtypes[presence.t].transformPresence(presence.s, c.o, isOwnOp)
});
}
// convert back to old string ops
if (c.t === 'text0') {
convertToText(c);
}
// TODO transform against non-subtype ops.
};
return presence;
}; It's a tricky problem, though, because we need consensus on what the shape of presence data should be for json0. |
Thanks for the references, that's definitely helpful. We only need presence information for a text value inside the JSON object. In this case, there would be no problem about deciding what shape the presence data should take if I understand correctly. Do you have an idea whether that would be easy to do? Besides this, I'm also wondering how important it is to transform the presence information locally at all. Wouldn't it be enough to store a mapping from user ID to arbitrary JSON alongside each doc, and have the ShareDB server delete keys when they lose their websocket connection? Is the problem that this would introduce a lag? |
The transformation is required, because I notice with my implementation now (which also uses CodeMirror), the presence cursor for the remote user stays in the same place, even if I add a character before it. It does not move around along with the text, which it should. It feels buggy without the transformation. For the shape of the presence, I ended up with something like this: {
p: ['some', 'path'], // Path of the presence.
t: 'ot-rich-text', // Subtype of the presence (a registered subtype).
s: { // Opaque presence object (subtype-specific structure).
u: '123', // An example of an ot-rich-text presence object.
c: 8,
s: [ [ 1, 1 ], [ 5, 7 ]]
}
} Here's a demo project with this in action. The task at hand is to upgrade that demo and the transformation logic to use the new ShareDB presence API. I think it's fairly similar, but I have not mapped out the details in full. |
We wrote something without any of the presence features of ShareDB now. We just store a mapping We only show cursors whose timestamp is not older than some threshold. Ideally, we could make cursors disappear when the ShareDB server looses the WebSocket connection to them rather than via a timeout, but we haven't found the right middleware to hook into for this. Thanks for the sharing the demo! It looks really clean and we will probably try switching to that when we run into problems with our solution. We are experiencing some lag with the solution above, not for your own cursor but for text insertions and cursor movements of other users. The text does not appear character by character but in chunks of about 3-5 characters. We didn't see this lag before. Are you experiencing this with you demo as well? |
Yes, sorry, we should definitely have a better error for this case. But yes, |
We're using ShareDB with the nickasd/sharedb-codemirror connector. The editor content is synchronized well and now we want to show other editor's cursors via ShareDB's presence feature.
Creating the doc on the server:
Connecting to the doc from the client:
Error message on document edit:
The text was updated successfully, but these errors were encountered: