itwillsync 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -3933,6 +3933,7 @@ function createSyncServer(options) {
|
|
|
3933
3933
|
const clients = /* @__PURE__ */ new Set();
|
|
3934
3934
|
const aliveMap = /* @__PURE__ */ new WeakMap();
|
|
3935
3935
|
let scrollbackBuffer = "";
|
|
3936
|
+
let seq = 0;
|
|
3936
3937
|
const httpServer = createServer2(async (req, res) => {
|
|
3937
3938
|
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
|
3938
3939
|
let pathname = url.pathname;
|
|
@@ -3969,7 +3970,7 @@ function createSyncServer(options) {
|
|
|
3969
3970
|
clients.add(ws);
|
|
3970
3971
|
aliveMap.set(ws, true);
|
|
3971
3972
|
if (scrollbackBuffer.length > 0) {
|
|
3972
|
-
ws.send(scrollbackBuffer);
|
|
3973
|
+
ws.send(JSON.stringify({ type: "data", data: scrollbackBuffer, seq }));
|
|
3973
3974
|
}
|
|
3974
3975
|
ws.on("pong", () => {
|
|
3975
3976
|
aliveMap.set(ws, true);
|
|
@@ -3981,6 +3982,12 @@ function createSyncServer(options) {
|
|
|
3981
3982
|
ptyManager.write(message.data);
|
|
3982
3983
|
} else if (message.type === "resize" && typeof message.cols === "number" && typeof message.rows === "number") {
|
|
3983
3984
|
ptyManager.resize(message.cols, message.rows);
|
|
3985
|
+
} else if (message.type === "resume" && typeof message.lastSeq === "number") {
|
|
3986
|
+
const missed = seq - message.lastSeq;
|
|
3987
|
+
if (missed > 0 && scrollbackBuffer.length > 0) {
|
|
3988
|
+
const delta = missed <= scrollbackBuffer.length ? scrollbackBuffer.slice(-missed) : scrollbackBuffer;
|
|
3989
|
+
ws.send(JSON.stringify({ type: "data", data: delta, seq }));
|
|
3990
|
+
}
|
|
3984
3991
|
}
|
|
3985
3992
|
} catch {
|
|
3986
3993
|
}
|
|
@@ -3993,13 +4000,15 @@ function createSyncServer(options) {
|
|
|
3993
4000
|
});
|
|
3994
4001
|
});
|
|
3995
4002
|
ptyManager.onData((data) => {
|
|
4003
|
+
seq += data.length;
|
|
3996
4004
|
scrollbackBuffer += data;
|
|
3997
4005
|
if (scrollbackBuffer.length > SCROLLBACK_BUFFER_SIZE) {
|
|
3998
4006
|
scrollbackBuffer = scrollbackBuffer.slice(-SCROLLBACK_BUFFER_SIZE);
|
|
3999
4007
|
}
|
|
4008
|
+
const msg = JSON.stringify({ type: "data", data, seq });
|
|
4000
4009
|
for (const client of clients) {
|
|
4001
4010
|
if (client.readyState === client.OPEN) {
|
|
4002
|
-
client.send(
|
|
4011
|
+
client.send(msg);
|
|
4003
4012
|
}
|
|
4004
4013
|
}
|
|
4005
4014
|
});
|