I am trying you to understand what i am trying to do:
I am using Prosemirror
Editor is being used by a team of 6 people to send messages to clients in timeline (just like facebook timeline). This message area is not synced.
I need templates to be made so its easier to send messages. When sending message, you can select predefined templates and send instantly.
Templates are needed to be made in collaboration by everyone in team
When you create a template, you can use it in in timeline section(again which is not realtime collaborative)
Collaboration is happening only when you are making a template. I guess this makes sense now.
yjs document needs to be preserved in Redis so that any machine (node of kubernetes) can work on same document.
Now i am telling about my pain points
I have SocketIO working already in front end, and i can see a websocket provider (y-websocket) in yjs github which i don’t want to use, neither it is feasible in my usecase as socket-io supports alternatives(of ws like long polling), so i need SocketIO connector
I need my connector to save changes in redis or mongo, so if someone wants to use template while it is being modified from someone else they can have the document at least.
I need document in Prosemirror format so i can append(or replace) the message box with new content when someone clicks on a certain template.
What i did so far
By looking at how y-websocket connector is working, i have tried the following things.
i am trying to make my own connector based on socket-io (sharing the code in comment, so far)
I am trying to implement the similar logic on server side (sharing the code in comment, so far)
WHAT I AM NOT GETTING
How the hell connector works. And i am not getting any clue of it even.
How can i implement multiple instances synced using redis or whatever i can use.
Simply store the document updates in a database. This is also fairly simple. On every change, push the update, or the complete document, to your database. Syncing the servers over PubSub is a bit more complicated. y-redis - a project I’m currently working on - enables you to store document updates efficiently as incremental updates and sync all servers using Redis PubSub.
The simplest approach is to let the client do this. Otherwise you need to load ProseMirror on the server side.
Thank you so much for the quick response. I am looking into details. What i assume is that:
Create a new Y.DOC() instance on client side
Listen to changes in Y.DOC()
Emit Changes to server (using socket-io)
Server will apply the changes on its document (on server from redis) and broadcast to everyone in room
Client will get the update and apply those changes
If we think about awareness, same will happen for it as Y.DOC contains awareness.
That was the case when i am working on template creation.
Now if someone is trying to get a list of templates, and clicks one. Unfortunately i can’t pass the Y.DOC to user, may be i can. But the problem is that in this specific prosemirror i am not using and Y plugins. I need normal prosemirror content.
If i look into y.doc api, i can’t find a way to get the prosemirror document out of it.
As said. Yjs only models the ProseMirror content. You need to create a ProseMirror instance and bind it to a Yjs document in order to get / set the content.
You can retrieve the Yjs document in an XML format by doing yXmlType.toString(). But that’s it.
You can simply encode the Yjs document and send it to the user, and restruct it.
If you just want to apply some initial content as a template, you could also store the template as a Yjs document update, and then apply the document update as the initial content on the server. Then you don’t need the ProseMirror instance.