deckide 3.5.12 → 3.5.14
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/routes/terminals.js
CHANGED
|
@@ -11,10 +11,14 @@ export function createTerminalRouter(db, decks, terminals) {
|
|
|
11
11
|
const router = new Hono();
|
|
12
12
|
function appendToTerminalBuffer(session, data) {
|
|
13
13
|
const newBuffer = session.buffer + data;
|
|
14
|
-
|
|
15
|
-
newBuffer.length
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (newBuffer.length > TERMINAL_BUFFER_LIMIT) {
|
|
15
|
+
const excess = newBuffer.length - TERMINAL_BUFFER_LIMIT;
|
|
16
|
+
session.buffer = newBuffer.slice(excess);
|
|
17
|
+
session.bufferBase += excess;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
session.buffer = newBuffer;
|
|
21
|
+
}
|
|
18
22
|
}
|
|
19
23
|
function getNextTerminalIndex(deckId) {
|
|
20
24
|
const current = deckTerminalCounters.get(deckId) ?? 0;
|
|
@@ -116,6 +120,7 @@ export function createTerminalRouter(db, decks, terminals) {
|
|
|
116
120
|
createdAt,
|
|
117
121
|
sockets: new Set(),
|
|
118
122
|
buffer: '',
|
|
123
|
+
bufferBase: 0,
|
|
119
124
|
lastActive: Date.now(),
|
|
120
125
|
write: (data) => { try {
|
|
121
126
|
term.write(data);
|
package/dist/websocket.js
CHANGED
|
@@ -143,20 +143,33 @@ export function setupWebSocketServer(server, terminals) {
|
|
|
143
143
|
const session = terminals.get(id);
|
|
144
144
|
if (!session) {
|
|
145
145
|
untrackConnection(clientIP, socket);
|
|
146
|
-
socket.close(
|
|
146
|
+
socket.close(1000, 'Terminal not found');
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
149
149
|
session.sockets.add(socket);
|
|
150
150
|
session.lastActive = Date.now();
|
|
151
151
|
// Send buffer content if available
|
|
152
|
-
// bufferOffset:
|
|
152
|
+
// bufferOffset: absolute character count the client already received
|
|
153
|
+
// bufferBase: absolute position of buffer[0] (chars dropped from start)
|
|
153
154
|
const offsetParam = url.searchParams.get('bufferOffset');
|
|
154
|
-
const
|
|
155
|
+
const clientOffset = offsetParam ? Math.max(0, parseInt(offsetParam, 10) || 0) : 0;
|
|
155
156
|
if (session.buffer) {
|
|
156
157
|
try {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const bufferStart = session.bufferBase;
|
|
159
|
+
const bufferEnd = session.bufferBase + session.buffer.length;
|
|
160
|
+
let bufferToSend;
|
|
161
|
+
if (clientOffset <= bufferStart) {
|
|
162
|
+
// Client's last position is before (or at) what we have — send everything
|
|
163
|
+
bufferToSend = session.buffer;
|
|
164
|
+
}
|
|
165
|
+
else if (clientOffset >= bufferEnd) {
|
|
166
|
+
// Client is fully up to date
|
|
167
|
+
bufferToSend = '';
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// Send only the delta
|
|
171
|
+
bufferToSend = session.buffer.slice(clientOffset - bufferStart);
|
|
172
|
+
}
|
|
160
173
|
if (bufferToSend) {
|
|
161
174
|
socket.send(bufferToSend);
|
|
162
175
|
}
|