How to combine Quill Rich Text Editor and socket.io to share Deltas

I am trying to combine Quill Rich text editor and socket.io. I would like to have an editor similar to Google docs where people can edit at the same time.

I'm struggling to send and apply "text change" events on a wire using code similar to this:

fullEditor.on('text-change', function(delta, source) {
  if (source === 'user') {
    socket.emit('text change', {'who': my_id, 'delta': JSON.stringify(delta)});
  }
});


socket.on('text change', function(msg){
  if(msg.who != my_id) {
      var del = JSON.parse(msg.delta);
      var Delta = fullEditor.getContents().constructor;
      var delta = new Delta(del.startLength,del.endLength,del.ops);
      fullEditor.updateContents( delta );
    }
    });

This does not work with

Uncaught TypeError: undefined is not a function | quill.js: 8020

since I have a simple hash on the other end, and quill expects objects of a certain type (InsertOp, http://quilljs.com/docs/editor/deltas/ , etc.).

Any ideas how to make it work?

+4
source share
1

, updateContents Delta, Delta Operations.

(v0.14.0) updateContents, javascript, :

socket.on('text change', function(msg){
  if(msg.who != my_id) {
    var del = JSON.parse(msg.delta);
    fullEditor.updateContents( del );
  }
});

, Google, - . , GoInstant OT API, , ShareJS.

+2

Source: https://habr.com/ru/post/1542759/


All Articles