@novnc/novnc 1.0.0 → 1.2.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 (87) hide show
  1. package/AUTHORS +13 -0
  2. package/LICENSE.txt +2 -1
  3. package/README.md +69 -3
  4. package/core/base64.js +35 -41
  5. package/core/decoders/copyrect.js +22 -0
  6. package/core/decoders/hextile.js +137 -0
  7. package/core/decoders/raw.js +56 -0
  8. package/core/decoders/rre.js +44 -0
  9. package/core/decoders/tight.js +315 -0
  10. package/core/decoders/tightpng.js +27 -0
  11. package/core/deflator.js +85 -0
  12. package/core/des.js +90 -95
  13. package/core/display.js +254 -297
  14. package/core/encodings.js +7 -3
  15. package/core/inflator.js +48 -20
  16. package/core/input/domkeytable.js +21 -24
  17. package/core/input/fixedkeys.js +3 -1
  18. package/core/input/gesturehandler.js +567 -0
  19. package/core/input/keyboard.js +194 -120
  20. package/core/input/keysym.js +2 -0
  21. package/core/input/keysymdef.js +3 -3
  22. package/core/input/util.js +53 -12
  23. package/core/input/vkeys.js +2 -1
  24. package/core/rfb.js +1937 -1496
  25. package/core/util/browser.js +80 -29
  26. package/core/util/cursor.js +253 -0
  27. package/core/util/element.js +32 -0
  28. package/core/util/events.js +59 -55
  29. package/core/util/eventtarget.js +25 -30
  30. package/core/util/int.js +15 -0
  31. package/core/util/logging.js +21 -16
  32. package/core/util/polyfill.js +15 -8
  33. package/core/util/strings.js +21 -8
  34. package/core/websock.js +145 -167
  35. package/docs/API.md +31 -10
  36. package/lib/base64.js +115 -0
  37. package/lib/decoders/copyrect.js +44 -0
  38. package/lib/decoders/hextile.js +173 -0
  39. package/lib/decoders/raw.js +78 -0
  40. package/lib/decoders/rre.js +65 -0
  41. package/lib/decoders/tight.js +350 -0
  42. package/lib/decoders/tightpng.js +67 -0
  43. package/lib/deflator.js +99 -0
  44. package/lib/des.js +314 -0
  45. package/lib/display.js +733 -0
  46. package/lib/encodings.js +64 -0
  47. package/lib/inflator.js +87 -0
  48. package/lib/input/domkeytable.js +282 -0
  49. package/lib/input/fixedkeys.js +123 -0
  50. package/lib/input/gesturehandler.js +642 -0
  51. package/lib/input/keyboard.js +429 -0
  52. package/lib/input/keysym.js +1135 -0
  53. package/lib/input/keysymdef.js +1354 -0
  54. package/lib/input/util.js +304 -0
  55. package/lib/input/vkeys.js +127 -0
  56. package/lib/input/xtscancodes.js +505 -0
  57. package/lib/rfb.js +3448 -0
  58. package/lib/util/browser.js +131 -0
  59. package/lib/util/cursor.js +314 -0
  60. package/lib/util/element.js +43 -0
  61. package/lib/util/events.js +142 -0
  62. package/lib/util/eventtarget.js +64 -0
  63. package/lib/util/int.js +22 -0
  64. package/lib/util/logging.js +79 -0
  65. package/lib/util/polyfill.js +72 -0
  66. package/lib/util/strings.js +38 -0
  67. package/lib/vendor/pako/lib/utils/common.js +67 -0
  68. package/lib/vendor/pako/lib/zlib/adler32.js +33 -0
  69. package/lib/vendor/pako/lib/zlib/constants.js +51 -0
  70. package/lib/vendor/pako/lib/zlib/crc32.js +42 -0
  71. package/lib/vendor/pako/lib/zlib/deflate.js +2159 -0
  72. package/lib/vendor/pako/lib/zlib/gzheader.js +53 -0
  73. package/lib/vendor/pako/lib/zlib/inffast.js +445 -0
  74. package/lib/vendor/pako/lib/zlib/inflate.js +2114 -0
  75. package/lib/vendor/pako/lib/zlib/inftrees.js +418 -0
  76. package/lib/vendor/pako/lib/zlib/messages.js +36 -0
  77. package/lib/vendor/pako/lib/zlib/trees.js +1499 -0
  78. package/lib/vendor/pako/lib/zlib/zstream.js +46 -0
  79. package/lib/vendor/promise.js +255 -0
  80. package/lib/websock.js +374 -0
  81. package/package.json +48 -28
  82. package/vendor/pako/lib/zlib/deflate.js +30 -30
  83. package/vendor/pako/lib/zlib/inflate.js +17 -17
  84. package/core/input/mouse.js +0 -280
  85. package/docs/API-internal.md +0 -125
  86. package/docs/EMBEDDING.md +0 -83
  87. package/docs/VERSION +0 -1
@@ -0,0 +1,315 @@
1
+ /*
2
+ * noVNC: HTML5 VNC client
3
+ * Copyright (C) 2019 The noVNC Authors
4
+ * (c) 2012 Michael Tinglof, Joe Balaz, Les Piech (Mercuri.ca)
5
+ * Licensed under MPL 2.0 (see LICENSE.txt)
6
+ *
7
+ * See README.md for usage and integration instructions.
8
+ *
9
+ */
10
+
11
+ import * as Log from '../util/logging.js';
12
+ import Inflator from "../inflator.js";
13
+
14
+ export default class TightDecoder {
15
+ constructor() {
16
+ this._ctl = null;
17
+ this._filter = null;
18
+ this._numColors = 0;
19
+ this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
20
+ this._len = 0;
21
+
22
+ this._zlibs = [];
23
+ for (let i = 0; i < 4; i++) {
24
+ this._zlibs[i] = new Inflator();
25
+ }
26
+ }
27
+
28
+ decodeRect(x, y, width, height, sock, display, depth) {
29
+ if (this._ctl === null) {
30
+ if (sock.rQwait("TIGHT compression-control", 1)) {
31
+ return false;
32
+ }
33
+
34
+ this._ctl = sock.rQshift8();
35
+
36
+ // Reset streams if the server requests it
37
+ for (let i = 0; i < 4; i++) {
38
+ if ((this._ctl >> i) & 1) {
39
+ this._zlibs[i].reset();
40
+ Log.Info("Reset zlib stream " + i);
41
+ }
42
+ }
43
+
44
+ // Figure out filter
45
+ this._ctl = this._ctl >> 4;
46
+ }
47
+
48
+ let ret;
49
+
50
+ if (this._ctl === 0x08) {
51
+ ret = this._fillRect(x, y, width, height,
52
+ sock, display, depth);
53
+ } else if (this._ctl === 0x09) {
54
+ ret = this._jpegRect(x, y, width, height,
55
+ sock, display, depth);
56
+ } else if (this._ctl === 0x0A) {
57
+ ret = this._pngRect(x, y, width, height,
58
+ sock, display, depth);
59
+ } else if ((this._ctl & 0x80) == 0) {
60
+ ret = this._basicRect(this._ctl, x, y, width, height,
61
+ sock, display, depth);
62
+ } else {
63
+ throw new Error("Illegal tight compression received (ctl: " +
64
+ this._ctl + ")");
65
+ }
66
+
67
+ if (ret) {
68
+ this._ctl = null;
69
+ }
70
+
71
+ return ret;
72
+ }
73
+
74
+ _fillRect(x, y, width, height, sock, display, depth) {
75
+ if (sock.rQwait("TIGHT", 3)) {
76
+ return false;
77
+ }
78
+
79
+ const rQi = sock.rQi;
80
+ const rQ = sock.rQ;
81
+
82
+ display.fillRect(x, y, width, height,
83
+ [rQ[rQi + 2], rQ[rQi + 1], rQ[rQi]], false);
84
+ sock.rQskipBytes(3);
85
+
86
+ return true;
87
+ }
88
+
89
+ _jpegRect(x, y, width, height, sock, display, depth) {
90
+ let data = this._readData(sock);
91
+ if (data === null) {
92
+ return false;
93
+ }
94
+
95
+ display.imageRect(x, y, width, height, "image/jpeg", data);
96
+
97
+ return true;
98
+ }
99
+
100
+ _pngRect(x, y, width, height, sock, display, depth) {
101
+ throw new Error("PNG received in standard Tight rect");
102
+ }
103
+
104
+ _basicRect(ctl, x, y, width, height, sock, display, depth) {
105
+ if (this._filter === null) {
106
+ if (ctl & 0x4) {
107
+ if (sock.rQwait("TIGHT", 1)) {
108
+ return false;
109
+ }
110
+
111
+ this._filter = sock.rQshift8();
112
+ } else {
113
+ // Implicit CopyFilter
114
+ this._filter = 0;
115
+ }
116
+ }
117
+
118
+ let streamId = ctl & 0x3;
119
+
120
+ let ret;
121
+
122
+ switch (this._filter) {
123
+ case 0: // CopyFilter
124
+ ret = this._copyFilter(streamId, x, y, width, height,
125
+ sock, display, depth);
126
+ break;
127
+ case 1: // PaletteFilter
128
+ ret = this._paletteFilter(streamId, x, y, width, height,
129
+ sock, display, depth);
130
+ break;
131
+ case 2: // GradientFilter
132
+ ret = this._gradientFilter(streamId, x, y, width, height,
133
+ sock, display, depth);
134
+ break;
135
+ default:
136
+ throw new Error("Illegal tight filter received (ctl: " +
137
+ this._filter + ")");
138
+ }
139
+
140
+ if (ret) {
141
+ this._filter = null;
142
+ }
143
+
144
+ return ret;
145
+ }
146
+
147
+ _copyFilter(streamId, x, y, width, height, sock, display, depth) {
148
+ const uncompressedSize = width * height * 3;
149
+ let data;
150
+
151
+ if (uncompressedSize < 12) {
152
+ if (sock.rQwait("TIGHT", uncompressedSize)) {
153
+ return false;
154
+ }
155
+
156
+ data = sock.rQshiftBytes(uncompressedSize);
157
+ } else {
158
+ data = this._readData(sock);
159
+ if (data === null) {
160
+ return false;
161
+ }
162
+
163
+ this._zlibs[streamId].setInput(data);
164
+ data = this._zlibs[streamId].inflate(uncompressedSize);
165
+ this._zlibs[streamId].setInput(null);
166
+ }
167
+
168
+ display.blitRgbImage(x, y, width, height, data, 0, false);
169
+
170
+ return true;
171
+ }
172
+
173
+ _paletteFilter(streamId, x, y, width, height, sock, display, depth) {
174
+ if (this._numColors === 0) {
175
+ if (sock.rQwait("TIGHT palette", 1)) {
176
+ return false;
177
+ }
178
+
179
+ const numColors = sock.rQpeek8() + 1;
180
+ const paletteSize = numColors * 3;
181
+
182
+ if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
183
+ return false;
184
+ }
185
+
186
+ this._numColors = numColors;
187
+ sock.rQskipBytes(1);
188
+
189
+ sock.rQshiftTo(this._palette, paletteSize);
190
+ }
191
+
192
+ const bpp = (this._numColors <= 2) ? 1 : 8;
193
+ const rowSize = Math.floor((width * bpp + 7) / 8);
194
+ const uncompressedSize = rowSize * height;
195
+
196
+ let data;
197
+
198
+ if (uncompressedSize < 12) {
199
+ if (sock.rQwait("TIGHT", uncompressedSize)) {
200
+ return false;
201
+ }
202
+
203
+ data = sock.rQshiftBytes(uncompressedSize);
204
+ } else {
205
+ data = this._readData(sock);
206
+ if (data === null) {
207
+ return false;
208
+ }
209
+
210
+ this._zlibs[streamId].setInput(data);
211
+ data = this._zlibs[streamId].inflate(uncompressedSize);
212
+ this._zlibs[streamId].setInput(null);
213
+ }
214
+
215
+ // Convert indexed (palette based) image data to RGB
216
+ if (this._numColors == 2) {
217
+ this._monoRect(x, y, width, height, data, this._palette, display);
218
+ } else {
219
+ this._paletteRect(x, y, width, height, data, this._palette, display);
220
+ }
221
+
222
+ this._numColors = 0;
223
+
224
+ return true;
225
+ }
226
+
227
+ _monoRect(x, y, width, height, data, palette, display) {
228
+ // Convert indexed (palette based) image data to RGB
229
+ // TODO: reduce number of calculations inside loop
230
+ const dest = this._getScratchBuffer(width * height * 4);
231
+ const w = Math.floor((width + 7) / 8);
232
+ const w1 = Math.floor(width / 8);
233
+
234
+ for (let y = 0; y < height; y++) {
235
+ let dp, sp, x;
236
+ for (x = 0; x < w1; x++) {
237
+ for (let b = 7; b >= 0; b--) {
238
+ dp = (y * width + x * 8 + 7 - b) * 4;
239
+ sp = (data[y * w + x] >> b & 1) * 3;
240
+ dest[dp] = palette[sp];
241
+ dest[dp + 1] = palette[sp + 1];
242
+ dest[dp + 2] = palette[sp + 2];
243
+ dest[dp + 3] = 255;
244
+ }
245
+ }
246
+
247
+ for (let b = 7; b >= 8 - width % 8; b--) {
248
+ dp = (y * width + x * 8 + 7 - b) * 4;
249
+ sp = (data[y * w + x] >> b & 1) * 3;
250
+ dest[dp] = palette[sp];
251
+ dest[dp + 1] = palette[sp + 1];
252
+ dest[dp + 2] = palette[sp + 2];
253
+ dest[dp + 3] = 255;
254
+ }
255
+ }
256
+
257
+ display.blitRgbxImage(x, y, width, height, dest, 0, false);
258
+ }
259
+
260
+ _paletteRect(x, y, width, height, data, palette, display) {
261
+ // Convert indexed (palette based) image data to RGB
262
+ const dest = this._getScratchBuffer(width * height * 4);
263
+ const total = width * height * 4;
264
+ for (let i = 0, j = 0; i < total; i += 4, j++) {
265
+ const sp = data[j] * 3;
266
+ dest[i] = palette[sp];
267
+ dest[i + 1] = palette[sp + 1];
268
+ dest[i + 2] = palette[sp + 2];
269
+ dest[i + 3] = 255;
270
+ }
271
+
272
+ display.blitRgbxImage(x, y, width, height, dest, 0, false);
273
+ }
274
+
275
+ _gradientFilter(streamId, x, y, width, height, sock, display, depth) {
276
+ throw new Error("Gradient filter not implemented");
277
+ }
278
+
279
+ _readData(sock) {
280
+ if (this._len === 0) {
281
+ if (sock.rQwait("TIGHT", 3)) {
282
+ return null;
283
+ }
284
+
285
+ let byte;
286
+
287
+ byte = sock.rQshift8();
288
+ this._len = byte & 0x7f;
289
+ if (byte & 0x80) {
290
+ byte = sock.rQshift8();
291
+ this._len |= (byte & 0x7f) << 7;
292
+ if (byte & 0x80) {
293
+ byte = sock.rQshift8();
294
+ this._len |= byte << 14;
295
+ }
296
+ }
297
+ }
298
+
299
+ if (sock.rQwait("TIGHT", this._len)) {
300
+ return null;
301
+ }
302
+
303
+ let data = sock.rQshiftBytes(this._len);
304
+ this._len = 0;
305
+
306
+ return data;
307
+ }
308
+
309
+ _getScratchBuffer(size) {
310
+ if (!this._scratchBuffer || (this._scratchBuffer.length < size)) {
311
+ this._scratchBuffer = new Uint8Array(size);
312
+ }
313
+ return this._scratchBuffer;
314
+ }
315
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * noVNC: HTML5 VNC client
3
+ * Copyright (C) 2019 The noVNC Authors
4
+ * Licensed under MPL 2.0 (see LICENSE.txt)
5
+ *
6
+ * See README.md for usage and integration instructions.
7
+ *
8
+ */
9
+
10
+ import TightDecoder from './tight.js';
11
+
12
+ export default class TightPNGDecoder extends TightDecoder {
13
+ _pngRect(x, y, width, height, sock, display, depth) {
14
+ let data = this._readData(sock);
15
+ if (data === null) {
16
+ return false;
17
+ }
18
+
19
+ display.imageRect(x, y, width, height, "image/png", data);
20
+
21
+ return true;
22
+ }
23
+
24
+ _basicRect(ctl, x, y, width, height, sock, display, depth) {
25
+ throw new Error("BasicCompression received in TightPNG rect");
26
+ }
27
+ }
@@ -0,0 +1,85 @@
1
+ /*
2
+ * noVNC: HTML5 VNC client
3
+ * Copyright (C) 2020 The noVNC Authors
4
+ * Licensed under MPL 2.0 (see LICENSE.txt)
5
+ *
6
+ * See README.md for usage and integration instructions.
7
+ */
8
+
9
+ import { deflateInit, deflate } from "../vendor/pako/lib/zlib/deflate.js";
10
+ import { Z_FULL_FLUSH } from "../vendor/pako/lib/zlib/deflate.js";
11
+ import ZStream from "../vendor/pako/lib/zlib/zstream.js";
12
+
13
+ export default class Deflator {
14
+ constructor() {
15
+ this.strm = new ZStream();
16
+ this.chunkSize = 1024 * 10 * 10;
17
+ this.outputBuffer = new Uint8Array(this.chunkSize);
18
+ this.windowBits = 5;
19
+
20
+ deflateInit(this.strm, this.windowBits);
21
+ }
22
+
23
+ deflate(inData) {
24
+ /* eslint-disable camelcase */
25
+ this.strm.input = inData;
26
+ this.strm.avail_in = this.strm.input.length;
27
+ this.strm.next_in = 0;
28
+ this.strm.output = this.outputBuffer;
29
+ this.strm.avail_out = this.chunkSize;
30
+ this.strm.next_out = 0;
31
+ /* eslint-enable camelcase */
32
+
33
+ let lastRet = deflate(this.strm, Z_FULL_FLUSH);
34
+ let outData = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
35
+
36
+ if (lastRet < 0) {
37
+ throw new Error("zlib deflate failed");
38
+ }
39
+
40
+ if (this.strm.avail_in > 0) {
41
+ // Read chunks until done
42
+
43
+ let chunks = [outData];
44
+ let totalLen = outData.length;
45
+ do {
46
+ /* eslint-disable camelcase */
47
+ this.strm.output = new Uint8Array(this.chunkSize);
48
+ this.strm.next_out = 0;
49
+ this.strm.avail_out = this.chunkSize;
50
+ /* eslint-enable camelcase */
51
+
52
+ lastRet = deflate(this.strm, Z_FULL_FLUSH);
53
+
54
+ if (lastRet < 0) {
55
+ throw new Error("zlib deflate failed");
56
+ }
57
+
58
+ let chunk = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
59
+ totalLen += chunk.length;
60
+ chunks.push(chunk);
61
+ } while (this.strm.avail_in > 0);
62
+
63
+ // Combine chunks into a single data
64
+
65
+ let newData = new Uint8Array(totalLen);
66
+ let offset = 0;
67
+
68
+ for (let i = 0; i < chunks.length; i++) {
69
+ newData.set(chunks[i], offset);
70
+ offset += chunks[i].length;
71
+ }
72
+
73
+ outData = newData;
74
+ }
75
+
76
+ /* eslint-disable camelcase */
77
+ this.strm.input = null;
78
+ this.strm.avail_in = 0;
79
+ this.strm.next_in = 0;
80
+ /* eslint-enable camelcase */
81
+
82
+ return outData;
83
+ }
84
+
85
+ }