Newer
Older
/* eslint-disable no-console */
import { yCursorPlugin, ySyncPlugin, yUndoPlugin } from 'y-prosemirror';
import { WebsocketProvider } from 'y-websocket';
import * as Y from 'yjs';
import './yjs.css';
const {
connectionUrl,
docIdentifier,
cursorBuilder,
provider: configProvider,
ydoc: configYdoc,
} = this.config;
let provider = configProvider ? configProvider() : null;
let ydoc = configYdoc ? configYdoc() : null;
if (!configProvider || !configYdoc) {
ydoc = new Y.Doc();
provider = new WebsocketProvider(connectionUrl, docIdentifier, ydoc);
}
provider.on('sync', args => {
console.log({ sync: args });
});
provider.on('status', args => {
console.log({ status: args });
});
provider.on('connection-close', args => {
console.log({ connectioClose: args });
});
provider.on('connection-error', args => {
console.log({ connectioError: args });
});
if (cursorBuilder) {
this.app.PmPlugins.add(
'yCursorPlugin',
yCursorPlugin(provider.awareness, { cursorBuilder }),
);
} else {
this.app.PmPlugins.add(
'yCursorPlugin',
yCursorPlugin(provider.awareness),
);
}