|
|
@ -61,7 +61,7 @@ fastify.register(async function (fastify: Fastify) {
|
|
|
|
socket.on("message", message => {
|
|
|
|
socket.on("message", message => {
|
|
|
|
const data = JSON.parse(message.toString());
|
|
|
|
const data = JSON.parse(message.toString());
|
|
|
|
const requestId = data._request;
|
|
|
|
const requestId = data._request;
|
|
|
|
console.log(data.type)
|
|
|
|
|
|
|
|
if (data.type === "pullUpdates") {
|
|
|
|
if (data.type === "pullUpdates") {
|
|
|
|
send(socket, requestId, updates.slice(data.version));
|
|
|
|
send(socket, requestId, updates.slice(data.version));
|
|
|
|
} else if (data.type === "pushUpdates") {
|
|
|
|
} else if (data.type === "pushUpdates") {
|
|
|
@ -69,17 +69,14 @@ fastify.register(async function (fastify: Fastify) {
|
|
|
|
clientID: json.clientID,
|
|
|
|
clientID: json.clientID,
|
|
|
|
changes: ChangeSet.fromJSON(json.changes),
|
|
|
|
changes: ChangeSet.fromJSON(json.changes),
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
console.log(received);
|
|
|
|
|
|
|
|
if (data.version != updates.length) {
|
|
|
|
if (data.version != updates.length) {
|
|
|
|
received = rebaseUpdates(received, updates.slice(data.version));
|
|
|
|
received = rebaseUpdates(received, updates.slice(data.version));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(received)
|
|
|
|
|
|
|
|
for (let update of received) {
|
|
|
|
for (let update of received) {
|
|
|
|
console.log(update);
|
|
|
|
|
|
|
|
updates.push(update);
|
|
|
|
updates.push(update);
|
|
|
|
console.log(update,doc);
|
|
|
|
|
|
|
|
doc = update.changes.apply(doc);
|
|
|
|
doc = update.changes.apply(doc);
|
|
|
|
console.log(update);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send(
|
|
|
|
send(
|
|
|
|
socket,
|
|
|
|
socket,
|
|
|
@ -90,7 +87,6 @@ fastify.register(async function (fastify: Fastify) {
|
|
|
|
})),
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else if (data.type == "getDocument") {
|
|
|
|
} else if (data.type == "getDocument") {
|
|
|
|
console.log("getDoc");
|
|
|
|
|
|
|
|
send(socket, requestId, { version: updates.length, doc: doc.toString() });
|
|
|
|
send(socket, requestId, { version: updates.length, doc: doc.toString() });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|