@gjermundgaraba/clankermux 0.2.0 → 0.4.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/README.md +91 -30
- package/dist/client/attachment.d.ts +1 -0
- package/dist/client/attachment.js +1 -1
- package/dist/client/client.d.ts +123 -0
- package/dist/client/client.js +268 -0
- package/dist/client/connection.d.ts +17 -2
- package/dist/client/connection.js +21 -3
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.js +1 -1
- package/dist/client/mount.d.ts +45 -42
- package/dist/client/mount.js +77 -56
- package/dist/client/worker.d.ts +115 -46
- package/dist/client/worker.js +457 -218
- package/dist/proto/messages.d.ts +358 -11
- package/package.json +4 -3
package/dist/client/worker.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The engine side of a
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The engine side of a client: the connection, the attachments and their
|
|
3
|
+
* render state live in a worker; the page draws frames and reports input.
|
|
4
|
+
* One worker serves one `Client` and every terminal mounted from it.
|
|
5
|
+
* Imported as `@gjermundgaraba/clankermux/worker`, so a worker typechecked
|
|
6
|
+
* without the DOM library does not see the page's types.
|
|
6
7
|
*/
|
|
7
8
|
import { type CellPoint, type Frame, type KeyInput } from "../engine/index.ts";
|
|
8
|
-
import { type ErrorCode, type ErrorMessage, type Exit, type
|
|
9
|
+
import { type ErrorCode, type ErrorMessage, type Event, type Exit, type Peer, type Profile, type Session, type Size } from "../proto/index.ts";
|
|
9
10
|
import { type ErrorKind } from "./connection.ts";
|
|
10
11
|
/** Why the link to the session ended. `closed`: the connection closed
|
|
11
12
|
* (not a `CLOSED` frame, which the worker does not wait for when it
|
|
12
|
-
* detaches); `removed` and `
|
|
13
|
+
* detaches); `removed`, `stopping` and `detached` (another client's
|
|
14
|
+
* `detach`): the server's `CLOSED`; `exited`:
|
|
13
15
|
* the session's program exited; `no_such_session` and `engine_mismatch`:
|
|
14
16
|
* an `OPEN` refused; `error`: any other error, the server's or the
|
|
15
17
|
* client's own. */
|
|
16
|
-
export type LinkEnd = "closed" | "removed" | "stopping" | "exited" | "no_such_session" | "engine_mismatch" | "error";
|
|
17
|
-
/**
|
|
18
|
-
* attachment. */
|
|
18
|
+
export type LinkEnd = "closed" | "removed" | "stopping" | "detached" | "exited" | "no_such_session" | "engine_mismatch" | "error";
|
|
19
|
+
/** A terminal's link to its session, through the client's connection and
|
|
20
|
+
* the terminal's attachment. */
|
|
19
21
|
export type Link =
|
|
20
22
|
/** Opening a connection; `attempt` counts from 1 and starts again once
|
|
21
23
|
* a server answers. */
|
|
@@ -30,10 +32,10 @@ export type Link =
|
|
|
30
32
|
session: Session | undefined;
|
|
31
33
|
}
|
|
32
34
|
/** The link ended. `code` and `message` are the error's, when there is
|
|
33
|
-
* one
|
|
35
|
+
* one, and `message` the reason a `detach` gave; `exit` is the
|
|
36
|
+
* program's, for `exited`. `retry`: the worker
|
|
34
37
|
* reconnects or attaches again by itself, so `connecting` or
|
|
35
|
-
* `connected` follows; otherwise nothing does until the page attaches
|
|
36
|
-
* or creates. */
|
|
38
|
+
* `connected` follows; otherwise nothing does until the page attaches. */
|
|
37
39
|
| {
|
|
38
40
|
state: "ended";
|
|
39
41
|
reason: LinkEnd;
|
|
@@ -44,48 +46,67 @@ export type Link =
|
|
|
44
46
|
};
|
|
45
47
|
/** A failed request, as it crosses to the page. */
|
|
46
48
|
export interface Failure {
|
|
47
|
-
|
|
48
|
-
kind?: ErrorKind;
|
|
49
|
+
kind: ErrorKind;
|
|
49
50
|
message: string;
|
|
50
51
|
server?: ErrorMessage;
|
|
51
52
|
}
|
|
53
|
+
/** What a mounted terminal starts with. `active`: the user is looking at
|
|
54
|
+
* the page (below). */
|
|
55
|
+
export interface MountInit {
|
|
56
|
+
session: string | undefined;
|
|
57
|
+
viewport: Size;
|
|
58
|
+
profile: Profile;
|
|
59
|
+
active: boolean;
|
|
60
|
+
readOnly: boolean;
|
|
61
|
+
ackOnFocus: boolean;
|
|
62
|
+
}
|
|
52
63
|
/** Messages from the page to the worker. */
|
|
53
|
-
export type ToWorker =
|
|
54
|
-
/** `active`: the user is looking at the page (below). */
|
|
55
|
-
{
|
|
64
|
+
export type ToWorker = {
|
|
56
65
|
type: "init";
|
|
57
66
|
wasm: string;
|
|
58
67
|
url: string;
|
|
59
|
-
|
|
60
|
-
profile: Profile;
|
|
61
|
-
active: boolean;
|
|
62
|
-
session: string | undefined;
|
|
63
|
-
} | {
|
|
64
|
-
type: "attach";
|
|
65
|
-
session: string;
|
|
68
|
+
client: Peer | undefined;
|
|
66
69
|
}
|
|
67
|
-
/**
|
|
70
|
+
/** A protocol request, answered by a `reply` with its `id`. */
|
|
68
71
|
| {
|
|
69
|
-
type: "
|
|
72
|
+
type: "request";
|
|
70
73
|
id: number;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
method: string;
|
|
75
|
+
params: unknown;
|
|
76
|
+
}
|
|
77
|
+
/** Cancels the pending `wait` (or `send` with `wait`) of request `id`. */
|
|
78
|
+
| {
|
|
79
|
+
type: "cancel";
|
|
74
80
|
id: number;
|
|
81
|
+
}
|
|
82
|
+
/** The terminals, each by the page's number for it. */
|
|
83
|
+
| ({
|
|
84
|
+
type: "mount";
|
|
85
|
+
mount: number;
|
|
86
|
+
} & MountInit) | {
|
|
87
|
+
type: "unmount";
|
|
88
|
+
mount: number;
|
|
75
89
|
} | {
|
|
76
|
-
type: "
|
|
77
|
-
|
|
90
|
+
type: "attach";
|
|
91
|
+
mount: number;
|
|
92
|
+
session: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: "detach";
|
|
95
|
+
mount: number;
|
|
78
96
|
} | {
|
|
79
97
|
type: "key";
|
|
98
|
+
mount: number;
|
|
80
99
|
input: KeyInput;
|
|
81
100
|
} | {
|
|
82
101
|
type: "paste";
|
|
102
|
+
mount: number;
|
|
83
103
|
text: string;
|
|
84
104
|
}
|
|
85
105
|
/** The mouse on the canvas, `at` in cells of the viewport, fractions
|
|
86
106
|
* included; `time` in ms, for double and triple clicks. */
|
|
87
107
|
| {
|
|
88
108
|
type: "select";
|
|
109
|
+
mount: number;
|
|
89
110
|
action: "press" | "drag" | "release";
|
|
90
111
|
at: CellPoint;
|
|
91
112
|
time: number;
|
|
@@ -93,53 +114,101 @@ export type ToWorker =
|
|
|
93
114
|
/** Text as typed, which no key sent: a composition's, the emoji picker's. */
|
|
94
115
|
| {
|
|
95
116
|
type: "text";
|
|
117
|
+
mount: number;
|
|
96
118
|
text: string;
|
|
97
119
|
}
|
|
98
120
|
/** The wheel: `rows` through the history, up when negative. */
|
|
99
121
|
| {
|
|
100
|
-
type: "
|
|
122
|
+
type: "wheel";
|
|
123
|
+
mount: number;
|
|
101
124
|
rows: number;
|
|
102
125
|
}
|
|
126
|
+
/** The view through the history: `rows` from where it is, up when
|
|
127
|
+
* negative, or back to the live screen. */
|
|
128
|
+
| {
|
|
129
|
+
type: "view";
|
|
130
|
+
mount: number;
|
|
131
|
+
rows: number | "live";
|
|
132
|
+
}
|
|
103
133
|
/** The page's size and profile. Only an `active` page, one the user is
|
|
104
|
-
* looking at, reports them to the session: the
|
|
105
|
-
* latest report, so the session takes the size
|
|
134
|
+
* looking at, reports them to the session: under the `latest` policy
|
|
135
|
+
* the server applies the latest report, so the session takes the size
|
|
136
|
+
* of the page in use. */
|
|
106
137
|
| {
|
|
107
138
|
type: "viewport";
|
|
139
|
+
mount: number;
|
|
108
140
|
size: Size;
|
|
109
141
|
profile: Profile;
|
|
110
142
|
active: boolean;
|
|
111
143
|
}
|
|
144
|
+
/** The terminal has the keyboard, and its window the focus, or not. */
|
|
145
|
+
| {
|
|
146
|
+
type: "focus";
|
|
147
|
+
mount: number;
|
|
148
|
+
focused: boolean;
|
|
149
|
+
}
|
|
112
150
|
/** The page lost its drawing: send the whole screen again. */
|
|
113
151
|
| {
|
|
114
152
|
type: "repaint";
|
|
153
|
+
mount: number;
|
|
115
154
|
};
|
|
116
155
|
/** Messages from the worker to the page. */
|
|
117
|
-
export type ToPage =
|
|
156
|
+
export type ToPage =
|
|
157
|
+
/** The engine loaded: the client is usable. */
|
|
158
|
+
{
|
|
159
|
+
type: "ready";
|
|
160
|
+
}
|
|
161
|
+
/** The engine did not load; nothing else follows. */
|
|
162
|
+
| {
|
|
163
|
+
type: "failed";
|
|
164
|
+
message: string;
|
|
165
|
+
} | {
|
|
166
|
+
type: "reply";
|
|
167
|
+
id: number;
|
|
168
|
+
result?: unknown;
|
|
169
|
+
error?: Failure;
|
|
170
|
+
}
|
|
171
|
+
/** Every session on the server, at each change. */
|
|
172
|
+
| {
|
|
173
|
+
type: "sessions";
|
|
174
|
+
sessions: Session[];
|
|
175
|
+
} | {
|
|
176
|
+
type: "event";
|
|
177
|
+
event: Event;
|
|
178
|
+
}
|
|
179
|
+
/** Events were lost: the server restarted, or more happened while the
|
|
180
|
+
* connection was down than it retains. `sessions` was paged again. */
|
|
181
|
+
| {
|
|
182
|
+
type: "gap";
|
|
183
|
+
incarnation: string;
|
|
184
|
+
}
|
|
185
|
+
/** The connection's own link: `connecting`, `connected` with no
|
|
186
|
+
* session, or `ended`. */
|
|
187
|
+
| {
|
|
188
|
+
type: "connection";
|
|
189
|
+
link: Link;
|
|
190
|
+
} | {
|
|
118
191
|
type: "status";
|
|
192
|
+
mount: number;
|
|
119
193
|
text: string;
|
|
120
194
|
} | {
|
|
121
195
|
type: "link";
|
|
196
|
+
mount: number;
|
|
122
197
|
link: Link;
|
|
123
|
-
} | {
|
|
124
|
-
type: "done";
|
|
125
|
-
id: number;
|
|
126
|
-
session?: Session;
|
|
127
|
-
error?: Failure;
|
|
128
198
|
} | {
|
|
129
199
|
type: "frame";
|
|
200
|
+
mount: number;
|
|
130
201
|
frame: Frame;
|
|
131
|
-
} | {
|
|
132
|
-
type: "sessions";
|
|
133
|
-
sessions: Session[];
|
|
134
|
-
current: string | undefined;
|
|
135
202
|
} | {
|
|
136
203
|
type: "clipboard";
|
|
204
|
+
mount: number;
|
|
137
205
|
text: string;
|
|
138
206
|
}
|
|
139
207
|
/** The selection's text, or undefined once there is none; `copy`: the
|
|
140
208
|
* answer to a release, so the text (if any) goes to the clipboard. */
|
|
141
209
|
| {
|
|
142
210
|
type: "selection";
|
|
211
|
+
mount: number;
|
|
143
212
|
text: string | undefined;
|
|
144
213
|
copy: boolean;
|
|
145
214
|
};
|
|
@@ -148,6 +217,6 @@ export interface WorkerPort {
|
|
|
148
217
|
postMessage(message: ToPage): void;
|
|
149
218
|
onmessage: ((e: MessageEvent<ToWorker>) => void) | null;
|
|
150
219
|
}
|
|
151
|
-
/** Serves a page's `
|
|
152
|
-
*
|
|
220
|
+
/** Serves a page's `connect` on `port`: the worker module the page starts
|
|
221
|
+
* calls `runWorker(self)`. */
|
|
153
222
|
export declare function runWorker(port: WorkerPort): void;
|