@celljs/ta-host 4.17.0 → 4.19.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/esm/node/account-service.d.ts +73 -0
- package/esm/node/account-service.js +304 -0
- package/esm/node/app-commands.d.ts +1 -1
- package/esm/node/app-commands.js +46 -29
- package/esm/node/credentials.d.ts +12 -0
- package/esm/node/credentials.js +35 -0
- package/esm/node/host-protocol.d.ts +2 -0
- package/esm/node/host-protocol.js +2 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +3 -0
- package/esm/node/keep-awake.d.ts +3 -0
- package/esm/node/keep-awake.js +6 -1
- package/esm/node/package-hosts.d.ts +4 -0
- package/esm/node/package-hosts.js +18 -1
- package/esm/node/relay-bridge.js +1 -1
- package/esm/node/rooms-bridge.d.ts +10 -1
- package/esm/node/rooms-bridge.js +25 -0
- package/esm/node/screen-share/desktop-picture.d.ts +51 -0
- package/esm/node/screen-share/desktop-picture.js +133 -0
- package/esm/node/screen-share/desktop-session.d.ts +128 -0
- package/esm/node/screen-share/desktop-session.js +437 -0
- package/esm/node/screen-share/desktop-targets.d.ts +24 -0
- package/esm/node/screen-share/desktop-targets.js +80 -0
- package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
- package/esm/node/screen-share/desktop-viewer.js +339 -0
- package/esm/node/screen-share/index.d.ts +8 -0
- package/esm/node/screen-share/index.js +9 -0
- package/esm/node/screen-share/rfb-client.d.ts +54 -0
- package/esm/node/screen-share/rfb-client.js +179 -0
- package/esm/node/screen-share/rfb-des.d.ts +11 -0
- package/esm/node/screen-share/rfb-des.js +143 -0
- package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
- package/esm/node/screen-share/rfb-encodings.js +288 -0
- package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
- package/esm/node/screen-share/rfb-framebuffer.js +53 -0
- package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
- package/esm/node/screen-share/rfb-protocol.js +36 -0
- package/esm/node/screen-share/rfb-reader.d.ts +34 -0
- package/esm/node/screen-share/rfb-reader.js +110 -0
- package/esm/node/screen-share/rfb-security.d.ts +30 -0
- package/esm/node/screen-share/rfb-security.js +136 -0
- package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
- package/esm/node/screen-share/rfb-test-server.js +116 -0
- package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
- package/esm/node/screen-share/screen-share-server-impl.js +76 -0
- package/esm/node/screen-share/screen-shares.d.ts +123 -0
- package/esm/node/screen-share/screen-shares.js +463 -0
- package/esm/node/session-info-util.d.ts +10 -11
- package/esm/node/session-info-util.js +16 -94
- package/esm/node/settings-store.d.ts +1 -1
- package/esm/node/settings-store.js +7 -4
- package/esm/node/sign-in/access-store.d.ts +1 -1
- package/esm/node/sign-in/access-store.js +4 -1
- package/esm/node/sign-in/index.d.ts +2 -0
- package/esm/node/sign-in/index.js +2 -0
- package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
- package/esm/node/sign-in/polled-sign-in.js +83 -0
- package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
- package/esm/node/sign-in/sign-in-devices.js +113 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
- package/esm/node/sign-in/sign-in-flow.js +79 -4
- package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
- package/esm/node/sign-in/sign-in-pages.js +137 -8
- package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
- package/esm/node/sign-in/sign-in-provider.js +15 -0
- package/esm/node/sources-extension.d.ts +10 -0
- package/esm/node/sources-extension.js +18 -0
- package/esm/node/ta-server-impl.js +3 -3
- package/esm/node/ta-session-factory.js +2 -0
- package/esm/node/team/team-calls.js +35 -0
- package/esm/node/voice-bridge.d.ts +3 -1
- package/esm/node/voice-bridge.js +10 -3
- package/esm/node/voices-file.d.ts +5 -0
- package/esm/node/voices-file.js +14 -3
- package/esm/node/working-directory.d.ts +8 -2
- package/esm/node/working-directory.js +7 -0
- package/lib/node/account-service.d.ts +74 -0
- package/lib/node/account-service.js +307 -0
- package/lib/node/app-commands.d.ts +1 -1
- package/lib/node/app-commands.js +46 -29
- package/lib/node/credentials.d.ts +13 -0
- package/lib/node/credentials.js +38 -0
- package/lib/node/host-protocol.d.ts +2 -0
- package/lib/node/host-protocol.js +3 -1
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.js +3 -0
- package/lib/node/keep-awake.d.ts +3 -0
- package/lib/node/keep-awake.js +6 -1
- package/lib/node/package-hosts.d.ts +4 -0
- package/lib/node/package-hosts.js +17 -0
- package/lib/node/relay-bridge.js +1 -1
- package/lib/node/rooms-bridge.d.ts +10 -1
- package/lib/node/rooms-bridge.js +25 -0
- package/lib/node/screen-share/desktop-picture.d.ts +52 -0
- package/lib/node/screen-share/desktop-picture.js +136 -0
- package/lib/node/screen-share/desktop-session.d.ts +129 -0
- package/lib/node/screen-share/desktop-session.js +442 -0
- package/lib/node/screen-share/desktop-targets.d.ts +25 -0
- package/lib/node/screen-share/desktop-targets.js +84 -0
- package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
- package/lib/node/screen-share/desktop-viewer.js +343 -0
- package/lib/node/screen-share/index.d.ts +9 -0
- package/lib/node/screen-share/index.js +25 -0
- package/lib/node/screen-share/rfb-client.d.ts +55 -0
- package/lib/node/screen-share/rfb-client.js +183 -0
- package/lib/node/screen-share/rfb-des.d.ts +12 -0
- package/lib/node/screen-share/rfb-des.js +146 -0
- package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
- package/lib/node/screen-share/rfb-encodings.js +295 -0
- package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
- package/lib/node/screen-share/rfb-framebuffer.js +57 -0
- package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
- package/lib/node/screen-share/rfb-protocol.js +39 -0
- package/lib/node/screen-share/rfb-reader.d.ts +35 -0
- package/lib/node/screen-share/rfb-reader.js +115 -0
- package/lib/node/screen-share/rfb-security.d.ts +31 -0
- package/lib/node/screen-share/rfb-security.js +141 -0
- package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
- package/lib/node/screen-share/rfb-test-server.js +120 -0
- package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
- package/lib/node/screen-share/screen-share-server-impl.js +79 -0
- package/lib/node/screen-share/screen-shares.d.ts +124 -0
- package/lib/node/screen-share/screen-shares.js +464 -0
- package/lib/node/session-info-util.d.ts +10 -11
- package/lib/node/session-info-util.js +15 -93
- package/lib/node/settings-store.d.ts +1 -1
- package/lib/node/settings-store.js +6 -3
- package/lib/node/sign-in/access-store.d.ts +1 -1
- package/lib/node/sign-in/access-store.js +4 -1
- package/lib/node/sign-in/index.d.ts +2 -0
- package/lib/node/sign-in/index.js +2 -0
- package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
- package/lib/node/sign-in/polled-sign-in.js +87 -0
- package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
- package/lib/node/sign-in/sign-in-devices.js +117 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
- package/lib/node/sign-in/sign-in-flow.js +80 -5
- package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
- package/lib/node/sign-in/sign-in-pages.js +136 -7
- package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
- package/lib/node/sign-in/sign-in-provider.js +15 -0
- package/lib/node/sources-extension.d.ts +11 -0
- package/lib/node/sources-extension.js +22 -0
- package/lib/node/ta-server-impl.js +2 -2
- package/lib/node/ta-session-factory.js +2 -0
- package/lib/node/team/team-calls.js +35 -0
- package/lib/node/voice-bridge.d.ts +3 -1
- package/lib/node/voice-bridge.js +9 -2
- package/lib/node/voices-file.d.ts +5 -0
- package/lib/node/voices-file.js +14 -3
- package/lib/node/working-directory.d.ts +8 -2
- package/lib/node/working-directory.js +7 -0
- package/package.json +14 -10
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { DesktopPicture } from './desktop-picture.js';
|
|
2
|
+
/** How long a claim of the next frame waits for something to change before it answers `idle`. */
|
|
3
|
+
export const DESKTOP_READ_WAIT_MS = 10000;
|
|
4
|
+
/** Frames a viewer keeps, for a claim sent again: as many as a page may have claimed (its window). */
|
|
5
|
+
export const DESKTOP_KEPT_FRAMES = 4;
|
|
6
|
+
/** The least time between two changes of the mouse buttons sent to a desktop (apply). */
|
|
7
|
+
export const DESKTOP_BUTTON_GAP_MS = 20;
|
|
8
|
+
/** Notches of the wheel that may wait to be sent. */
|
|
9
|
+
const DESKTOP_QUEUED_NOTCHES = 8;
|
|
10
|
+
/** The buttons of RFB that are notches of the wheel. */
|
|
11
|
+
const WHEEL = 8 | 16 | 32 | 64;
|
|
12
|
+
const fresh = () => ({ tiles: new Set(), all: false, size: false, cursor: false, news: false });
|
|
13
|
+
/**
|
|
14
|
+
* One page looking at a desktop (docs/design/ta-desktop-remote.md 5.4): its view, what changed in it since its last
|
|
15
|
+
* frame, and its frames numbered from 1. A page claims frames by number, several at once: the next waits for a change,
|
|
16
|
+
* one beyond waits for the one before, so that no two claims get the same picture; the last frames are kept, so that a
|
|
17
|
+
* claim sent again gets what it got. Its input once it works the desktop.
|
|
18
|
+
*/
|
|
19
|
+
export class DesktopViewer {
|
|
20
|
+
constructor(id, connection, principal, clientMessageId, device, view) {
|
|
21
|
+
var _a;
|
|
22
|
+
this.id = id;
|
|
23
|
+
this.connection = connection;
|
|
24
|
+
this.principal = principal;
|
|
25
|
+
this.clientMessageId = clientMessageId;
|
|
26
|
+
this.device = device;
|
|
27
|
+
this.quality = 'auto';
|
|
28
|
+
/** The last frame made. */
|
|
29
|
+
this.built = 0;
|
|
30
|
+
this.since = Date.now();
|
|
31
|
+
/** The largest batch of input taken. */
|
|
32
|
+
this.inputSeq = 0;
|
|
33
|
+
this.pastes = new Set();
|
|
34
|
+
/** Mouse buttons held and keys down: let go when it loses control or goes. */
|
|
35
|
+
this.buttons = 0;
|
|
36
|
+
this.keys = new Set();
|
|
37
|
+
this.lastInputAt = 0;
|
|
38
|
+
/** Input not sent yet, and what of the buttons went last and when (apply). */
|
|
39
|
+
this.outgoing = [];
|
|
40
|
+
this.sentButtons = 0;
|
|
41
|
+
this.buttonsAt = 0;
|
|
42
|
+
/** What its last frame told of control and the link: told again only when it changes. */
|
|
43
|
+
this.told = {};
|
|
44
|
+
this.pending = { ...fresh(), all: true, size: true, cursor: true, news: true };
|
|
45
|
+
this.frames = new Map();
|
|
46
|
+
/** A claim came for a frame dropped: the next is whole. */
|
|
47
|
+
this.needsFull = false;
|
|
48
|
+
this.stopped = false;
|
|
49
|
+
this.lastBuiltAt = 0;
|
|
50
|
+
this.asked = view;
|
|
51
|
+
this.quality = (_a = view.quality) !== null && _a !== void 0 ? _a : 'auto';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Frame `want`, as docs/design/ta-desktop-remote.md 5.4 answers it. `minGapMs` keeps frames apart (the cap of
|
|
55
|
+
* frames a second); `showing` says whether the desktop has pictures to give.
|
|
56
|
+
*/
|
|
57
|
+
async claim(want, make, options) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const arrived = Date.now();
|
|
60
|
+
const kept = this.frames.get(want);
|
|
61
|
+
if (kept) {
|
|
62
|
+
return kept;
|
|
63
|
+
}
|
|
64
|
+
if (!Number.isInteger(want) || want <= this.built || want > this.built + DESKTOP_KEPT_FRAMES) {
|
|
65
|
+
if (Number.isInteger(want) && want <= this.built) {
|
|
66
|
+
this.needsFull = true;
|
|
67
|
+
}
|
|
68
|
+
return { seq: this.built, stale: true, waited: 0, tiles: [] };
|
|
69
|
+
}
|
|
70
|
+
if (want > this.built + 1) {
|
|
71
|
+
await this.claim(this.built + 1, make, options).catch(() => undefined);
|
|
72
|
+
if (this.stopped) {
|
|
73
|
+
return { seq: 0, unknown: true, waited: 0, tiles: [] };
|
|
74
|
+
}
|
|
75
|
+
// The one before came (or answered idle): this one waits its turn now.
|
|
76
|
+
return this.claim(want, make, options);
|
|
77
|
+
}
|
|
78
|
+
if (((_a = this.building) === null || _a === void 0 ? void 0 : _a.seq) === want) {
|
|
79
|
+
return this.building.frame;
|
|
80
|
+
}
|
|
81
|
+
const frame = this.build(want, arrived, make, options);
|
|
82
|
+
this.building = { seq: want, frame };
|
|
83
|
+
try {
|
|
84
|
+
return await frame;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
if (((_b = this.building) === null || _b === void 0 ? void 0 : _b.frame) === frame) {
|
|
88
|
+
this.building = undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async build(want, arrived, make, options) {
|
|
93
|
+
const deadline = arrived + DESKTOP_READ_WAIT_MS;
|
|
94
|
+
for (;;) {
|
|
95
|
+
if (this.stopped) {
|
|
96
|
+
return { seq: 0, unknown: true, waited: 0, tiles: [] };
|
|
97
|
+
}
|
|
98
|
+
const showing = options.showing();
|
|
99
|
+
if ((this.needsFull && showing) || (showing ? this.ready : this.pending.news)) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
const left = deadline - Date.now();
|
|
103
|
+
if (left <= 0) {
|
|
104
|
+
return { seq: this.built, idle: true, waited: Date.now() - arrived, tiles: [] };
|
|
105
|
+
}
|
|
106
|
+
await this.wait(left);
|
|
107
|
+
}
|
|
108
|
+
// Frames no closer than the cap allows: what changes meanwhile goes in this one.
|
|
109
|
+
const gap = this.lastBuiltAt + options.minGapMs - Date.now();
|
|
110
|
+
if (gap > 0) {
|
|
111
|
+
await new Promise(resolve => setTimeout(resolve, gap));
|
|
112
|
+
}
|
|
113
|
+
const whole = this.needsFull || this.pending.all;
|
|
114
|
+
if (this.needsFull) {
|
|
115
|
+
this.needsFull = false;
|
|
116
|
+
this.pending.all = true;
|
|
117
|
+
}
|
|
118
|
+
const seq = want;
|
|
119
|
+
this.built = seq;
|
|
120
|
+
this.lastBuiltAt = Date.now();
|
|
121
|
+
const frame = make(this, { seq, whole, waited: this.lastBuiltAt - arrived });
|
|
122
|
+
this.frames.set(seq, frame);
|
|
123
|
+
for (const old of this.frames.keys()) {
|
|
124
|
+
if (old <= seq - DESKTOP_KEPT_FRAMES) {
|
|
125
|
+
this.frames.delete(old);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return frame;
|
|
129
|
+
}
|
|
130
|
+
/** The view a page asks for; a later revision only. */
|
|
131
|
+
setView(view, framebuffer, screen) {
|
|
132
|
+
if (typeof (view === null || view === void 0 ? void 0 : view.revision) !== 'number' || view.revision < this.asked.revision) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
this.asked = view;
|
|
136
|
+
this.quality = view.quality === 'crisp' || view.quality === 'smooth' ? view.quality : 'auto';
|
|
137
|
+
this.fit(framebuffer, screen);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
/** The view fitted to the framebuffer (and the screen asked for): again whenever its size changes. */
|
|
141
|
+
fit(framebuffer, screen) {
|
|
142
|
+
var _a;
|
|
143
|
+
if (framebuffer.width < 1 || framebuffer.height < 1) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const next = DesktopPicture.fit(framebuffer, { ...this.asked, rect: (_a = this.asked.rect) !== null && _a !== void 0 ? _a : screen });
|
|
147
|
+
const now = this.view;
|
|
148
|
+
const same = now &&
|
|
149
|
+
now.width === next.width &&
|
|
150
|
+
now.height === next.height &&
|
|
151
|
+
now.rect.x === next.rect.x &&
|
|
152
|
+
now.rect.y === next.rect.y &&
|
|
153
|
+
now.rect.w === next.rect.w &&
|
|
154
|
+
now.rect.h === next.rect.h;
|
|
155
|
+
if (!same) {
|
|
156
|
+
this.view = next;
|
|
157
|
+
this.pending.all = true;
|
|
158
|
+
this.notify();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
damage(rect) {
|
|
162
|
+
if (!this.view || this.pending.all) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
for (const tile of DesktopPicture.touched(this.view, rect)) {
|
|
166
|
+
this.pending.tiles.add(tile);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
sized() {
|
|
170
|
+
this.pending.size = true;
|
|
171
|
+
this.pending.all = true;
|
|
172
|
+
}
|
|
173
|
+
cursorChanged() {
|
|
174
|
+
this.pending.cursor = true;
|
|
175
|
+
}
|
|
176
|
+
/** Something its page should hear of (control, the link). */
|
|
177
|
+
news() {
|
|
178
|
+
this.pending.news = true;
|
|
179
|
+
this.notify();
|
|
180
|
+
}
|
|
181
|
+
/** An update of the desktop ended: a claim that waits answers now. */
|
|
182
|
+
updated() {
|
|
183
|
+
if (this.ready) {
|
|
184
|
+
this.notify();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
get ready() {
|
|
188
|
+
const { pending } = this;
|
|
189
|
+
return pending.all || pending.tiles.size > 0 || pending.size || pending.cursor || pending.news;
|
|
190
|
+
}
|
|
191
|
+
/** Ends what waits: the viewer closed. */
|
|
192
|
+
stop() {
|
|
193
|
+
this.stopped = true;
|
|
194
|
+
clearTimeout(this.pacing);
|
|
195
|
+
this.pacing = undefined;
|
|
196
|
+
this.outgoing = [];
|
|
197
|
+
this.notify();
|
|
198
|
+
}
|
|
199
|
+
/** What it has to tell, taken: the next frame starts from nothing. */
|
|
200
|
+
take() {
|
|
201
|
+
const taken = this.pending;
|
|
202
|
+
this.pending = fresh();
|
|
203
|
+
return taken;
|
|
204
|
+
}
|
|
205
|
+
/** What it took and could not tell (the view changed while it was made): told with the next. */
|
|
206
|
+
putBack(taken) {
|
|
207
|
+
var _a, _b, _c, _d;
|
|
208
|
+
(_a = this.pending).all || (_a.all = taken.all);
|
|
209
|
+
(_b = this.pending).size || (_b.size = taken.size);
|
|
210
|
+
(_c = this.pending).cursor || (_c.cursor = taken.cursor);
|
|
211
|
+
(_d = this.pending).news || (_d.news = taken.news);
|
|
212
|
+
for (const tile of taken.tiles) {
|
|
213
|
+
this.pending.tiles.add(tile);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The JPEG quality for this many tiles of the view: the whole screen changing (a scroll, a video) at less, so that
|
|
218
|
+
* frames keep coming; a little change crisper. `crisp` and `smooth` hold it up or down.
|
|
219
|
+
*/
|
|
220
|
+
qualityFor(tiles) {
|
|
221
|
+
if (this.quality === 'crisp') {
|
|
222
|
+
return 85;
|
|
223
|
+
}
|
|
224
|
+
if (this.quality === 'smooth') {
|
|
225
|
+
return 50;
|
|
226
|
+
}
|
|
227
|
+
const { columns, rows } = this.view ? DesktopPicture.grid(this.view) : { columns: 1, rows: 1 };
|
|
228
|
+
return tiles > columns * rows * 0.25 ? 60 : 80;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Input of a batch into RFB, in the framebuffer's coordinates; keys and buttons it holds are remembered. It goes in
|
|
232
|
+
* order, each change of the buttons (a press, a release, a notch of the wheel) DESKTOP_BUTTON_GAP_MS after the one
|
|
233
|
+
* before: the Screen Sharing of macOS keeps only the last state of the pointer of what comes at once, so that a
|
|
234
|
+
* click sent in one batch never clicked.
|
|
235
|
+
*/
|
|
236
|
+
apply(client, events) {
|
|
237
|
+
this.client = client;
|
|
238
|
+
for (const event of events) {
|
|
239
|
+
if (event.kind === 'pointer') {
|
|
240
|
+
this.buttons = (Number(event.buttons) || 0) & 7;
|
|
241
|
+
this.outgoing.push({ kind: 'pointer', x: Number(event.x) || 0, y: Number(event.y) || 0, buttons: this.buttons });
|
|
242
|
+
}
|
|
243
|
+
else if (event.kind === 'wheel') {
|
|
244
|
+
const x = Number(event.x) || 0;
|
|
245
|
+
const y = Number(event.y) || 0;
|
|
246
|
+
// RFB scrolls by buttons 4 and 5 (up, down), 6 and 7 (left, right), each a press and a release a notch;
|
|
247
|
+
// notches beyond those waiting already are dropped, so that a scroll stops when the fingers do.
|
|
248
|
+
let room = DESKTOP_QUEUED_NOTCHES - this.outgoing.filter(one => one.kind === 'pointer' && one.buttons & WHEEL).length;
|
|
249
|
+
const notch = (count, bit) => {
|
|
250
|
+
for (let index = 0; index < count && room > 0; index++, room--) {
|
|
251
|
+
this.outgoing.push({ kind: 'pointer', x, y, buttons: this.buttons | bit }, { kind: 'pointer', x, y, buttons: this.buttons });
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const notches = (delta) => Math.min(10, Math.max(0, Math.round(Math.abs(delta))));
|
|
255
|
+
const vertical = Number(event.dy) || 0;
|
|
256
|
+
const horizontal = Number(event.dx) || 0;
|
|
257
|
+
notch(notches(vertical), vertical < 0 ? 8 : 16);
|
|
258
|
+
notch(notches(horizontal), horizontal < 0 ? 32 : 64);
|
|
259
|
+
}
|
|
260
|
+
else if (event.kind === 'key') {
|
|
261
|
+
const keysym = Number(event.keysym) >>> 0;
|
|
262
|
+
if (!keysym) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (event.down) {
|
|
266
|
+
this.keys.add(keysym);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
this.keys.delete(keysym);
|
|
270
|
+
}
|
|
271
|
+
this.outgoing.push({ kind: 'key', keysym, down: !!event.down });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
this.lastInputAt = Date.now();
|
|
275
|
+
this.send();
|
|
276
|
+
}
|
|
277
|
+
/** Lets go of what it holds: it lost control, or closed. */
|
|
278
|
+
letGo(client, at) {
|
|
279
|
+
clearTimeout(this.pacing);
|
|
280
|
+
this.pacing = undefined;
|
|
281
|
+
this.outgoing = [];
|
|
282
|
+
if (client) {
|
|
283
|
+
for (const keysym of this.keys) {
|
|
284
|
+
client.key(keysym, false);
|
|
285
|
+
}
|
|
286
|
+
if (this.sentButtons) {
|
|
287
|
+
client.pointer(at.x, at.y, 0);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
this.keys.clear();
|
|
291
|
+
this.buttons = 0;
|
|
292
|
+
this.sentButtons = 0;
|
|
293
|
+
}
|
|
294
|
+
/** Sends what waits, up to a change of the buttons too soon after the last: the rest goes when it may. */
|
|
295
|
+
send() {
|
|
296
|
+
clearTimeout(this.pacing);
|
|
297
|
+
this.pacing = undefined;
|
|
298
|
+
const client = this.client;
|
|
299
|
+
while (client && this.outgoing.length > 0) {
|
|
300
|
+
const next = this.outgoing[0];
|
|
301
|
+
if (next.kind === 'pointer' && next.buttons !== this.sentButtons) {
|
|
302
|
+
const wait = this.buttonsAt + DESKTOP_BUTTON_GAP_MS - Date.now();
|
|
303
|
+
if (wait > 0) {
|
|
304
|
+
this.pacing = setTimeout(() => this.send(), wait);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this.buttonsAt = Date.now();
|
|
308
|
+
}
|
|
309
|
+
this.outgoing.shift();
|
|
310
|
+
if (next.kind === 'pointer') {
|
|
311
|
+
this.sentButtons = next.buttons;
|
|
312
|
+
client.pointer(next.x, next.y, next.buttons);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
client.key(next.keysym, next.down);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
wait(ms) {
|
|
320
|
+
return new Promise(resolve => {
|
|
321
|
+
const timer = setTimeout(done, ms);
|
|
322
|
+
const previous = this.wake;
|
|
323
|
+
function done() {
|
|
324
|
+
clearTimeout(timer);
|
|
325
|
+
resolve();
|
|
326
|
+
}
|
|
327
|
+
this.wake = () => {
|
|
328
|
+
previous === null || previous === void 0 ? void 0 : previous();
|
|
329
|
+
done();
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
notify() {
|
|
334
|
+
const wake = this.wake;
|
|
335
|
+
this.wake = undefined;
|
|
336
|
+
wake === null || wake === void 0 ? void 0 : wake();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=desktop-viewer.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './desktop-picture.js';
|
|
2
|
+
export * from './desktop-session.js';
|
|
3
|
+
export * from './desktop-targets.js';
|
|
4
|
+
export * from './desktop-viewer.js';
|
|
5
|
+
export * from './rfb-client.js';
|
|
6
|
+
export * from './rfb-protocol.js';
|
|
7
|
+
export * from './screen-share-server-impl.js';
|
|
8
|
+
export * from './screen-shares.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './desktop-picture.js';
|
|
2
|
+
export * from './desktop-session.js';
|
|
3
|
+
export * from './desktop-targets.js';
|
|
4
|
+
export * from './desktop-viewer.js';
|
|
5
|
+
export * from './rfb-client.js';
|
|
6
|
+
export * from './rfb-protocol.js';
|
|
7
|
+
export * from './screen-share-server-impl.js';
|
|
8
|
+
export * from './screen-shares.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ExecSocket } from '@celljs/ta-exec';
|
|
2
|
+
import { RfbDecoders } from './rfb-encodings.js';
|
|
3
|
+
import { RfbFramebuffer } from './rfb-framebuffer.js';
|
|
4
|
+
import { type RfbClientEvents, type RfbClientOptions, type RfbScreen } from './rfb-protocol.js';
|
|
5
|
+
import { RfbReader } from './rfb-reader.js';
|
|
6
|
+
/** What a server said it is once Ta was let in. */
|
|
7
|
+
export interface RfbServerInit {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A client of RFB 3.8 (also 3.7 and 3.3) on a socket of an ExecEnvironment (docs/design/ta-desktop-remote.md 3): signs
|
|
14
|
+
* in, keeps the framebuffer, and asks for the next update only when the last has been taken (`request`), which is
|
|
15
|
+
* all the flow control RFB has.
|
|
16
|
+
*/
|
|
17
|
+
export declare class RfbClient {
|
|
18
|
+
protected readonly socket: ExecSocket;
|
|
19
|
+
protected readonly options: RfbClientOptions;
|
|
20
|
+
readonly reader: RfbReader;
|
|
21
|
+
readonly framebuffer: RfbFramebuffer;
|
|
22
|
+
screens: RfbScreen[];
|
|
23
|
+
/** The server told its screens (ExtendedDesktopSize). */
|
|
24
|
+
extended: boolean;
|
|
25
|
+
name: string;
|
|
26
|
+
protected decoders?: RfbDecoders;
|
|
27
|
+
protected closed: boolean;
|
|
28
|
+
protected events?: RfbClientEvents;
|
|
29
|
+
/** An update was asked for and has not come. */
|
|
30
|
+
protected asked: boolean;
|
|
31
|
+
constructor(socket: ExecSocket, options: RfbClientOptions);
|
|
32
|
+
/** Signs in and reads the first size; `run` then reads updates. */
|
|
33
|
+
connect(): Promise<RfbServerInit>;
|
|
34
|
+
/** Reads what the server sends until the connection ends; the first update asked is the whole screen. */
|
|
35
|
+
run(events: RfbClientEvents): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Asks for the next update: incremental, what changed since the last; the server answers once something did. One
|
|
38
|
+
* at a time: a page that is slow asks later, and what changed meanwhile comes as one.
|
|
39
|
+
*/
|
|
40
|
+
request(incremental?: boolean): void;
|
|
41
|
+
pointer(x: number, y: number, buttons: number): void;
|
|
42
|
+
key(keysym: number, down: boolean): void;
|
|
43
|
+
/** Text into the clipboard of the desktop: Latin-1, as RFB has it; other characters become ?. */
|
|
44
|
+
clipboard(text: string): void;
|
|
45
|
+
protected closedByUs: boolean;
|
|
46
|
+
close(): void;
|
|
47
|
+
/** Ended by Ta, not lost: `closed` says no error. */
|
|
48
|
+
end(): void;
|
|
49
|
+
protected update(events: RfbClientEvents): Promise<void>;
|
|
50
|
+
protected resize(width: number, height: number, screens: RfbScreen[]): void;
|
|
51
|
+
protected colourMap(): Promise<void>;
|
|
52
|
+
protected cutText(): Promise<string>;
|
|
53
|
+
protected send(bytes: Uint8Array): void;
|
|
54
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { RfbDecoders } from './rfb-encodings.js';
|
|
2
|
+
import { RfbFramebuffer } from './rfb-framebuffer.js';
|
|
3
|
+
import { Rfb } from './rfb-protocol.js';
|
|
4
|
+
import { RfbBytes, RfbClosedError, RfbReader } from './rfb-reader.js';
|
|
5
|
+
import { RfbSecurity } from './rfb-security.js';
|
|
6
|
+
/**
|
|
7
|
+
* A client of RFB 3.8 (also 3.7 and 3.3) on a socket of an ExecEnvironment (docs/design/ta-desktop-remote.md 3): signs
|
|
8
|
+
* in, keeps the framebuffer, and asks for the next update only when the last has been taken (`request`), which is
|
|
9
|
+
* all the flow control RFB has.
|
|
10
|
+
*/
|
|
11
|
+
export class RfbClient {
|
|
12
|
+
constructor(socket, options) {
|
|
13
|
+
this.socket = socket;
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.framebuffer = new RfbFramebuffer(0, 0);
|
|
16
|
+
this.screens = [];
|
|
17
|
+
/** The server told its screens (ExtendedDesktopSize). */
|
|
18
|
+
this.extended = false;
|
|
19
|
+
this.name = '';
|
|
20
|
+
this.closed = false;
|
|
21
|
+
/** An update was asked for and has not come. */
|
|
22
|
+
this.asked = false;
|
|
23
|
+
this.closedByUs = false;
|
|
24
|
+
this.reader = new RfbReader(socket);
|
|
25
|
+
}
|
|
26
|
+
/** Signs in and reads the first size; `run` then reads updates. */
|
|
27
|
+
async connect() {
|
|
28
|
+
const version = new TextDecoder().decode(await this.reader.read(12));
|
|
29
|
+
const match = /^RFB (\d{3})\.(\d{3})\n$/.exec(version);
|
|
30
|
+
if (!match) {
|
|
31
|
+
throw new RfbClosedError('What answered is not a VNC server.');
|
|
32
|
+
}
|
|
33
|
+
const major = Number(match[1]);
|
|
34
|
+
const offered = Number(match[2]);
|
|
35
|
+
const minor = major > 3 || offered >= 8 ? 8 : offered >= 7 ? 7 : 3;
|
|
36
|
+
this.send(new TextEncoder().encode(`RFB 003.00${minor}\n`));
|
|
37
|
+
await new RfbSecurity(this.reader, bytes => this.send(bytes), this.options).negotiate(minor);
|
|
38
|
+
this.send(Uint8Array.of(this.options.shared === false ? 0 : 1));
|
|
39
|
+
const width = await this.reader.u16();
|
|
40
|
+
const height = await this.reader.u16();
|
|
41
|
+
await this.reader.read(16);
|
|
42
|
+
const nameLength = await this.reader.u32();
|
|
43
|
+
if (nameLength > Rfb.MAX_TEXT) {
|
|
44
|
+
throw new RfbClosedError('The desktop sent a name too long to read.');
|
|
45
|
+
}
|
|
46
|
+
this.name = new TextDecoder().decode(await this.reader.read(nameLength));
|
|
47
|
+
this.resize(width, height, []);
|
|
48
|
+
this.send(Uint8Array.of(Rfb.ClientMessage.SET_PIXEL_FORMAT, 0, 0, 0, ...Rfb.PIXEL_FORMAT));
|
|
49
|
+
this.send(Uint8Array.of(Rfb.ClientMessage.SET_ENCODINGS, 0, ...RfbBytes.u16(Rfb.ENCODINGS.length), ...Rfb.ENCODINGS.flatMap(one => RfbBytes.s32(one))));
|
|
50
|
+
this.decoders = new RfbDecoders(this.reader, this.framebuffer);
|
|
51
|
+
return { width, height, name: this.name };
|
|
52
|
+
}
|
|
53
|
+
/** Reads what the server sends until the connection ends; the first update asked is the whole screen. */
|
|
54
|
+
async run(events) {
|
|
55
|
+
this.events = events;
|
|
56
|
+
events.size(this.framebuffer.width, this.framebuffer.height, this.screens);
|
|
57
|
+
this.request(false);
|
|
58
|
+
try {
|
|
59
|
+
for (;;) {
|
|
60
|
+
const type = await this.reader.u8();
|
|
61
|
+
switch (type) {
|
|
62
|
+
case Rfb.ServerMessage.FRAMEBUFFER_UPDATE:
|
|
63
|
+
await this.update(events);
|
|
64
|
+
break;
|
|
65
|
+
case Rfb.ServerMessage.COLOUR_MAP:
|
|
66
|
+
await this.colourMap();
|
|
67
|
+
break;
|
|
68
|
+
case Rfb.ServerMessage.BELL:
|
|
69
|
+
events.bell();
|
|
70
|
+
break;
|
|
71
|
+
case Rfb.ServerMessage.CUT_TEXT:
|
|
72
|
+
events.clipboard(await this.cutText());
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
throw new RfbClosedError(`The desktop sent a message Ta does not know (${type}).`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this.close();
|
|
81
|
+
events.closed(this.closedByUs ? undefined : error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Asks for the next update: incremental, what changed since the last; the server answers once something did. One
|
|
86
|
+
* at a time: a page that is slow asks later, and what changed meanwhile comes as one.
|
|
87
|
+
*/
|
|
88
|
+
request(incremental = true) {
|
|
89
|
+
if (this.closed || this.asked) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.asked = true;
|
|
93
|
+
const { width, height } = this.framebuffer;
|
|
94
|
+
this.send(Uint8Array.of(Rfb.ClientMessage.UPDATE_REQUEST, incremental ? 1 : 0, 0, 0, 0, 0, ...RfbBytes.u16(width), ...RfbBytes.u16(height)));
|
|
95
|
+
}
|
|
96
|
+
pointer(x, y, buttons) {
|
|
97
|
+
const { width, height } = this.framebuffer;
|
|
98
|
+
const px = Math.max(0, Math.min(width - 1, Math.round(x)));
|
|
99
|
+
const py = Math.max(0, Math.min(height - 1, Math.round(y)));
|
|
100
|
+
this.send(Uint8Array.of(Rfb.ClientMessage.POINTER, buttons & 255, ...RfbBytes.u16(px), ...RfbBytes.u16(py)));
|
|
101
|
+
}
|
|
102
|
+
key(keysym, down) {
|
|
103
|
+
this.send(Uint8Array.of(Rfb.ClientMessage.KEY, down ? 1 : 0, 0, 0, ...RfbBytes.u32(keysym)));
|
|
104
|
+
}
|
|
105
|
+
/** Text into the clipboard of the desktop: Latin-1, as RFB has it; other characters become ?. */
|
|
106
|
+
clipboard(text) {
|
|
107
|
+
const bytes = Uint8Array.from([...text.slice(0, Rfb.MAX_TEXT)].map(char => { var _a, _b; return (((_a = char.codePointAt(0)) !== null && _a !== void 0 ? _a : 63) <= 255 ? ((_b = char.codePointAt(0)) !== null && _b !== void 0 ? _b : 63) : 63); }));
|
|
108
|
+
this.send(Uint8Array.of(Rfb.ClientMessage.CUT_TEXT, 0, 0, 0, ...RfbBytes.u32(bytes.length)));
|
|
109
|
+
this.send(bytes);
|
|
110
|
+
}
|
|
111
|
+
close() {
|
|
112
|
+
if (!this.closed) {
|
|
113
|
+
this.closed = true;
|
|
114
|
+
this.closedByUs || (this.closedByUs = !this.events);
|
|
115
|
+
this.socket.end();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Ended by Ta, not lost: `closed` says no error. */
|
|
119
|
+
end() {
|
|
120
|
+
this.closedByUs = true;
|
|
121
|
+
this.close();
|
|
122
|
+
this.reader.end(new RfbClosedError('Closed.'));
|
|
123
|
+
}
|
|
124
|
+
async update(events) {
|
|
125
|
+
var _a;
|
|
126
|
+
await this.reader.read(1);
|
|
127
|
+
const count = await this.reader.u16();
|
|
128
|
+
const decoders = this.decoders;
|
|
129
|
+
for (let index = 0; index < count; index++) {
|
|
130
|
+
const rect = { x: await this.reader.u16(), y: await this.reader.u16(), w: await this.reader.u16(), h: await this.reader.u16() };
|
|
131
|
+
const encoding = await this.reader.s32();
|
|
132
|
+
const result = await decoders.read(rect, encoding);
|
|
133
|
+
if (result.kind === 'last') {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (result.kind === 'pixels') {
|
|
137
|
+
events.damage(rect);
|
|
138
|
+
}
|
|
139
|
+
else if (result.kind === 'cursor') {
|
|
140
|
+
events.cursor(result.cursor);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.resize(result.width, result.height, (_a = result.screens) !== null && _a !== void 0 ? _a : []);
|
|
144
|
+
events.size(this.framebuffer.width, this.framebuffer.height, this.screens);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.asked = false;
|
|
148
|
+
events.update();
|
|
149
|
+
}
|
|
150
|
+
resize(width, height, screens) {
|
|
151
|
+
if (width < 1 || height < 1 || width > Rfb.MAX_SIDE || height > Rfb.MAX_SIDE) {
|
|
152
|
+
throw new RfbClosedError(`The desktop says it is ${width} by ${height}.`);
|
|
153
|
+
}
|
|
154
|
+
if (width !== this.framebuffer.width || height !== this.framebuffer.height) {
|
|
155
|
+
this.framebuffer.resize(width, height);
|
|
156
|
+
}
|
|
157
|
+
this.extended || (this.extended = screens.length > 0);
|
|
158
|
+
this.screens = screens.length ? screens : [{ id: 0, x: 0, y: 0, width, height }];
|
|
159
|
+
}
|
|
160
|
+
async colourMap() {
|
|
161
|
+
await this.reader.read(3);
|
|
162
|
+
const count = await this.reader.u16();
|
|
163
|
+
await this.reader.read(count * 6);
|
|
164
|
+
}
|
|
165
|
+
async cutText() {
|
|
166
|
+
await this.reader.read(3);
|
|
167
|
+
const length = await this.reader.u32();
|
|
168
|
+
if (length > Rfb.MAX_TEXT) {
|
|
169
|
+
throw new RfbClosedError('The desktop sent a clipboard too long to read.');
|
|
170
|
+
}
|
|
171
|
+
return new TextDecoder('latin1').decode(await this.reader.read(length));
|
|
172
|
+
}
|
|
173
|
+
send(bytes) {
|
|
174
|
+
if (!this.closed) {
|
|
175
|
+
this.socket.write(bytes);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=rfb-client.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DES of one block, as VNC Authentication needs it (RFB 3.8, 7.2.2): the challenge of 16 bytes encrypted with the
|
|
3
|
+
* password as the key, each byte of the key with its bits reversed. Written here because the OpenSSL of Node.js 17+
|
|
4
|
+
* keeps DES in its legacy provider, which is off; it encrypts 16 bytes once per sign-in, so speed does not matter.
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace RfbDes {
|
|
7
|
+
/** One block of 8 bytes encrypted with a key of 8 bytes (its parity bits ignored). */
|
|
8
|
+
function encryptBlock(key: Uint8Array, block: Uint8Array): Uint8Array;
|
|
9
|
+
/** The answer to the challenge of VNC Authentication: the password, cut or padded to 8 bytes, with its bits reversed. */
|
|
10
|
+
function vncResponse(password: string, challenge: Uint8Array): Uint8Array;
|
|
11
|
+
}
|