my server code:
const decoder = decoding.createDecoder(new Uint8Array(message));
const messageType = decoding.readVarUint(decoder);
if (messageType === 0) {
// send initial doc state
const stateVector = decoding.readVarUint8Array(decoder);
const update = Y.encodeStateAsUpdate(model.ydoc, stateVector);
const encoder = encoding.createEncoder();
encoding.writeVarUint(encoder, 1);
encoding.writeVarUint8Array(encoder, update);
ws.send(encoding.toUint8Array(encoder), true);
} else if (messageType === 1) {
const update = decoding.readVarUint8Array(decoder);
Y.applyUpdate(model.ydoc, update, ws);
model.change++;
if (model.clients > 1) {
const encoder = encoding.createEncoder();
encoding.writeVarUint(encoder, 1);
encoding.writeVarUint8Array(encoder, update);
ws.publish(wdata.fid, encoding.toUint8Array(encoder));
}
}
client code:
let data=event.data
if(data=='1'){
// request initial doc state
const encoder = new encoding.Encoder();
encoding.writeVarUint(encoder, 0);
encoding.writeVarUint8Array(encoder, Y.encodeStateVector(doc));
ws.send(encoding.toUint8Array(encoder));
}else{
const decoder = new decoding.Decoder(new Uint8Array(event.data));
const messageType = decoding.readVarUint(decoder);
if (messageType === 1) {
const update = decoding.readVarUint8Array(decoder);
Y.applyUpdate(doc, update);
if(first){
console.log('update',update.length)
first=false
cb()
}
}
}
when i refresh the browser, why the update.length is increasing (23 bytes each time)? i dont change anything.