@celljs/ta-host 4.17.0 → 4.18.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.
Files changed (143) hide show
  1. package/esm/node/app-commands.d.ts +1 -1
  2. package/esm/node/app-commands.js +46 -29
  3. package/esm/node/credentials.d.ts +12 -0
  4. package/esm/node/credentials.js +35 -0
  5. package/esm/node/index.d.ts +2 -0
  6. package/esm/node/index.js +2 -0
  7. package/esm/node/keep-awake.d.ts +3 -0
  8. package/esm/node/keep-awake.js +6 -1
  9. package/esm/node/package-hosts.d.ts +2 -0
  10. package/esm/node/package-hosts.js +6 -0
  11. package/esm/node/rooms-bridge.d.ts +10 -1
  12. package/esm/node/rooms-bridge.js +25 -0
  13. package/esm/node/screen-share/desktop-picture.d.ts +51 -0
  14. package/esm/node/screen-share/desktop-picture.js +133 -0
  15. package/esm/node/screen-share/desktop-session.d.ts +128 -0
  16. package/esm/node/screen-share/desktop-session.js +437 -0
  17. package/esm/node/screen-share/desktop-targets.d.ts +24 -0
  18. package/esm/node/screen-share/desktop-targets.js +80 -0
  19. package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
  20. package/esm/node/screen-share/desktop-viewer.js +339 -0
  21. package/esm/node/screen-share/index.d.ts +8 -0
  22. package/esm/node/screen-share/index.js +9 -0
  23. package/esm/node/screen-share/rfb-client.d.ts +54 -0
  24. package/esm/node/screen-share/rfb-client.js +179 -0
  25. package/esm/node/screen-share/rfb-des.d.ts +11 -0
  26. package/esm/node/screen-share/rfb-des.js +143 -0
  27. package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
  28. package/esm/node/screen-share/rfb-encodings.js +288 -0
  29. package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
  30. package/esm/node/screen-share/rfb-framebuffer.js +53 -0
  31. package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
  32. package/esm/node/screen-share/rfb-protocol.js +36 -0
  33. package/esm/node/screen-share/rfb-reader.d.ts +34 -0
  34. package/esm/node/screen-share/rfb-reader.js +110 -0
  35. package/esm/node/screen-share/rfb-security.d.ts +30 -0
  36. package/esm/node/screen-share/rfb-security.js +136 -0
  37. package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
  38. package/esm/node/screen-share/rfb-test-server.js +116 -0
  39. package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
  40. package/esm/node/screen-share/screen-share-server-impl.js +76 -0
  41. package/esm/node/screen-share/screen-shares.d.ts +123 -0
  42. package/esm/node/screen-share/screen-shares.js +463 -0
  43. package/esm/node/session-info-util.d.ts +10 -11
  44. package/esm/node/session-info-util.js +16 -94
  45. package/esm/node/settings-store.d.ts +1 -1
  46. package/esm/node/settings-store.js +7 -4
  47. package/esm/node/sign-in/access-store.d.ts +1 -1
  48. package/esm/node/sign-in/access-store.js +4 -1
  49. package/esm/node/sign-in/index.d.ts +2 -0
  50. package/esm/node/sign-in/index.js +2 -0
  51. package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
  52. package/esm/node/sign-in/polled-sign-in.js +83 -0
  53. package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
  54. package/esm/node/sign-in/sign-in-devices.js +113 -0
  55. package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
  56. package/esm/node/sign-in/sign-in-flow.js +79 -4
  57. package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
  58. package/esm/node/sign-in/sign-in-pages.js +137 -8
  59. package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
  60. package/esm/node/sign-in/sign-in-provider.js +15 -0
  61. package/esm/node/sources-extension.d.ts +10 -0
  62. package/esm/node/sources-extension.js +18 -0
  63. package/esm/node/ta-server-impl.js +3 -3
  64. package/esm/node/ta-session-factory.js +2 -0
  65. package/esm/node/team/team-calls.js +27 -0
  66. package/esm/node/voice-bridge.d.ts +3 -1
  67. package/esm/node/voice-bridge.js +10 -3
  68. package/esm/node/voices-file.d.ts +5 -0
  69. package/esm/node/voices-file.js +14 -3
  70. package/esm/node/working-directory.d.ts +8 -2
  71. package/esm/node/working-directory.js +7 -0
  72. package/lib/node/app-commands.d.ts +1 -1
  73. package/lib/node/app-commands.js +46 -29
  74. package/lib/node/credentials.d.ts +13 -0
  75. package/lib/node/credentials.js +38 -0
  76. package/lib/node/index.d.ts +2 -0
  77. package/lib/node/index.js +2 -0
  78. package/lib/node/keep-awake.d.ts +3 -0
  79. package/lib/node/keep-awake.js +6 -1
  80. package/lib/node/package-hosts.d.ts +2 -0
  81. package/lib/node/package-hosts.js +6 -0
  82. package/lib/node/rooms-bridge.d.ts +10 -1
  83. package/lib/node/rooms-bridge.js +25 -0
  84. package/lib/node/screen-share/desktop-picture.d.ts +52 -0
  85. package/lib/node/screen-share/desktop-picture.js +136 -0
  86. package/lib/node/screen-share/desktop-session.d.ts +129 -0
  87. package/lib/node/screen-share/desktop-session.js +442 -0
  88. package/lib/node/screen-share/desktop-targets.d.ts +25 -0
  89. package/lib/node/screen-share/desktop-targets.js +84 -0
  90. package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
  91. package/lib/node/screen-share/desktop-viewer.js +343 -0
  92. package/lib/node/screen-share/index.d.ts +9 -0
  93. package/lib/node/screen-share/index.js +25 -0
  94. package/lib/node/screen-share/rfb-client.d.ts +55 -0
  95. package/lib/node/screen-share/rfb-client.js +183 -0
  96. package/lib/node/screen-share/rfb-des.d.ts +12 -0
  97. package/lib/node/screen-share/rfb-des.js +146 -0
  98. package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
  99. package/lib/node/screen-share/rfb-encodings.js +295 -0
  100. package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
  101. package/lib/node/screen-share/rfb-framebuffer.js +57 -0
  102. package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
  103. package/lib/node/screen-share/rfb-protocol.js +39 -0
  104. package/lib/node/screen-share/rfb-reader.d.ts +35 -0
  105. package/lib/node/screen-share/rfb-reader.js +115 -0
  106. package/lib/node/screen-share/rfb-security.d.ts +31 -0
  107. package/lib/node/screen-share/rfb-security.js +141 -0
  108. package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
  109. package/lib/node/screen-share/rfb-test-server.js +120 -0
  110. package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
  111. package/lib/node/screen-share/screen-share-server-impl.js +79 -0
  112. package/lib/node/screen-share/screen-shares.d.ts +124 -0
  113. package/lib/node/screen-share/screen-shares.js +464 -0
  114. package/lib/node/session-info-util.d.ts +10 -11
  115. package/lib/node/session-info-util.js +15 -93
  116. package/lib/node/settings-store.d.ts +1 -1
  117. package/lib/node/settings-store.js +6 -3
  118. package/lib/node/sign-in/access-store.d.ts +1 -1
  119. package/lib/node/sign-in/access-store.js +4 -1
  120. package/lib/node/sign-in/index.d.ts +2 -0
  121. package/lib/node/sign-in/index.js +2 -0
  122. package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
  123. package/lib/node/sign-in/polled-sign-in.js +87 -0
  124. package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
  125. package/lib/node/sign-in/sign-in-devices.js +117 -0
  126. package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
  127. package/lib/node/sign-in/sign-in-flow.js +80 -5
  128. package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
  129. package/lib/node/sign-in/sign-in-pages.js +136 -7
  130. package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
  131. package/lib/node/sign-in/sign-in-provider.js +15 -0
  132. package/lib/node/sources-extension.d.ts +11 -0
  133. package/lib/node/sources-extension.js +22 -0
  134. package/lib/node/ta-server-impl.js +2 -2
  135. package/lib/node/ta-session-factory.js +2 -0
  136. package/lib/node/team/team-calls.js +27 -0
  137. package/lib/node/voice-bridge.d.ts +3 -1
  138. package/lib/node/voice-bridge.js +9 -2
  139. package/lib/node/voices-file.d.ts +5 -0
  140. package/lib/node/voices-file.js +14 -3
  141. package/lib/node/working-directory.d.ts +8 -2
  142. package/lib/node/working-directory.js +7 -0
  143. package/package.json +14 -10
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RfbZrle = exports.RfbDecoders = exports.RfbByteCursor = exports.RfbZrleTooLargeError = exports.RfbInflater = void 0;
4
+ const node_zlib_1 = require("node:zlib");
5
+ const rfb_protocol_1 = require("./rfb-protocol");
6
+ const rfb_reader_1 = require("./rfb-reader");
7
+ /** The most a ZRLE rectangle may say it holds, compressed. */
8
+ const MAX_ZLIB = 64 * 1024 * 1024;
9
+ /** What deflate may refer back to. */
10
+ const WINDOW = 32 * 1024;
11
+ /**
12
+ * The zlib stream of ZRLE, one for the whole connection: each rectangle's bytes go on where the last ended. Inflated
13
+ * piece by piece as raw deflate, with the last 32 KB of what came out as the dictionary, so that nothing waits on a
14
+ * stream's events.
15
+ */
16
+ class RfbInflater {
17
+ constructor() {
18
+ this.window = new Uint8Array(0);
19
+ this.started = false;
20
+ }
21
+ /**
22
+ * Inflates the bytes of one rectangle, never more than `limit` (RfbZrle.maxBytes): a few KB of deflate can say
23
+ * gigabytes, and zlib stops at the limit instead of making them.
24
+ */
25
+ inflate(compressed, limit) {
26
+ let input = compressed;
27
+ if (!this.started) {
28
+ // The header of zlib (two bytes) before the first deflate block.
29
+ input = input.subarray(2);
30
+ this.started = true;
31
+ }
32
+ let inflated;
33
+ try {
34
+ inflated = (0, node_zlib_1.inflateRawSync)(input, {
35
+ finishFlush: node_zlib_1.constants.Z_SYNC_FLUSH,
36
+ maxOutputLength: Math.max(1, limit),
37
+ ...(this.window.length ? { dictionary: this.window } : {}),
38
+ });
39
+ }
40
+ catch (error) {
41
+ if (error.code === 'ERR_BUFFER_TOO_LARGE') {
42
+ throw new RfbZrleTooLargeError(limit);
43
+ }
44
+ throw error;
45
+ }
46
+ const out = new Uint8Array(inflated);
47
+ if (out.length >= WINDOW) {
48
+ this.window = out.slice(out.length - WINDOW);
49
+ }
50
+ else {
51
+ const joined = new Uint8Array(Math.min(WINDOW, this.window.length + out.length));
52
+ const keep = joined.length - out.length;
53
+ joined.set(this.window.subarray(this.window.length - keep), 0);
54
+ joined.set(out, keep);
55
+ this.window = joined;
56
+ }
57
+ return out;
58
+ }
59
+ }
60
+ exports.RfbInflater = RfbInflater;
61
+ /** A ZRLE rectangle inflated to more than its size allows: a broken or hostile server, and the connection ends. */
62
+ class RfbZrleTooLargeError extends rfb_reader_1.RfbClosedError {
63
+ constructor(limit) {
64
+ super(`A ZRLE rectangle inflates to more than the ${limit} bytes its size allows.`);
65
+ this.limit = limit;
66
+ }
67
+ }
68
+ exports.RfbZrleTooLargeError = RfbZrleTooLargeError;
69
+ /** Reads bytes already inflated, failing as a closed connection when they end early. */
70
+ class RfbByteCursor {
71
+ constructor(bytes) {
72
+ this.bytes = bytes;
73
+ this.at = 0;
74
+ }
75
+ u8() {
76
+ if (this.at >= this.bytes.length) {
77
+ throw new rfb_reader_1.RfbClosedError('A ZRLE rectangle ended early.');
78
+ }
79
+ return this.bytes[this.at++];
80
+ }
81
+ take(count) {
82
+ if (this.at + count > this.bytes.length) {
83
+ throw new rfb_reader_1.RfbClosedError('A ZRLE rectangle ended early.');
84
+ }
85
+ const out = this.bytes.subarray(this.at, this.at + count);
86
+ this.at += count;
87
+ return out;
88
+ }
89
+ run() {
90
+ let length = 1;
91
+ let byte;
92
+ do {
93
+ byte = this.u8();
94
+ length += byte;
95
+ } while (byte === 255);
96
+ return length;
97
+ }
98
+ }
99
+ exports.RfbByteCursor = RfbByteCursor;
100
+ /** The encodings of rectangles Ta asks for (docs/design/ta-desktop-remote.md 3.3). */
101
+ class RfbDecoders {
102
+ constructor(reader, framebuffer) {
103
+ this.reader = reader;
104
+ this.framebuffer = framebuffer;
105
+ this.inflater = new RfbInflater();
106
+ }
107
+ async read(rect, encoding) {
108
+ switch (encoding) {
109
+ case rfb_protocol_1.Rfb.Encoding.RAW:
110
+ return this.raw(rect);
111
+ case rfb_protocol_1.Rfb.Encoding.COPY_RECT:
112
+ return this.copyRect(rect);
113
+ case rfb_protocol_1.Rfb.Encoding.ZRLE:
114
+ return this.zrle(rect);
115
+ case rfb_protocol_1.Rfb.Encoding.CURSOR:
116
+ return this.cursor(rect);
117
+ case rfb_protocol_1.Rfb.Encoding.DESKTOP_SIZE:
118
+ return { kind: 'size', width: rect.w, height: rect.h };
119
+ case rfb_protocol_1.Rfb.Encoding.EXTENDED_DESKTOP_SIZE:
120
+ return this.extendedSize(rect);
121
+ case rfb_protocol_1.Rfb.Encoding.LAST_RECT:
122
+ return { kind: 'last' };
123
+ default:
124
+ throw new rfb_reader_1.RfbClosedError(`The desktop sent an encoding Ta did not ask for (${encoding}).`);
125
+ }
126
+ }
127
+ async raw(rect) {
128
+ const bytes = await this.reader.read(rect.w * rect.h * 4);
129
+ if (this.framebuffer.contains(rect)) {
130
+ this.framebuffer.putRaw(rect, bytes);
131
+ }
132
+ return { kind: 'pixels' };
133
+ }
134
+ async copyRect(rect) {
135
+ const fromX = await this.reader.u16();
136
+ const fromY = await this.reader.u16();
137
+ if (this.framebuffer.contains(rect) && this.framebuffer.contains({ x: fromX, y: fromY, w: rect.w, h: rect.h })) {
138
+ this.framebuffer.copy(rect, fromX, fromY);
139
+ }
140
+ return { kind: 'pixels' };
141
+ }
142
+ async zrle(rect) {
143
+ const length = await this.reader.u32();
144
+ if (length > MAX_ZLIB) {
145
+ throw new rfb_reader_1.RfbClosedError(`A ZRLE rectangle of ${length} bytes is too big.`);
146
+ }
147
+ // Before inflating: the size of the rectangle is what bounds what it may inflate to.
148
+ if (!this.framebuffer.contains(rect)) {
149
+ throw new rfb_reader_1.RfbClosedError(`A ZRLE rectangle of ${rect.w} by ${rect.h} at ${rect.x}, ${rect.y} lies outside the desktop.`);
150
+ }
151
+ const data = this.inflater.inflate(await this.reader.read(length), RfbZrle.maxBytes(rect));
152
+ RfbZrle.decode(new RfbByteCursor(data), rect, this.framebuffer);
153
+ return { kind: 'pixels' };
154
+ }
155
+ async cursor(rect) {
156
+ if (rect.w === 0 || rect.h === 0) {
157
+ return { kind: 'cursor', cursor: null };
158
+ }
159
+ if (rect.w > 256 || rect.h > 256) {
160
+ throw new rfb_reader_1.RfbClosedError('The desktop sent a pointer too big to draw.');
161
+ }
162
+ const pixels = await this.reader.read(rect.w * rect.h * 4);
163
+ const rowMask = (rect.w + 7) >> 3;
164
+ const mask = await this.reader.read(rowMask * rect.h);
165
+ const rgba = new Uint8Array(rect.w * rect.h * 4);
166
+ for (let y = 0; y < rect.h; y++) {
167
+ for (let x = 0; x < rect.w; x++) {
168
+ const at = (y * rect.w + x) * 4;
169
+ rgba[at] = pixels[at];
170
+ rgba[at + 1] = pixels[at + 1];
171
+ rgba[at + 2] = pixels[at + 2];
172
+ rgba[at + 3] = mask[y * rowMask + (x >> 3)] & (0x80 >> (x & 7)) ? 255 : 0;
173
+ }
174
+ }
175
+ return { kind: 'cursor', cursor: { hotX: rect.x, hotY: rect.y, width: rect.w, height: rect.h, rgba } };
176
+ }
177
+ async extendedSize(rect) {
178
+ const count = await this.reader.u8();
179
+ await this.reader.read(3);
180
+ const screens = [];
181
+ for (let index = 0; index < count; index++) {
182
+ const id = await this.reader.u32();
183
+ const [x, y, width, height] = [await this.reader.u16(), await this.reader.u16(), await this.reader.u16(), await this.reader.u16()];
184
+ await this.reader.u32();
185
+ screens.push({ id, x, y, width, height });
186
+ }
187
+ // rect.y is the status of a change the client asked for: Ta asks for none, so every one is the server's.
188
+ return { kind: 'size', width: rect.w, height: rect.h, screens };
189
+ }
190
+ }
191
+ exports.RfbDecoders = RfbDecoders;
192
+ /** ZRLE (RFC 6143 7.7.6): tiles of 64 by 64, each raw, one colour, a packed palette, or runs, with pixels of 3 bytes. */
193
+ var RfbZrle;
194
+ (function (RfbZrle) {
195
+ const TILE = 64;
196
+ /** The largest palette of a tile, 127 colours of 3 bytes. */
197
+ const MAX_PALETTE = 127 * 3;
198
+ /**
199
+ * The most bytes a rectangle may inflate to: each tile its kind byte, then at worst a run of one for every pixel (3
200
+ * bytes of colour and 1 of length: 4 a pixel), or the largest palette and a run of one for every pixel (381 bytes,
201
+ * then 2 a pixel); raw (3 a pixel) and packed palettes (at most 48 bytes and 1 a pixel) are less.
202
+ */
203
+ function maxBytes(rect) {
204
+ const tile = (width, height) => {
205
+ const pixels = width * height;
206
+ return pixels === 0 ? 0 : 1 + Math.max(4 * pixels, MAX_PALETTE + 2 * pixels);
207
+ };
208
+ const columns = Math.floor(rect.w / TILE);
209
+ const rows = Math.floor(rect.h / TILE);
210
+ const right = rect.w % TILE;
211
+ const bottom = rect.h % TILE;
212
+ return columns * rows * tile(TILE, TILE) + rows * tile(right, TILE) + columns * tile(TILE, bottom) + tile(right, bottom);
213
+ }
214
+ RfbZrle.maxBytes = maxBytes;
215
+ function decode(cursor, rect, framebuffer) {
216
+ const palette = new Uint8Array(128 * 3);
217
+ for (let top = 0; top < rect.h; top += TILE) {
218
+ for (let left = 0; left < rect.w; left += TILE) {
219
+ const tile = { x: rect.x + left, y: rect.y + top, w: Math.min(TILE, rect.w - left), h: Math.min(TILE, rect.h - top) };
220
+ tileOf(cursor, tile, framebuffer, palette);
221
+ }
222
+ }
223
+ }
224
+ RfbZrle.decode = decode;
225
+ function tileOf(cursor, tile, framebuffer, palette) {
226
+ const kind = cursor.u8();
227
+ const { rgba, width } = framebuffer;
228
+ const put = (index, r, g, b) => {
229
+ const at = ((tile.y + Math.floor(index / tile.w)) * width + tile.x + (index % tile.w)) * 4;
230
+ rgba[at] = r;
231
+ rgba[at + 1] = g;
232
+ rgba[at + 2] = b;
233
+ rgba[at + 3] = 255;
234
+ };
235
+ const count = tile.w * tile.h;
236
+ if (kind === 0) {
237
+ const bytes = cursor.take(count * 3);
238
+ for (let index = 0; index < count; index++) {
239
+ put(index, bytes[index * 3], bytes[index * 3 + 1], bytes[index * 3 + 2]);
240
+ }
241
+ return;
242
+ }
243
+ if (kind === 1) {
244
+ const [r, g, b] = cursor.take(3);
245
+ framebuffer.fill(tile, r, g, b);
246
+ return;
247
+ }
248
+ if (kind <= 16) {
249
+ palette.set(cursor.take(kind * 3));
250
+ const bits = kind === 2 ? 1 : kind <= 4 ? 2 : 4;
251
+ const mask = (1 << bits) - 1;
252
+ for (let row = 0; row < tile.h; row++) {
253
+ let byte = 0;
254
+ let left = 0;
255
+ for (let column = 0; column < tile.w; column++) {
256
+ if (left === 0) {
257
+ byte = cursor.u8();
258
+ left = 8;
259
+ }
260
+ left -= bits;
261
+ const index = ((byte >> left) & mask) * 3;
262
+ put(row * tile.w + column, palette[index], palette[index + 1], palette[index + 2]);
263
+ }
264
+ }
265
+ return;
266
+ }
267
+ if (kind === 128) {
268
+ let index = 0;
269
+ while (index < count) {
270
+ const [r, g, b] = cursor.take(3);
271
+ const end = Math.min(count, index + cursor.run());
272
+ for (; index < end; index++) {
273
+ put(index, r, g, b);
274
+ }
275
+ }
276
+ return;
277
+ }
278
+ if (kind >= 130) {
279
+ const size = kind - 128;
280
+ palette.set(cursor.take(size * 3));
281
+ let index = 0;
282
+ while (index < count) {
283
+ const byte = cursor.u8();
284
+ const colour = (byte & 127) * 3;
285
+ const end = byte & 128 ? Math.min(count, index + cursor.run()) : index + 1;
286
+ for (; index < end; index++) {
287
+ put(index, palette[colour], palette[colour + 1], palette[colour + 2]);
288
+ }
289
+ }
290
+ return;
291
+ }
292
+ throw new rfb_reader_1.RfbClosedError(`A ZRLE tile of a kind Ta does not know (${kind}).`);
293
+ }
294
+ })(RfbZrle || (exports.RfbZrle = RfbZrle = {}));
295
+ //# sourceMappingURL=rfb-encodings.js.map
@@ -0,0 +1,17 @@
1
+ import type { RfbRect } from './rfb-protocol';
2
+ /** The pixels of a desktop, RGBA, one copy for every page that looks at it. */
3
+ export declare class RfbFramebuffer {
4
+ width: number;
5
+ height: number;
6
+ rgba: Uint8Array;
7
+ constructor(width: number, height: number);
8
+ resize(width: number, height: number): void;
9
+ /** Whether a rectangle a server named lies inside: one that does not is a broken server, and its bytes are read but not drawn. */
10
+ contains(rect: RfbRect): boolean;
11
+ /** Pixels of 4 bytes, R G B X, a row after another: the alpha set opaque. */
12
+ putRaw(rect: RfbRect, bytes: Uint8Array): void;
13
+ /** One colour, R G B in the low 24 bits of `rgb` as they are in memory (R lowest). */
14
+ fill(rect: RfbRect, r: number, g: number, b: number): void;
15
+ copy(rect: RfbRect, fromX: number, fromY: number): void;
16
+ }
17
+ //# sourceMappingURL=rfb-framebuffer.d.ts.map
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RfbFramebuffer = void 0;
4
+ /** The pixels of a desktop, RGBA, one copy for every page that looks at it. */
5
+ class RfbFramebuffer {
6
+ constructor(width, height) {
7
+ this.width = width;
8
+ this.height = height;
9
+ this.rgba = new Uint8Array(width * height * 4);
10
+ }
11
+ resize(width, height) {
12
+ this.width = width;
13
+ this.height = height;
14
+ this.rgba = new Uint8Array(width * height * 4);
15
+ }
16
+ /** Whether a rectangle a server named lies inside: one that does not is a broken server, and its bytes are read but not drawn. */
17
+ contains(rect) {
18
+ return rect.x >= 0 && rect.y >= 0 && rect.w >= 0 && rect.h >= 0 && rect.x + rect.w <= this.width && rect.y + rect.h <= this.height;
19
+ }
20
+ /** Pixels of 4 bytes, R G B X, a row after another: the alpha set opaque. */
21
+ putRaw(rect, bytes) {
22
+ const { rgba, width } = this;
23
+ for (let row = 0; row < rect.h; row++) {
24
+ const to = ((rect.y + row) * width + rect.x) * 4;
25
+ rgba.set(bytes.subarray(row * rect.w * 4, (row + 1) * rect.w * 4), to);
26
+ for (let at = to + 3, end = to + rect.w * 4; at < end; at += 4) {
27
+ rgba[at] = 255;
28
+ }
29
+ }
30
+ }
31
+ /** One colour, R G B in the low 24 bits of `rgb` as they are in memory (R lowest). */
32
+ fill(rect, r, g, b) {
33
+ const { rgba, width } = this;
34
+ for (let row = 0; row < rect.h; row++) {
35
+ let at = ((rect.y + row) * width + rect.x) * 4;
36
+ for (let column = 0; column < rect.w; column++, at += 4) {
37
+ rgba[at] = r;
38
+ rgba[at + 1] = g;
39
+ rgba[at + 2] = b;
40
+ rgba[at + 3] = 255;
41
+ }
42
+ }
43
+ }
44
+ copy(rect, fromX, fromY) {
45
+ const { rgba, width } = this;
46
+ const rowBytes = rect.w * 4;
47
+ // Rows in the order that does not read a row already written over.
48
+ const down = fromY >= rect.y;
49
+ for (let index = 0; index < rect.h; index++) {
50
+ const row = down ? index : rect.h - 1 - index;
51
+ const from = ((fromY + row) * width + fromX) * 4;
52
+ rgba.copyWithin(((rect.y + row) * width + rect.x) * 4, from, from + rowBytes);
53
+ }
54
+ }
55
+ }
56
+ exports.RfbFramebuffer = RfbFramebuffer;
57
+ //# sourceMappingURL=rfb-framebuffer.js.map
@@ -0,0 +1,91 @@
1
+ /** What RFB (RFC 6143) calls things, as the client of Ta uses them (docs/design/ta-desktop-remote.md 3). */
2
+ export declare namespace Rfb {
3
+ const Security: {
4
+ readonly NONE: 1;
5
+ readonly VNC: 2;
6
+ readonly ARD: 30;
7
+ };
8
+ const Encoding: {
9
+ readonly RAW: 0;
10
+ readonly COPY_RECT: 1;
11
+ readonly ZRLE: 16;
12
+ readonly CURSOR: -239;
13
+ readonly DESKTOP_SIZE: -223;
14
+ readonly LAST_RECT: -224;
15
+ readonly EXTENDED_DESKTOP_SIZE: -308;
16
+ };
17
+ /** What Ta asks the server for, in order of preference. */
18
+ const ENCODINGS: readonly number[];
19
+ const ServerMessage: {
20
+ readonly FRAMEBUFFER_UPDATE: 0;
21
+ readonly COLOUR_MAP: 1;
22
+ readonly BELL: 2;
23
+ readonly CUT_TEXT: 3;
24
+ };
25
+ const ClientMessage: {
26
+ readonly SET_PIXEL_FORMAT: 0;
27
+ readonly SET_ENCODINGS: 2;
28
+ readonly UPDATE_REQUEST: 3;
29
+ readonly KEY: 4;
30
+ readonly POINTER: 5;
31
+ readonly CUT_TEXT: 6;
32
+ };
33
+ /**
34
+ * The pixels Ta asks for: 32 bits, little-endian, red in the lowest byte, so that a pixel in memory is R, G, B, X,
35
+ * the order of an RGBA buffer; ZRLE then sends three bytes a pixel (its CPIXEL), in the same order.
36
+ */
37
+ const PIXEL_FORMAT: readonly number[];
38
+ /** The biggest framebuffer Ta takes: 8K by 8K, whatever a server says. */
39
+ const MAX_SIDE = 8192;
40
+ /** The longest text of the clipboard or of a reason Ta reads. */
41
+ const MAX_TEXT: number;
42
+ }
43
+ /** One screen of a framebuffer (ExtendedDesktopSize); a framebuffer without them is one screen. */
44
+ export interface RfbScreen {
45
+ id: number;
46
+ x: number;
47
+ y: number;
48
+ width: number;
49
+ height: number;
50
+ }
51
+ export interface RfbRect {
52
+ x: number;
53
+ y: number;
54
+ w: number;
55
+ h: number;
56
+ }
57
+ /** The pointer's picture (Cursor pseudo-encoding), RGBA with the server's mask as alpha; drawn by the page. */
58
+ export interface RfbCursor {
59
+ hotX: number;
60
+ hotY: number;
61
+ width: number;
62
+ height: number;
63
+ rgba: Uint8Array;
64
+ }
65
+ /** What a client asks of whoever opened it while it signs in. */
66
+ export interface RfbCredentials {
67
+ username?: string;
68
+ password: string;
69
+ }
70
+ export interface RfbClientOptions {
71
+ /** Asked when the server wants a password (VNC Authentication) or an account (Apple Remote Desktop). */
72
+ credentials(need: {
73
+ username: boolean;
74
+ }): Promise<RfbCredentials>;
75
+ /** Shared with other clients of the server: true, so that Ta never ends the session of someone else. */
76
+ shared?: boolean;
77
+ }
78
+ /** What a client tells as the desktop changes. */
79
+ export interface RfbClientEvents {
80
+ /** The framebuffer has a new size (and maybe new screens); all of it follows as damage. */
81
+ size(width: number, height: number, screens: RfbScreen[]): void;
82
+ /** These pixels changed. */
83
+ damage(rect: RfbRect): void;
84
+ /** An update ended: what changed since the last is all there. */
85
+ update(): void;
86
+ cursor(cursor: RfbCursor | null): void;
87
+ clipboard(text: string): void;
88
+ bell(): void;
89
+ closed(error?: Error): void;
90
+ }
91
+ //# sourceMappingURL=rfb-protocol.d.ts.map
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Rfb = void 0;
4
+ /** What RFB (RFC 6143) calls things, as the client of Ta uses them (docs/design/ta-desktop-remote.md 3). */
5
+ var Rfb;
6
+ (function (Rfb) {
7
+ Rfb.Security = { NONE: 1, VNC: 2, ARD: 30 };
8
+ Rfb.Encoding = {
9
+ RAW: 0,
10
+ COPY_RECT: 1,
11
+ ZRLE: 16,
12
+ CURSOR: -239,
13
+ DESKTOP_SIZE: -223,
14
+ LAST_RECT: -224,
15
+ EXTENDED_DESKTOP_SIZE: -308,
16
+ };
17
+ /** What Ta asks the server for, in order of preference. */
18
+ Rfb.ENCODINGS = [
19
+ Rfb.Encoding.ZRLE,
20
+ Rfb.Encoding.COPY_RECT,
21
+ Rfb.Encoding.RAW,
22
+ Rfb.Encoding.CURSOR,
23
+ Rfb.Encoding.EXTENDED_DESKTOP_SIZE,
24
+ Rfb.Encoding.DESKTOP_SIZE,
25
+ Rfb.Encoding.LAST_RECT,
26
+ ];
27
+ Rfb.ServerMessage = { FRAMEBUFFER_UPDATE: 0, COLOUR_MAP: 1, BELL: 2, CUT_TEXT: 3 };
28
+ Rfb.ClientMessage = { SET_PIXEL_FORMAT: 0, SET_ENCODINGS: 2, UPDATE_REQUEST: 3, KEY: 4, POINTER: 5, CUT_TEXT: 6 };
29
+ /**
30
+ * The pixels Ta asks for: 32 bits, little-endian, red in the lowest byte, so that a pixel in memory is R, G, B, X,
31
+ * the order of an RGBA buffer; ZRLE then sends three bytes a pixel (its CPIXEL), in the same order.
32
+ */
33
+ Rfb.PIXEL_FORMAT = [32, 24, 0, 1, 0, 255, 0, 255, 0, 255, 0, 8, 16, 0, 0, 0];
34
+ /** The biggest framebuffer Ta takes: 8K by 8K, whatever a server says. */
35
+ Rfb.MAX_SIDE = 8192;
36
+ /** The longest text of the clipboard or of a reason Ta reads. */
37
+ Rfb.MAX_TEXT = 1024 * 1024;
38
+ })(Rfb || (exports.Rfb = Rfb = {}));
39
+ //# sourceMappingURL=rfb-protocol.js.map
@@ -0,0 +1,35 @@
1
+ import type { ExecSocket } from '@celljs/ta-exec';
2
+ /** The connection to an RFB server ended, or said something Ta does not follow. */
3
+ export declare class RfbClosedError extends Error {
4
+ }
5
+ /**
6
+ * Bytes as they come from a socket, read by exact counts: the messages of RFB have no framing, so a reader asks for
7
+ * the next n bytes and waits until they are there.
8
+ */
9
+ export declare class RfbReader {
10
+ protected chunks: Uint8Array[];
11
+ protected buffered: number;
12
+ protected waiting?: {
13
+ count: number;
14
+ resolve: (bytes: Uint8Array) => void;
15
+ reject: (error: Error) => void;
16
+ };
17
+ protected ended?: Error;
18
+ constructor(socket: Pick<ExecSocket, 'onData' | 'onClose'>);
19
+ push(data: Uint8Array): void;
20
+ end(error: Error): void;
21
+ /** The next `count` bytes. One read at a time. */
22
+ read(count: number): Promise<Uint8Array>;
23
+ u8(): Promise<number>;
24
+ u16(): Promise<number>;
25
+ s32(): Promise<number>;
26
+ u32(): Promise<number>;
27
+ protected take(count: number): Uint8Array;
28
+ }
29
+ /** Big-endian numbers written into the messages Ta sends. */
30
+ export declare namespace RfbBytes {
31
+ function u16(value: number): number[];
32
+ function u32(value: number): number[];
33
+ function s32(value: number): number[];
34
+ }
35
+ //# sourceMappingURL=rfb-reader.d.ts.map
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RfbBytes = exports.RfbReader = exports.RfbClosedError = void 0;
4
+ /** The connection to an RFB server ended, or said something Ta does not follow. */
5
+ class RfbClosedError extends Error {
6
+ }
7
+ exports.RfbClosedError = RfbClosedError;
8
+ /**
9
+ * Bytes as they come from a socket, read by exact counts: the messages of RFB have no framing, so a reader asks for
10
+ * the next n bytes and waits until they are there.
11
+ */
12
+ class RfbReader {
13
+ constructor(socket) {
14
+ this.chunks = [];
15
+ this.buffered = 0;
16
+ socket.onData(data => this.push(data));
17
+ socket.onClose(() => this.end(new RfbClosedError('The connection to the desktop ended.')));
18
+ }
19
+ push(data) {
20
+ if (data.length === 0) {
21
+ return;
22
+ }
23
+ this.chunks.push(data);
24
+ this.buffered += data.length;
25
+ if (this.waiting && this.buffered >= this.waiting.count) {
26
+ const { count, resolve } = this.waiting;
27
+ this.waiting = undefined;
28
+ resolve(this.take(count));
29
+ }
30
+ }
31
+ end(error) {
32
+ var _a;
33
+ (_a = this.ended) !== null && _a !== void 0 ? _a : (this.ended = error);
34
+ if (this.waiting) {
35
+ const { reject } = this.waiting;
36
+ this.waiting = undefined;
37
+ reject(this.ended);
38
+ }
39
+ }
40
+ /** The next `count` bytes. One read at a time. */
41
+ read(count) {
42
+ if (this.buffered >= count) {
43
+ return Promise.resolve(this.take(count));
44
+ }
45
+ if (this.ended) {
46
+ return Promise.reject(this.ended);
47
+ }
48
+ return new Promise((resolve, reject) => {
49
+ this.waiting = { count, resolve, reject };
50
+ });
51
+ }
52
+ async u8() {
53
+ return (await this.read(1))[0];
54
+ }
55
+ async u16() {
56
+ const bytes = await this.read(2);
57
+ return (bytes[0] << 8) | bytes[1];
58
+ }
59
+ async s32() {
60
+ const bytes = await this.read(4);
61
+ return (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
62
+ }
63
+ async u32() {
64
+ return (await this.s32()) >>> 0;
65
+ }
66
+ take(count) {
67
+ if (count === 0) {
68
+ return new Uint8Array(0);
69
+ }
70
+ const first = this.chunks[0];
71
+ if (first.length >= count) {
72
+ this.buffered -= count;
73
+ if (first.length === count) {
74
+ this.chunks.shift();
75
+ return first;
76
+ }
77
+ this.chunks[0] = first.subarray(count);
78
+ return first.subarray(0, count);
79
+ }
80
+ const out = new Uint8Array(count);
81
+ let at = 0;
82
+ while (at < count) {
83
+ const chunk = this.chunks[0];
84
+ const part = Math.min(chunk.length, count - at);
85
+ out.set(chunk.subarray(0, part), at);
86
+ at += part;
87
+ if (part === chunk.length) {
88
+ this.chunks.shift();
89
+ }
90
+ else {
91
+ this.chunks[0] = chunk.subarray(part);
92
+ }
93
+ }
94
+ this.buffered -= count;
95
+ return out;
96
+ }
97
+ }
98
+ exports.RfbReader = RfbReader;
99
+ /** Big-endian numbers written into the messages Ta sends. */
100
+ var RfbBytes;
101
+ (function (RfbBytes) {
102
+ function u16(value) {
103
+ return [(value >> 8) & 255, value & 255];
104
+ }
105
+ RfbBytes.u16 = u16;
106
+ function u32(value) {
107
+ return [(value >>> 24) & 255, (value >> 16) & 255, (value >> 8) & 255, value & 255];
108
+ }
109
+ RfbBytes.u32 = u32;
110
+ function s32(value) {
111
+ return u32(value >>> 0);
112
+ }
113
+ RfbBytes.s32 = s32;
114
+ })(RfbBytes || (exports.RfbBytes = RfbBytes = {}));
115
+ //# sourceMappingURL=rfb-reader.js.map
@@ -0,0 +1,31 @@
1
+ import { type RfbClientOptions } from './rfb-protocol';
2
+ import { type RfbReader } from './rfb-reader';
3
+ /** The server refused to let Ta in, with its reason. */
4
+ export declare class RfbAuthError extends Error {
5
+ }
6
+ /**
7
+ * Signing in (RFC 6143 7.1.2, 7.2): the first security type of the server's list that Ta knows (None, VNC
8
+ * Authentication, Apple Remote Desktop), and the result.
9
+ */
10
+ export declare class RfbSecurity {
11
+ protected readonly reader: RfbReader;
12
+ protected readonly write: (bytes: Uint8Array) => void;
13
+ protected readonly options: Pick<RfbClientOptions, 'credentials'>;
14
+ constructor(reader: RfbReader, write: (bytes: Uint8Array) => void, options: Pick<RfbClientOptions, 'credentials'>);
15
+ /** Signs in with the minor version agreed (3, 7 or 8). */
16
+ negotiate(minor: number): Promise<void>;
17
+ protected vnc(): Promise<void>;
18
+ /**
19
+ * Apple Remote Desktop (type 30), which the Screen Sharing of macOS offers: Diffie-Hellman with the server's
20
+ * generator and prime, MD5 of the shared secret as an AES-128 key, the account in 128 bytes encrypted with it.
21
+ */
22
+ protected ard(): Promise<void>;
23
+ protected result(minor: number): Promise<void>;
24
+ protected reason(): Promise<string>;
25
+ /** A text of up to 63 bytes, ended by a zero, at `at` (the rest of its 64 bytes stays random). */
26
+ protected static field(into: Buffer, at: number, text: string): void;
27
+ static toBigInt(bytes: Uint8Array): bigint;
28
+ static toBytes(value: bigint, length: number): Uint8Array;
29
+ static power(base: bigint, exponent: bigint, modulus: bigint): bigint;
30
+ }
31
+ //# sourceMappingURL=rfb-security.d.ts.map