I am building a collaborative editor for my canvas editor, I am using Yjs for the collaborative editor. For every change one client is doing i am receiving that update at the backend and updating my yjs doc at the backend. I am using React and Nodejs along with sockets.
But one problem I am facing with this backend code (given), my backend Yjs doc is not updating and it’s saving the older data to Redis. I am adding both backend and frontend code.
Canvas is JSON objects of elements
Any help will be grateful.
Yjs version Node : yjs13.6.18
Yjs version React : yjs :13.0.0-103
// Frontend React Code
const ymap = doc.getMap('json');
ymap.set('data', designer.canvas);
const update = Y.encodeStateAsUpdate(doc);
if (socket) socket.emit('update', { update, id });
// Backend Node code
socket.on('update', async ({update, id}) => {
doc.transact(() => {
Y.applyUpdate(doc, new Uint8Array(update));
});
let updatedJson = ymap.get('data');
}
I tried this Y.applyUpdate() & Y.diffUpdate() but some times my older data is not updating :