@eserstack/mux 0.0.0-stage → 5.0.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/LICENSE +13 -0
- package/README.md +150 -2
- package/dist/engine/effects.d.ts +52 -0
- package/dist/engine/effects.js +2 -0
- package/dist/engine/geometry.d.ts +57 -0
- package/dist/engine/geometry.js +170 -0
- package/dist/engine/mod.d.ts +13 -0
- package/dist/engine/mod.js +5 -0
- package/dist/engine/reducer.d.ts +15 -0
- package/dist/engine/reducer.js +325 -0
- package/dist/engine/sanitize.d.ts +60 -0
- package/dist/engine/sanitize.js +64 -0
- package/dist/engine/split-tree.d.ts +41 -0
- package/dist/engine/split-tree.js +117 -0
- package/dist/engine/types.d.ts +192 -0
- package/dist/engine/types.js +2 -0
- package/dist/frontends/frontend.d.ts +17 -0
- package/dist/frontends/frontend.js +2 -0
- package/dist/frontends/tui/compositor.d.ts +23 -0
- package/dist/frontends/tui/compositor.js +72 -0
- package/dist/frontends/tui/frame.d.ts +9 -0
- package/dist/frontends/tui/frame.js +2 -0
- package/dist/frontends/tui/input-source.d.ts +21 -0
- package/dist/frontends/tui/input-source.js +40 -0
- package/dist/frontends/tui/tui-frontend.d.ts +36 -0
- package/dist/frontends/tui/tui-frontend.js +188 -0
- package/dist/ipc/protocol.d.ts +41 -0
- package/dist/ipc/protocol.js +2 -0
- package/dist/ipc/transport-inprocess.d.ts +9 -0
- package/dist/ipc/transport-inprocess.js +35 -0
- package/dist/ipc/transport-ws.d.ts +19 -0
- package/dist/ipc/transport-ws.js +37 -0
- package/dist/keybindings/defaults.d.ts +3 -0
- package/dist/keybindings/defaults.js +80 -0
- package/dist/keybindings/mod.d.ts +10 -0
- package/dist/keybindings/mod.js +4 -0
- package/dist/keybindings/modes.d.ts +19 -0
- package/dist/keybindings/modes.js +18 -0
- package/dist/keybindings/registry.d.ts +20 -0
- package/dist/keybindings/registry.js +37 -0
- package/dist/mod.d.ts +28 -0
- package/dist/mod.js +21 -0
- package/dist/render/scheduler.d.ts +18 -0
- package/dist/render/scheduler.js +33 -0
- package/dist/runner/inprocess.d.ts +10 -0
- package/dist/runner/inprocess.js +60 -0
- package/dist/scene/diff.d.ts +26 -0
- package/dist/scene/diff.js +83 -0
- package/dist/scene/mod.d.ts +9 -0
- package/dist/scene/mod.js +3 -0
- package/dist/scene/scene.d.ts +30 -0
- package/dist/scene/scene.js +54 -0
- package/dist/server/pty-host.d.ts +25 -0
- package/dist/server/pty-host.js +81 -0
- package/dist/server/server.d.ts +58 -0
- package/dist/server/server.js +204 -0
- package/package.json +48 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* The frontend-neutral scene model.
|
|
4
|
+
*
|
|
5
|
+
* The server derives a {@link Scene} from {@link MuxState} and broadcasts it
|
|
6
|
+
* (plus per-pane raw output streamed separately). Every frontend — the ANSI TUI
|
|
7
|
+
* compositor and a browser xterm.js app alike — renders from this same model, so
|
|
8
|
+
* the core stays rendering-agnostic.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import * as geometry from "../engine/geometry.js";
|
|
13
|
+
import * as splitTree from "../engine/split-tree.js";
|
|
14
|
+
/** Derive the neutral scene for the active tab from engine state. */
|
|
15
|
+
export const deriveScene = (state, chrome = geometry.DEFAULT_CHROME) => {
|
|
16
|
+
const tab = state.tabs[state.activeTab];
|
|
17
|
+
if (tab === undefined) {
|
|
18
|
+
return {
|
|
19
|
+
tabs: [],
|
|
20
|
+
activeTab: 0,
|
|
21
|
+
mode: state.mode,
|
|
22
|
+
viewport: state.viewport,
|
|
23
|
+
focusedPane: null,
|
|
24
|
+
panes: [],
|
|
25
|
+
chrome,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const geoms = geometry.computeTabGeoms(tab, state.viewport, chrome);
|
|
29
|
+
const order = splitTree.collectLeaves(tab.root);
|
|
30
|
+
const panes = [];
|
|
31
|
+
for (const id of order) {
|
|
32
|
+
const geom = geoms.get(id);
|
|
33
|
+
if (geom === undefined)
|
|
34
|
+
continue; // hidden behind a fullscreen pane
|
|
35
|
+
const pane = state.panes[id];
|
|
36
|
+
panes.push({
|
|
37
|
+
id,
|
|
38
|
+
kind: pane?.kind ?? "terminal",
|
|
39
|
+
title: pane?.title ?? id,
|
|
40
|
+
geom,
|
|
41
|
+
focused: id === tab.focusedPane,
|
|
42
|
+
exited: pane?.exited ?? false,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
tabs: state.tabs.map((t) => ({ id: t.id, name: t.name })),
|
|
47
|
+
activeTab: state.activeTab,
|
|
48
|
+
mode: state.mode,
|
|
49
|
+
viewport: state.viewport,
|
|
50
|
+
focusedPane: tab.focusedPane,
|
|
51
|
+
panes,
|
|
52
|
+
chrome,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PaneId } from "../engine/types.ts";
|
|
2
|
+
export type PtyHostCallbacks = {
|
|
3
|
+
onData(pane: PaneId, data: string): void;
|
|
4
|
+
onExit(pane: PaneId, code: number): void;
|
|
5
|
+
};
|
|
6
|
+
export type SpawnRequest = {
|
|
7
|
+
readonly pane: PaneId;
|
|
8
|
+
readonly command: string;
|
|
9
|
+
readonly args: readonly string[];
|
|
10
|
+
readonly cwd?: string;
|
|
11
|
+
readonly env?: Record<string, string>;
|
|
12
|
+
readonly cols: number;
|
|
13
|
+
readonly rows: number;
|
|
14
|
+
};
|
|
15
|
+
export type PtyHost = {
|
|
16
|
+
spawn(req: SpawnRequest): Promise<void>;
|
|
17
|
+
write(pane: PaneId, data: string): void;
|
|
18
|
+
resize(pane: PaneId, cols: number, rows: number): void;
|
|
19
|
+
kill(pane: PaneId): void;
|
|
20
|
+
/** Drop a pane that already exited (no signal sent). */
|
|
21
|
+
forget(pane: PaneId): void;
|
|
22
|
+
killAll(): Promise<void>;
|
|
23
|
+
has(pane: PaneId): boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const createPtyHost: (cb: PtyHostCallbacks) => PtyHost;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Owns the live PtyProcess for each pane and bridges them to the engine: pane
|
|
4
|
+
* output is forwarded out, process exit is reported back. Resizes are
|
|
5
|
+
* de-duplicated so a steady stream of identical geometry costs nothing.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import * as exec from "@eserstack/shell/exec";
|
|
10
|
+
export const createPtyHost = (cb) => {
|
|
11
|
+
const ptys = new Map();
|
|
12
|
+
const sizes = new Map();
|
|
13
|
+
return {
|
|
14
|
+
async spawn(req) {
|
|
15
|
+
if (ptys.has(req.pane))
|
|
16
|
+
return;
|
|
17
|
+
const pty = await exec.spawnPty({
|
|
18
|
+
command: req.command,
|
|
19
|
+
args: [...req.args],
|
|
20
|
+
cwd: req.cwd,
|
|
21
|
+
env: req.env,
|
|
22
|
+
cols: req.cols,
|
|
23
|
+
rows: req.rows,
|
|
24
|
+
});
|
|
25
|
+
ptys.set(req.pane, pty);
|
|
26
|
+
sizes.set(req.pane, `${req.cols}x${req.rows}`);
|
|
27
|
+
pty.onData((data) => cb.onData(req.pane, data));
|
|
28
|
+
pty.exitCode
|
|
29
|
+
.then((code) => cb.onExit(req.pane, code))
|
|
30
|
+
.catch(() => cb.onExit(req.pane, -1));
|
|
31
|
+
},
|
|
32
|
+
write(pane, data) {
|
|
33
|
+
ptys.get(pane)?.write(data);
|
|
34
|
+
},
|
|
35
|
+
resize(pane, cols, rows) {
|
|
36
|
+
const key = `${cols}x${rows}`;
|
|
37
|
+
if (sizes.get(pane) === key)
|
|
38
|
+
return;
|
|
39
|
+
sizes.set(pane, key);
|
|
40
|
+
ptys.get(pane)?.resize(cols, rows);
|
|
41
|
+
},
|
|
42
|
+
kill(pane) {
|
|
43
|
+
const p = ptys.get(pane);
|
|
44
|
+
if (p === undefined)
|
|
45
|
+
return;
|
|
46
|
+
p.kill();
|
|
47
|
+
ptys.delete(pane);
|
|
48
|
+
sizes.delete(pane);
|
|
49
|
+
},
|
|
50
|
+
forget(pane) {
|
|
51
|
+
ptys.delete(pane);
|
|
52
|
+
sizes.delete(pane);
|
|
53
|
+
},
|
|
54
|
+
async killAll() {
|
|
55
|
+
const live = [...ptys.values()];
|
|
56
|
+
ptys.clear();
|
|
57
|
+
sizes.clear();
|
|
58
|
+
for (const p of live)
|
|
59
|
+
p.kill("SIGTERM");
|
|
60
|
+
// Wait briefly for clean exits, then hard-kill stragglers so a process
|
|
61
|
+
// that ignores SIGTERM can't hang shutdown forever.
|
|
62
|
+
const exits = live.map((p) => p.exitCode.catch(() => -1));
|
|
63
|
+
let timer;
|
|
64
|
+
const timedOut = await Promise.race([
|
|
65
|
+
Promise.allSettled(exits).then(() => false),
|
|
66
|
+
new Promise((resolve) => {
|
|
67
|
+
timer = setTimeout(() => resolve(true), 2000);
|
|
68
|
+
}),
|
|
69
|
+
]);
|
|
70
|
+
if (timer !== undefined)
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
if (timedOut) {
|
|
73
|
+
for (const p of live)
|
|
74
|
+
p.kill("SIGKILL");
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
has(pane) {
|
|
78
|
+
return ptys.has(pane);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mux server: owns engine state and the live PTYs, interprets reducer
|
|
3
|
+
* effects, and broadcasts the neutral scene + per-pane output to a connected
|
|
4
|
+
* frontend. It performs no rendering — that is the frontend's job — so the same
|
|
5
|
+
* server drives an ANSI TUI or a browser identically.
|
|
6
|
+
*
|
|
7
|
+
* This first cut serves a single connected frontend (the in-process runner);
|
|
8
|
+
* multi-client fanout and reattach snapshots come with the socket/WS transports.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { Chrome } from "../engine/geometry.ts";
|
|
13
|
+
import type { Action, Geom, MuxState, Pane, PaneId } from "../engine/types.ts";
|
|
14
|
+
import type { FrontendToServer, ServerToFrontend, Transport } from "../ipc/protocol.ts";
|
|
15
|
+
import type { PtyHost, PtyHostCallbacks } from "./pty-host.ts";
|
|
16
|
+
/** Resolves how to actually launch a pane's process. */
|
|
17
|
+
export type SpawnResolver = (pane: Pane, geom: Geom) => {
|
|
18
|
+
readonly command: string;
|
|
19
|
+
readonly args: readonly string[];
|
|
20
|
+
readonly cwd?: string;
|
|
21
|
+
readonly env?: Record<string, string>;
|
|
22
|
+
};
|
|
23
|
+
export type MuxServerOptions = {
|
|
24
|
+
readonly initialState: MuxState;
|
|
25
|
+
readonly resolveSpawn: SpawnResolver;
|
|
26
|
+
readonly chrome?: Chrome;
|
|
27
|
+
/** Override the PTY host (for tests / alternate backends). */
|
|
28
|
+
readonly createHost?: (cb: PtyHostCallbacks) => PtyHost;
|
|
29
|
+
/**
|
|
30
|
+
* Tear down the session when the last tab closes (default `true`). A TUI
|
|
31
|
+
* client wants this — the program ends with its last pane. A long-lived host
|
|
32
|
+
* (web, headless/remote daemon) sets it `false` so closing the last tab just
|
|
33
|
+
* leaves an empty multiplexer the client can repopulate.
|
|
34
|
+
*/
|
|
35
|
+
readonly exitOnEmpty?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Called after a pane's process exits on its own (and its `paneExited` has
|
|
38
|
+
* been applied). Lets an embedding host reconcile external bookkeeping — e.g.
|
|
39
|
+
* deleting the persisted session for a tab that closed when its agent quit.
|
|
40
|
+
*/
|
|
41
|
+
readonly onPaneExit?: (pane: PaneId) => void;
|
|
42
|
+
};
|
|
43
|
+
export type MuxServer = {
|
|
44
|
+
/** Attach a frontend transport (server sends scene/output, receives input).
|
|
45
|
+
* Single-viewer: a new transport replaces and closes the previous one. */
|
|
46
|
+
connect(transport: Transport<ServerToFrontend, FrontendToServer>): void;
|
|
47
|
+
/** Detach a transport if it is the current sink (e.g. its socket closed), so
|
|
48
|
+
* the server stops addressing a dead connection. */
|
|
49
|
+
disconnect(transport: Transport<ServerToFrontend, FrontendToServer>): void;
|
|
50
|
+
/** Dispatch an action from outside a frontend (e.g. an agent driver). */
|
|
51
|
+
dispatch(action: Action): void;
|
|
52
|
+
/** Change the reserved-region chrome at runtime (e.g. toggle a sidebar). */
|
|
53
|
+
setChrome(chrome: Chrome): void;
|
|
54
|
+
/** Current engine state (read-only snapshot). */
|
|
55
|
+
getState(): MuxState;
|
|
56
|
+
dispose(): Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
export declare const createServer: (opts: MuxServerOptions) => MuxServer;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
import * as geometry from "../engine/geometry.js";
|
|
3
|
+
import * as reducer from "../engine/reducer.js";
|
|
4
|
+
import * as diff from "../scene/diff.js";
|
|
5
|
+
import * as scene from "../scene/scene.js";
|
|
6
|
+
import * as ptyHost from "./pty-host.js";
|
|
7
|
+
/** Interim scroll behavior: forward key sequences to the focused pane's process
|
|
8
|
+
* until the server keeps its own VTerminal scrollback. */
|
|
9
|
+
const SCROLL_SEQ = {
|
|
10
|
+
up: "\x1b[A\x1b[A\x1b[A",
|
|
11
|
+
down: "\x1b[B\x1b[B\x1b[B",
|
|
12
|
+
pageUp: "\x1b[5~",
|
|
13
|
+
pageDown: "\x1b[6~",
|
|
14
|
+
home: "\x1b[H",
|
|
15
|
+
end: "\x1b[F",
|
|
16
|
+
};
|
|
17
|
+
export const createServer = (opts) => {
|
|
18
|
+
let baseChrome = opts.chrome ?? geometry.DEFAULT_CHROME;
|
|
19
|
+
let state = opts.initialState;
|
|
20
|
+
const exitOnEmpty = opts.exitOnEmpty ?? true;
|
|
21
|
+
// Chrome actually applied, with decorations dropped when the viewport is too
|
|
22
|
+
// small. Server and frontend both use this (it's carried in the scene).
|
|
23
|
+
const currentChrome = () => geometry.effectiveChrome(state.viewport, baseChrome);
|
|
24
|
+
let sink = null;
|
|
25
|
+
let lastScene = null;
|
|
26
|
+
let disposed = false;
|
|
27
|
+
// Panes whose async spawn is in flight, and those killed before it resolved.
|
|
28
|
+
const spawning = new Set();
|
|
29
|
+
const pendingKill = new Set();
|
|
30
|
+
const host = (opts.createHost ?? ptyHost.createPtyHost)({
|
|
31
|
+
onData: (pane, data) => sink?.send({ t: "output", pane, data }),
|
|
32
|
+
onExit: (pane, code) => {
|
|
33
|
+
host.forget(pane);
|
|
34
|
+
applyAction({ type: "paneExited", pane, code });
|
|
35
|
+
opts.onPaneExit?.(pane);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const activeGeoms = () => {
|
|
39
|
+
const tab = state.tabs[state.activeTab];
|
|
40
|
+
if (tab === undefined)
|
|
41
|
+
return new Map();
|
|
42
|
+
return geometry.computeTabGeoms(tab, state.viewport, currentChrome());
|
|
43
|
+
};
|
|
44
|
+
const contentSize = (geom) => ({
|
|
45
|
+
cols: geom
|
|
46
|
+
? Math.max(1, geom.width - 2)
|
|
47
|
+
: Math.max(1, state.viewport.cols - 2),
|
|
48
|
+
rows: geom
|
|
49
|
+
? Math.max(1, geom.height - 2)
|
|
50
|
+
: Math.max(1, state.viewport.rows - 2),
|
|
51
|
+
});
|
|
52
|
+
const spawnPane = async (paneId) => {
|
|
53
|
+
const pane = state.panes[paneId];
|
|
54
|
+
if (pane === undefined || host.has(paneId) || spawning.has(paneId))
|
|
55
|
+
return;
|
|
56
|
+
spawning.add(paneId);
|
|
57
|
+
try {
|
|
58
|
+
const geom = activeGeoms().get(paneId);
|
|
59
|
+
const { cols, rows } = contentSize(geom);
|
|
60
|
+
const spec = opts.resolveSpawn(pane, geom ?? { x: 0, y: 0, width: cols, height: rows });
|
|
61
|
+
await host.spawn({
|
|
62
|
+
pane: paneId,
|
|
63
|
+
command: spec.command,
|
|
64
|
+
args: spec.args,
|
|
65
|
+
cwd: spec.cwd,
|
|
66
|
+
env: spec.env,
|
|
67
|
+
cols,
|
|
68
|
+
rows,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
spawning.delete(paneId);
|
|
73
|
+
// If the pane was closed while its spawn was in flight, kill the freshly
|
|
74
|
+
// created process now so it isn't orphaned.
|
|
75
|
+
if (pendingKill.delete(paneId) && host.has(paneId))
|
|
76
|
+
host.kill(paneId);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const resizePtys = () => {
|
|
80
|
+
for (const [paneId, geom] of activeGeoms()) {
|
|
81
|
+
if (!host.has(paneId))
|
|
82
|
+
continue;
|
|
83
|
+
const { cols, rows } = contentSize(geom);
|
|
84
|
+
host.resize(paneId, cols, rows);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const broadcastScene = () => {
|
|
88
|
+
const next = scene.deriveScene(state, currentChrome());
|
|
89
|
+
const wasNull = lastScene === null;
|
|
90
|
+
const delta = diff.diffScene(lastScene, next);
|
|
91
|
+
lastScene = next;
|
|
92
|
+
if (delta !== null)
|
|
93
|
+
sink?.send({ t: "scene", full: wasNull, delta });
|
|
94
|
+
};
|
|
95
|
+
const runEffect = (effect) => {
|
|
96
|
+
switch (effect.type) {
|
|
97
|
+
case "spawnPty":
|
|
98
|
+
spawnPane(effect.pane).catch((err) => {
|
|
99
|
+
// Surface spawn failures in the pane instead of swallowing them; the
|
|
100
|
+
// pane stays closeable and shows why it didn't start.
|
|
101
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
102
|
+
sink?.send({
|
|
103
|
+
t: "output",
|
|
104
|
+
pane: effect.pane,
|
|
105
|
+
data: `\r\n[mux] failed to start pane: ${msg}\r\n`,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
break;
|
|
109
|
+
case "writePty":
|
|
110
|
+
host.write(effect.pane, effect.data);
|
|
111
|
+
break;
|
|
112
|
+
case "killPty":
|
|
113
|
+
if (host.has(effect.pane))
|
|
114
|
+
host.kill(effect.pane);
|
|
115
|
+
else if (spawning.has(effect.pane))
|
|
116
|
+
pendingKill.add(effect.pane);
|
|
117
|
+
break;
|
|
118
|
+
case "scrollPane":
|
|
119
|
+
host.write(effect.pane, SCROLL_SEQ[effect.action]);
|
|
120
|
+
break;
|
|
121
|
+
case "render":
|
|
122
|
+
// Broadcast happens after every batch; nothing extra to do.
|
|
123
|
+
break;
|
|
124
|
+
case "detach":
|
|
125
|
+
sink?.send({ t: "exit", code: 0 });
|
|
126
|
+
break;
|
|
127
|
+
case "exit":
|
|
128
|
+
// A long-lived host keeps serving an empty multiplexer; the post-batch
|
|
129
|
+
// broadcast pushes the now-tabless scene so the client can repopulate.
|
|
130
|
+
if (!exitOnEmpty)
|
|
131
|
+
break;
|
|
132
|
+
sink?.send({ t: "exit", code: 0 });
|
|
133
|
+
void dispose();
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const applyAction = (action) => {
|
|
138
|
+
if (disposed)
|
|
139
|
+
return;
|
|
140
|
+
const result = reducer.reduce(state, action);
|
|
141
|
+
state = result.state;
|
|
142
|
+
for (const effect of result.effects)
|
|
143
|
+
runEffect(effect);
|
|
144
|
+
resizePtys();
|
|
145
|
+
broadcastScene();
|
|
146
|
+
};
|
|
147
|
+
const handleFrontend = (msg) => {
|
|
148
|
+
switch (msg.t) {
|
|
149
|
+
case "attach":
|
|
150
|
+
state = { ...state, viewport: msg.viewport };
|
|
151
|
+
lastScene = null; // force a full scene to the freshly-attached frontend
|
|
152
|
+
resizePtys();
|
|
153
|
+
broadcastScene();
|
|
154
|
+
break;
|
|
155
|
+
case "action":
|
|
156
|
+
applyAction(msg.action);
|
|
157
|
+
break;
|
|
158
|
+
case "resize":
|
|
159
|
+
applyAction({
|
|
160
|
+
type: "resizeViewport",
|
|
161
|
+
cols: msg.viewport.cols,
|
|
162
|
+
rows: msg.viewport.rows,
|
|
163
|
+
});
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
// Cache the teardown promise so the un-awaited exit-effect dispose and the
|
|
168
|
+
// caller's awaited dispose() share one run and both await full teardown.
|
|
169
|
+
let disposePromise = null;
|
|
170
|
+
const dispose = () => {
|
|
171
|
+
if (disposePromise !== null)
|
|
172
|
+
return disposePromise;
|
|
173
|
+
disposed = true;
|
|
174
|
+
disposePromise = (async () => {
|
|
175
|
+
await host.killAll();
|
|
176
|
+
sink?.close();
|
|
177
|
+
})();
|
|
178
|
+
return disposePromise;
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
connect(transport) {
|
|
182
|
+
// Single-viewer: replace and close any prior sink so its socket is torn
|
|
183
|
+
// down rather than leaked on reconnect.
|
|
184
|
+
const previous = sink;
|
|
185
|
+
sink = transport;
|
|
186
|
+
lastScene = null; // the new viewer's first broadcast must be a full scene
|
|
187
|
+
transport.onMessage(handleFrontend);
|
|
188
|
+
if (previous !== null && previous !== transport)
|
|
189
|
+
previous.close();
|
|
190
|
+
},
|
|
191
|
+
disconnect(transport) {
|
|
192
|
+
if (sink === transport)
|
|
193
|
+
sink = null;
|
|
194
|
+
},
|
|
195
|
+
dispatch: applyAction,
|
|
196
|
+
setChrome(chrome) {
|
|
197
|
+
baseChrome = chrome;
|
|
198
|
+
resizePtys();
|
|
199
|
+
broadcastScene();
|
|
200
|
+
},
|
|
201
|
+
getState: () => state,
|
|
202
|
+
dispose,
|
|
203
|
+
};
|
|
204
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eserstack/mux",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/eser/stack",
|
|
8
|
+
"directory": "pkg/@eserstack/mux"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/**/*.js",
|
|
12
|
+
"dist/**/*.d.ts",
|
|
13
|
+
"dist/**/*.json"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/mod.d.ts",
|
|
18
|
+
"import": "./dist/mod.js"
|
|
19
|
+
},
|
|
20
|
+
"./engine": {
|
|
21
|
+
"types": "./dist/engine/mod.d.ts",
|
|
22
|
+
"import": "./dist/engine/mod.js"
|
|
23
|
+
},
|
|
24
|
+
"./keybindings": {
|
|
25
|
+
"types": "./dist/keybindings/mod.d.ts",
|
|
26
|
+
"import": "./dist/keybindings/mod.js"
|
|
27
|
+
},
|
|
28
|
+
"./scene": {
|
|
29
|
+
"types": "./dist/scene/mod.d.ts",
|
|
30
|
+
"import": "./dist/scene/mod.js"
|
|
31
|
+
},
|
|
32
|
+
"./server": {
|
|
33
|
+
"types": "./dist/server/server.d.ts",
|
|
34
|
+
"import": "./dist/server/server.js"
|
|
35
|
+
},
|
|
36
|
+
"./runner": {
|
|
37
|
+
"types": "./dist/runner/inprocess.d.ts",
|
|
38
|
+
"import": "./dist/runner/inprocess.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@eserstack/shell": "5.0.0",
|
|
43
|
+
"@eserstack/standards": "5.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@eserstack/test-kit": "5.0.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "node ../../../etc/scripts/build-library.ts"
|
|
50
|
+
}
|
|
6
51
|
}
|