Using y-codemirror and y-websocket with a custom Go server

Greetings!

I’d like to enable collaborative editing for codemirror using y-codemirror and y-websocket with Go server being used as a backend (WebSocket support is provided by gorilla/websocket).

AFAIU it should be possible to enable this functionality without any yjs-specifc code on server side; only an open websocket connection is required. Is it correct?

The client’s code that I have is as simple as

const doc = new Y.Doc();
var provider = new WebsocketProvider(url, room, doc);
const text = doc.getText('codemirror');
const binding = new CodemirrorBinding(text, this.editor, provider.awareness);

It works as a charm. At least the shared editing works across multiple clients in a browser.

However, the browser console reports that a client attempts to send numerous requests with binary content to the server, which the server doesn’t now how to interpret. It causes a request failure as a result. It’d like to solve this problem.

First, what are these messages? Are these sync messages? Why are they needed given that a collaborative editing works without them, as far as I can see. Does it mean that the server cannot be agnostic to y-codemirror/y-websocket libraries being used by the client?

What is a reasonable workaround for solving this problem, given that the server is implemented in Go? Several ideas that I have, which I haven’t managed to implement successfully so far:

  • Disable sync messages in client’s code. How to do it and what will be the implications?
  • Implement a custom logic in the server for handling the sync messages. I tried to rewrite this logic in Go, unsuccessfully so far. Does it make sense in overall?
    It’s the most tiresome approach and I’d like to use it if other alternative solutions are infeasible.

I appreciate your help in advance.

Hi @zayac,

If you want to implement a custom network provider, you don’t necessarily need to interpret the yjs content. It is just important that all clients end up with all document updates. This is explained in more detail here: https://github.com/yjs/yjs#document-updates

There is no yjs implementation in go yet. Please also have a look at this thread: Y-websocket server vs ydb for long-term persistent store of documents

The y-websocket protocol requires you to understand the sync-protocol that is implemented in y-protocols and requires you to understand the Yjs document updates. You can implement your custom sync protocol purely on synchronizing document updates.

As long as your custom server implementation syncs document updates with all clients, you can use Yjs with any editor binding. You can even use multiple network providers at the same time.