@dotrino/terminal-agent 0.25.0 → 0.26.0
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/consoles.js +27 -2
- package/index.js +7 -1
- package/package.json +1 -1
package/consoles.js
CHANGED
|
@@ -310,13 +310,38 @@ export class ConsoleHub {
|
|
|
310
310
|
c.viewers.clear()
|
|
311
311
|
try { c.screen.dispose() } catch (_) {}
|
|
312
312
|
})
|
|
313
|
-
|
|
313
|
+
// DÓNDE va en el panel: mientras nadie haya movido nada (están por número), en su sitio por
|
|
314
|
+
// número; si alguien las ordenó a mano, al final, para no deshacerle el orden.
|
|
315
|
+
const all = [...this.consoles.values()]
|
|
316
|
+
const byNumber = all.every((x, i) => i === 0 || all[i - 1].n < x.n)
|
|
317
|
+
const at = byNumber ? all.findIndex((x) => x.n > n) : -1
|
|
318
|
+
if (at === -1) all.push(c); else all.splice(at, 0, c)
|
|
319
|
+
this._order(all)
|
|
314
320
|
return c
|
|
315
321
|
}
|
|
316
322
|
|
|
323
|
+
_order (all) { this.consoles = new Map(all.map((c) => [c.id, c])) }
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* El ORDEN del panel, el mismo en todas las ventanas y aparatos: la consola `id` pasa a estar
|
|
327
|
+
* justo antes de `before` (o al final, con `null` o con una que ya no existe). No cambia su
|
|
328
|
+
* número, que es fijo. `false` si esa consola ya no existe.
|
|
329
|
+
*/
|
|
330
|
+
move (id, before = null) {
|
|
331
|
+
const c = this.consoles.get(id)
|
|
332
|
+
if (!c) return false
|
|
333
|
+
if (before === id) return true
|
|
334
|
+
const all = [...this.consoles.values()].filter((x) => x !== c)
|
|
335
|
+
const at = before == null ? -1 : all.findIndex((x) => x.id === before)
|
|
336
|
+
if (at === -1) all.push(c); else all.splice(at, 0, c)
|
|
337
|
+
this._order(all)
|
|
338
|
+
return true
|
|
339
|
+
}
|
|
340
|
+
|
|
317
341
|
get (id) { return this.consoles.get(id) || null }
|
|
318
342
|
|
|
319
|
-
|
|
343
|
+
/** Las consolas, en el orden del panel (por número hasta que alguien las mueve: `move`). */
|
|
344
|
+
list () { return [...this.consoles.values()].map((c) => c.info()) }
|
|
320
345
|
|
|
321
346
|
/** Cierra una consola. `by`: la pantalla (viewer) que lo pide, para decirle a las DEMÁS que no fueron ellas. */
|
|
322
347
|
kill (id, by = null) {
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* { type:'attach', id, cols, rows } · { type:'detach' } ·
|
|
15
15
|
* { type:'input', data } · { type:'resize', cols, rows } · { type:'pin', on } ·
|
|
16
16
|
* { type:'close' } (mata la consola enganchada) · { type:'kill', id } ·
|
|
17
|
+
* { type:'move', id, before? } (el orden del panel; contesta con `consoles`) ·
|
|
17
18
|
* { type:'unlock', code } (la clave de la máquina, si tiene: access.js)
|
|
18
19
|
* agente → cliente: { type:'consoles', list } · { type:'attached', id, fresh } ·
|
|
19
20
|
* { type:'replay', id, data, last } · { type:'out', data } ·
|
|
@@ -174,7 +175,12 @@ export function serveSession (session, hub, { origin = 'remote', gate = null } =
|
|
|
174
175
|
// ⤢ «Esta pantalla manda en el tamaño» (on) o soltarlo (off).
|
|
175
176
|
if (msg.type === 'pin') { current?.pin(viewer, !!msg.on); return }
|
|
176
177
|
if (msg.type === 'close') { if (current) hub.kill(current.id, viewer); return }
|
|
177
|
-
if (msg.type === 'kill') { if (!hub.kill(msg.id, viewer)) fail('no-console', 'that console no longer exists') }
|
|
178
|
+
if (msg.type === 'kill') { if (!hub.kill(msg.id, viewer)) fail('no-console', 'that console no longer exists'); return }
|
|
179
|
+
// El orden del panel: es de la máquina, así que lo ve igual cualquier pantalla.
|
|
180
|
+
if (msg.type === 'move') {
|
|
181
|
+
if (!hub.move(String(msg.id), msg.before == null ? null : String(msg.before))) return fail('no-console', 'that console no longer exists')
|
|
182
|
+
session.send({ type: 'consoles', list: hub.list() })
|
|
183
|
+
}
|
|
178
184
|
})
|
|
179
185
|
session.on('close', () => {
|
|
180
186
|
const mine = owned && owned === current ? owned : null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Dotrino Terminal: las ventanas de esta máquina (dotrino-terminal) y su agente, que deja abrir esas mismas consolas desde los otros aparatos de tu cuenta, cifrado punto a punto.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|