longtable 0.1.52 → 0.1.53
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/package.json +1 -1
- package/src/browser.mjs +3 -3
- package/src/local.mjs +18 -8
package/package.json
CHANGED
package/src/browser.mjs
CHANGED
|
@@ -166,7 +166,7 @@ export class Browser {
|
|
|
166
166
|
this.call("Page.screencastFrameAck", { sessionId: p.sessionId }, msg.sessionId).catch(() => {});
|
|
167
167
|
if (msg.sessionId !== this.page?.sessionId) return;
|
|
168
168
|
this.size = { w: p.metadata.deviceWidth, h: p.metadata.deviceHeight };
|
|
169
|
-
return this.tell({ frame: p.data });
|
|
169
|
+
return this.tell({ frame: p.data, tab: this.page.targetId });
|
|
170
170
|
}
|
|
171
171
|
// A new tab, theirs or their AI's, is the one shown, as it would be in front of them.
|
|
172
172
|
if (msg.method === "Target.targetCreated" && this.note(p.targetInfo)) {
|
|
@@ -229,7 +229,7 @@ export class Browser {
|
|
|
229
229
|
await this.fitTo();
|
|
230
230
|
await this.cast();
|
|
231
231
|
const { data } = await this.call("Page.captureScreenshot", { format: "jpeg", quality: 70 }, sessionId);
|
|
232
|
-
this.tell({ frame: data });
|
|
232
|
+
this.tell({ frame: data, tab: targetId });
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -264,7 +264,7 @@ export class Browser {
|
|
|
264
264
|
await this.cast();
|
|
265
265
|
// A still page sends no new frame, so the one on screen is asked for.
|
|
266
266
|
const { data } = await this.call("Page.captureScreenshot", { format: "jpeg", quality: 70 }, this.page.sessionId);
|
|
267
|
-
viewer({ frame: data });
|
|
267
|
+
viewer({ frame: data, tab: this.page.targetId });
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
unwatch(viewer) {
|
package/src/local.mjs
CHANGED
|
@@ -27,13 +27,17 @@ export const keyOk = (auth, key) => !!key && same(String(auth || "").replace(/^B
|
|
|
27
27
|
|
|
28
28
|
export function startBridge({ app, seats, home, browser, log }) {
|
|
29
29
|
const origin = new URL(app).origin;
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
30
|
+
// Each table's terminals, as many as the person opens (tabs on their page), by a name the page gives each.
|
|
31
|
+
const terms = new Map(); // "<table>:<terminal>" -> { term, listeners, id }
|
|
32
|
+
const termId = (url) => { const id = url.searchParams.get("id") || "1"; if (!/^[A-Za-z0-9_-]{1,40}$/.test(id)) throw new Error("not a terminal"); return id; };
|
|
33
|
+
const termFor = (seat, id) => {
|
|
34
|
+
const key = `${seat.table_id}:${id}`;
|
|
35
|
+
let t = terms.get(key);
|
|
33
36
|
if (!t) {
|
|
37
|
+
if ([...terms.keys()].filter((k) => k.startsWith(`${seat.table_id}:`)).length >= 30) throw new Error("thirty terminals are open already");
|
|
34
38
|
const listeners = new Set();
|
|
35
|
-
t = { listeners, term: new Terminal(seat.terminalFolder || home, (e) => { for (const l of listeners) l(e); }) };
|
|
36
|
-
terms.set(
|
|
39
|
+
t = { id, listeners, term: new Terminal(seat.terminalFolder || home, (e) => { for (const l of listeners) l(e); }) };
|
|
40
|
+
terms.set(key, t);
|
|
37
41
|
}
|
|
38
42
|
return t;
|
|
39
43
|
};
|
|
@@ -70,8 +74,12 @@ export function startBridge({ app, seats, home, browser, log }) {
|
|
|
70
74
|
}
|
|
71
75
|
const path = url.pathname;
|
|
72
76
|
// The terminal: what it printed so far, then everything it prints. Opening it starts the shell at the page's size.
|
|
77
|
+
// Which terminals this table has running, so a page opened later shows them all as tabs.
|
|
78
|
+
if (req.method === "GET" && path === "/terms") {
|
|
79
|
+
return send(res, 200, [...terms.entries()].filter(([k, t]) => k.startsWith(`${seat.table_id}:`) && t.term.proc).map(([, t]) => ({ id: t.id })));
|
|
80
|
+
}
|
|
73
81
|
if (req.method === "GET" && path === "/term") {
|
|
74
|
-
const t = termFor(seat);
|
|
82
|
+
const t = termFor(seat, termId(url));
|
|
75
83
|
return stream(req, res, { data: t.term.text, all: true, os: SYSTEM }, async (w) => { t.listeners.add(w); await t.term.open(url.searchParams.get("cols"), url.searchParams.get("rows")); },
|
|
76
84
|
(w) => t.listeners.delete(w));
|
|
77
85
|
}
|
|
@@ -81,8 +89,10 @@ export function startBridge({ app, seats, home, browser, log }) {
|
|
|
81
89
|
if (req.method !== "POST") return send(res, 404, { error: "nothing here" });
|
|
82
90
|
const b = await body(req);
|
|
83
91
|
// Keys as typed, or a whole command from the chat's "!".
|
|
84
|
-
if (path === "/term") { const t = termFor(seat).term; await (typeof b.line === "string" ? t.run(b.line) : t.write(b.data)); return send(res, 200, { ok: true }); }
|
|
85
|
-
if (path === "/term/size") { termFor(seat).term.resize(b.cols, b.rows); return send(res, 200, { ok: true }); }
|
|
92
|
+
if (path === "/term") { const t = termFor(seat, termId(url)).term; await (typeof b.line === "string" ? t.run(b.line) : t.write(b.data)); return send(res, 200, { ok: true }); }
|
|
93
|
+
if (path === "/term/size") { termFor(seat, termId(url)).term.resize(b.cols, b.rows); return send(res, 200, { ok: true }); }
|
|
94
|
+
// A terminal's tab closed: that shell ends, as closing a tab in a terminal app does.
|
|
95
|
+
if (path === "/term/close") { const key = `${seat.table_id}:${termId(url)}`; terms.get(key)?.term.stop(); terms.delete(key); return send(res, 200, { ok: true }); }
|
|
86
96
|
if (path === "/browser") { await browser.act(b); return send(res, 200, { ok: true }); }
|
|
87
97
|
return send(res, 404, { error: "nothing here" });
|
|
88
98
|
} catch (e) {
|