I am using Y.applyUpdate() for a complex json data but it’s not working sometimes.
// Client Side
const doc = new Y.Doc();
const stateVector1 = Y.encodeStateVector(doc);
let ymapJSON = doc.getMap(‘json’);
doc.transact(() => {
ymapJSON.set(‘data’, designer.data);
}, uniqueId);
const diff1 = Y.encodeStateAsUpdate(doc, stateVector1);
currentSocket.emit('update', {update: diff1, Id: id});
//Server Side
socket.on('update', async ({update, Id}) => {
// doc is defined earlier while I loaded the presentation the first time
const ymap = doc.getMap('json');
doc.transact(() => {
Y.applyUpdate(doc, update,);
});
let updatedJson = ymap.get('data');
await redis.set(redis_key, JSON.stringify(data))
})}