@novnc/novnc 1.6.0 → 1.7.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 (103) hide show
  1. package/core/base64.js +104 -0
  2. package/core/crypto/aes.js +178 -0
  3. package/core/crypto/bigint.js +34 -0
  4. package/core/crypto/crypto.js +90 -0
  5. package/core/crypto/des.js +330 -0
  6. package/core/crypto/dh.js +55 -0
  7. package/core/crypto/md5.js +82 -0
  8. package/core/crypto/rsa.js +132 -0
  9. package/core/decoders/copyrect.js +27 -0
  10. package/core/decoders/h264.js +321 -0
  11. package/core/decoders/hextile.js +181 -0
  12. package/core/decoders/jpeg.js +161 -0
  13. package/core/decoders/raw.js +59 -0
  14. package/core/decoders/rre.js +44 -0
  15. package/core/decoders/tight.js +393 -0
  16. package/core/decoders/tightpng.js +27 -0
  17. package/core/decoders/zlib.js +51 -0
  18. package/core/decoders/zrle.js +185 -0
  19. package/core/deflator.js +84 -0
  20. package/core/display.js +578 -0
  21. package/core/encodings.js +54 -0
  22. package/core/inflator.js +65 -0
  23. package/core/input/domkeytable.js +311 -0
  24. package/core/input/fixedkeys.js +129 -0
  25. package/core/input/gesturehandler.js +567 -0
  26. package/core/input/keyboard.js +294 -0
  27. package/core/input/keysym.js +616 -0
  28. package/core/input/keysymdef.js +688 -0
  29. package/core/input/util.js +191 -0
  30. package/core/input/vkeys.js +116 -0
  31. package/core/input/xtscancodes.js +173 -0
  32. package/core/ra2.js +312 -0
  33. package/core/rfb.js +3411 -0
  34. package/core/util/browser.js +233 -0
  35. package/core/util/cursor.js +249 -0
  36. package/core/util/element.js +32 -0
  37. package/core/util/events.js +138 -0
  38. package/core/util/eventtarget.js +35 -0
  39. package/core/util/int.js +15 -0
  40. package/core/util/logging.js +56 -0
  41. package/core/util/strings.js +28 -0
  42. package/core/websock.js +369 -0
  43. package/docs/API.md +0 -5
  44. package/package.json +6 -10
  45. package/vendor/pako/LICENSE +21 -0
  46. package/vendor/pako/README.md +6 -0
  47. package/{lib/vendor → vendor}/pako/lib/utils/common.js +13 -23
  48. package/{lib/vendor → vendor}/pako/lib/zlib/adler32.js +12 -14
  49. package/vendor/pako/lib/zlib/constants.js +47 -0
  50. package/{lib/vendor → vendor}/pako/lib/zlib/crc32.js +15 -14
  51. package/{lib/vendor → vendor}/pako/lib/zlib/deflate.js +459 -334
  52. package/{lib/vendor → vendor}/pako/lib/zlib/gzheader.js +13 -19
  53. package/{lib/vendor → vendor}/pako/lib/zlib/inffast.js +116 -119
  54. package/vendor/pako/lib/zlib/inflate.js +1527 -0
  55. package/{lib/vendor → vendor}/pako/lib/zlib/inftrees.js +103 -91
  56. package/vendor/pako/lib/zlib/messages.js +11 -0
  57. package/{lib/vendor → vendor}/pako/lib/zlib/trees.js +313 -268
  58. package/{lib/vendor → vendor}/pako/lib/zlib/zstream.js +4 -10
  59. package/lib/base64.js +0 -100
  60. package/lib/crypto/aes.js +0 -481
  61. package/lib/crypto/bigint.js +0 -41
  62. package/lib/crypto/crypto.js +0 -109
  63. package/lib/crypto/des.js +0 -374
  64. package/lib/crypto/dh.js +0 -81
  65. package/lib/crypto/md5.js +0 -97
  66. package/lib/crypto/rsa.js +0 -312
  67. package/lib/decoders/copyrect.js +0 -40
  68. package/lib/decoders/h264.js +0 -349
  69. package/lib/decoders/hextile.js +0 -195
  70. package/lib/decoders/jpeg.js +0 -175
  71. package/lib/decoders/raw.js +0 -66
  72. package/lib/decoders/rre.js +0 -52
  73. package/lib/decoders/tight.js +0 -363
  74. package/lib/decoders/tightpng.js +0 -51
  75. package/lib/decoders/zlib.js +0 -57
  76. package/lib/decoders/zrle.js +0 -192
  77. package/lib/deflator.js +0 -88
  78. package/lib/display.js +0 -588
  79. package/lib/encodings.js +0 -70
  80. package/lib/inflator.js +0 -77
  81. package/lib/input/domkeytable.js +0 -313
  82. package/lib/input/fixedkeys.js +0 -127
  83. package/lib/input/gesturehandler.js +0 -573
  84. package/lib/input/keyboard.js +0 -293
  85. package/lib/input/keysym.js +0 -878
  86. package/lib/input/keysymdef.js +0 -1351
  87. package/lib/input/util.js +0 -217
  88. package/lib/input/vkeys.js +0 -121
  89. package/lib/input/xtscancodes.js +0 -343
  90. package/lib/ra2.js +0 -535
  91. package/lib/rfb.js +0 -3398
  92. package/lib/util/browser.js +0 -239
  93. package/lib/util/cursor.js +0 -269
  94. package/lib/util/element.js +0 -41
  95. package/lib/util/events.js +0 -133
  96. package/lib/util/eventtarget.js +0 -53
  97. package/lib/util/int.js +0 -21
  98. package/lib/util/logging.js +0 -56
  99. package/lib/util/strings.js +0 -36
  100. package/lib/vendor/pako/lib/zlib/constants.js +0 -47
  101. package/lib/vendor/pako/lib/zlib/inflate.js +0 -1602
  102. package/lib/vendor/pako/lib/zlib/messages.js +0 -25
  103. package/lib/websock.js +0 -395
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
11
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
12
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
13
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
17
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
- /*
21
- * noVNC: HTML5 VNC client
22
- * Copyright (C) 2019 The noVNC authors
23
- * Licensed under MPL 2.0 (see LICENSE.txt)
24
- *
25
- * See README.md for usage and integration instructions.
26
- *
27
- */
28
- var JPEGDecoder = exports["default"] = /*#__PURE__*/function () {
29
- function JPEGDecoder() {
30
- _classCallCheck(this, JPEGDecoder);
31
- // RealVNC will reuse the quantization tables
32
- // and Huffman tables, so we need to cache them.
33
- this._cachedQuantTables = [];
34
- this._cachedHuffmanTables = [];
35
- this._segments = [];
36
- }
37
- return _createClass(JPEGDecoder, [{
38
- key: "decodeRect",
39
- value: function decodeRect(x, y, width, height, sock, display, depth) {
40
- // A rect of JPEG encodings is simply a JPEG file
41
- while (true) {
42
- var segment = this._readSegment(sock);
43
- if (segment === null) {
44
- return false;
45
- }
46
- this._segments.push(segment);
47
- // End of image?
48
- if (segment[1] === 0xD9) {
49
- break;
50
- }
51
- }
52
- var huffmanTables = [];
53
- var quantTables = [];
54
- var _iterator = _createForOfIteratorHelper(this._segments),
55
- _step;
56
- try {
57
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
58
- var _segment = _step.value;
59
- var type = _segment[1];
60
- if (type === 0xC4) {
61
- // Huffman tables
62
- huffmanTables.push(_segment);
63
- } else if (type === 0xDB) {
64
- // Quantization tables
65
- quantTables.push(_segment);
66
- }
67
- }
68
- } catch (err) {
69
- _iterator.e(err);
70
- } finally {
71
- _iterator.f();
72
- }
73
- var sofIndex = this._segments.findIndex(function (x) {
74
- return x[1] == 0xC0 || x[1] == 0xC2;
75
- });
76
- if (sofIndex == -1) {
77
- throw new Error("Illegal JPEG image without SOF");
78
- }
79
- if (quantTables.length === 0) {
80
- var _this$_segments;
81
- (_this$_segments = this._segments).splice.apply(_this$_segments, [sofIndex + 1, 0].concat(_toConsumableArray(this._cachedQuantTables)));
82
- }
83
- if (huffmanTables.length === 0) {
84
- var _this$_segments2;
85
- (_this$_segments2 = this._segments).splice.apply(_this$_segments2, [sofIndex + 1, 0].concat(_toConsumableArray(this._cachedHuffmanTables)));
86
- }
87
- var length = 0;
88
- var _iterator2 = _createForOfIteratorHelper(this._segments),
89
- _step2;
90
- try {
91
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
92
- var _segment2 = _step2.value;
93
- length += _segment2.length;
94
- }
95
- } catch (err) {
96
- _iterator2.e(err);
97
- } finally {
98
- _iterator2.f();
99
- }
100
- var data = new Uint8Array(length);
101
- length = 0;
102
- var _iterator3 = _createForOfIteratorHelper(this._segments),
103
- _step3;
104
- try {
105
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
106
- var _segment3 = _step3.value;
107
- data.set(_segment3, length);
108
- length += _segment3.length;
109
- }
110
- } catch (err) {
111
- _iterator3.e(err);
112
- } finally {
113
- _iterator3.f();
114
- }
115
- display.imageRect(x, y, width, height, "image/jpeg", data);
116
- if (huffmanTables.length !== 0) {
117
- this._cachedHuffmanTables = huffmanTables;
118
- }
119
- if (quantTables.length !== 0) {
120
- this._cachedQuantTables = quantTables;
121
- }
122
- this._segments = [];
123
- return true;
124
- }
125
- }, {
126
- key: "_readSegment",
127
- value: function _readSegment(sock) {
128
- if (sock.rQwait("JPEG", 2)) {
129
- return null;
130
- }
131
- var marker = sock.rQshift8();
132
- if (marker != 0xFF) {
133
- throw new Error("Illegal JPEG marker received (byte: " + marker + ")");
134
- }
135
- var type = sock.rQshift8();
136
- if (type >= 0xD0 && type <= 0xD9 || type == 0x01) {
137
- // No length after marker
138
- return new Uint8Array([marker, type]);
139
- }
140
- if (sock.rQwait("JPEG", 2, 2)) {
141
- return null;
142
- }
143
- var length = sock.rQshift16();
144
- if (length < 2) {
145
- throw new Error("Illegal JPEG length received (length: " + length + ")");
146
- }
147
- if (sock.rQwait("JPEG", length - 2, 4)) {
148
- return null;
149
- }
150
- var extra = 0;
151
- if (type === 0xDA) {
152
- // start of scan
153
- extra += 2;
154
- while (true) {
155
- if (sock.rQwait("JPEG", length - 2 + extra, 4)) {
156
- return null;
157
- }
158
- var data = sock.rQpeekBytes(length - 2 + extra, false);
159
- if (data.at(-2) === 0xFF && data.at(-1) !== 0x00 && !(data.at(-1) >= 0xD0 && data.at(-1) <= 0xD7)) {
160
- extra -= 2;
161
- break;
162
- }
163
- extra++;
164
- }
165
- }
166
- var segment = new Uint8Array(2 + length + extra);
167
- segment[0] = marker;
168
- segment[1] = type;
169
- segment[2] = length >> 8;
170
- segment[3] = length;
171
- segment.set(sock.rQshiftBytes(length - 2 + extra, false), 4);
172
- return segment;
173
- }
174
- }]);
175
- }();
@@ -1,66 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
9
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
10
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- /*
14
- * noVNC: HTML5 VNC client
15
- * Copyright (C) 2019 The noVNC authors
16
- * Licensed under MPL 2.0 (see LICENSE.txt)
17
- *
18
- * See README.md for usage and integration instructions.
19
- *
20
- */
21
- var RawDecoder = exports["default"] = /*#__PURE__*/function () {
22
- function RawDecoder() {
23
- _classCallCheck(this, RawDecoder);
24
- this._lines = 0;
25
- }
26
- return _createClass(RawDecoder, [{
27
- key: "decodeRect",
28
- value: function decodeRect(x, y, width, height, sock, display, depth) {
29
- if (width === 0 || height === 0) {
30
- return true;
31
- }
32
- if (this._lines === 0) {
33
- this._lines = height;
34
- }
35
- var pixelSize = depth == 8 ? 1 : 4;
36
- var bytesPerLine = width * pixelSize;
37
- while (this._lines > 0) {
38
- if (sock.rQwait("RAW", bytesPerLine)) {
39
- return false;
40
- }
41
- var curY = y + (height - this._lines);
42
- var data = sock.rQshiftBytes(bytesPerLine, false);
43
-
44
- // Convert data if needed
45
- if (depth == 8) {
46
- var newdata = new Uint8Array(width * 4);
47
- for (var i = 0; i < width; i++) {
48
- newdata[i * 4 + 0] = (data[i] >> 0 & 0x3) * 255 / 3;
49
- newdata[i * 4 + 1] = (data[i] >> 2 & 0x3) * 255 / 3;
50
- newdata[i * 4 + 2] = (data[i] >> 4 & 0x3) * 255 / 3;
51
- newdata[i * 4 + 3] = 255;
52
- }
53
- data = newdata;
54
- }
55
-
56
- // Max sure the image is fully opaque
57
- for (var _i = 0; _i < width; _i++) {
58
- data[_i * 4 + 3] = 255;
59
- }
60
- display.blitImage(x, curY, width, 1, data, 0);
61
- this._lines--;
62
- }
63
- return true;
64
- }
65
- }]);
66
- }();
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
9
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
10
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- /*
14
- * noVNC: HTML5 VNC client
15
- * Copyright (C) 2019 The noVNC authors
16
- * Licensed under MPL 2.0 (see LICENSE.txt)
17
- *
18
- * See README.md for usage and integration instructions.
19
- *
20
- */
21
- var RREDecoder = exports["default"] = /*#__PURE__*/function () {
22
- function RREDecoder() {
23
- _classCallCheck(this, RREDecoder);
24
- this._subrects = 0;
25
- }
26
- return _createClass(RREDecoder, [{
27
- key: "decodeRect",
28
- value: function decodeRect(x, y, width, height, sock, display, depth) {
29
- if (this._subrects === 0) {
30
- if (sock.rQwait("RRE", 4 + 4)) {
31
- return false;
32
- }
33
- this._subrects = sock.rQshift32();
34
- var color = sock.rQshiftBytes(4); // Background
35
- display.fillRect(x, y, width, height, color);
36
- }
37
- while (this._subrects > 0) {
38
- if (sock.rQwait("RRE", 4 + 8)) {
39
- return false;
40
- }
41
- var _color = sock.rQshiftBytes(4);
42
- var sx = sock.rQshift16();
43
- var sy = sock.rQshift16();
44
- var swidth = sock.rQshift16();
45
- var sheight = sock.rQshift16();
46
- display.fillRect(x + sx, y + sy, swidth, sheight, _color);
47
- this._subrects--;
48
- }
49
- return true;
50
- }
51
- }]);
52
- }();
@@ -1,363 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var Log = _interopRequireWildcard(require("../util/logging.js"));
8
- var _inflator = _interopRequireDefault(require("../inflator.js"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
12
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
14
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
15
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
16
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
17
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
18
- * noVNC: HTML5 VNC client
19
- * Copyright (C) 2019 The noVNC authors
20
- * (c) 2012 Michael Tinglof, Joe Balaz, Les Piech (Mercuri.ca)
21
- * Licensed under MPL 2.0 (see LICENSE.txt)
22
- *
23
- * See README.md for usage and integration instructions.
24
- *
25
- */
26
- var TightDecoder = exports["default"] = /*#__PURE__*/function () {
27
- function TightDecoder() {
28
- _classCallCheck(this, TightDecoder);
29
- this._ctl = null;
30
- this._filter = null;
31
- this._numColors = 0;
32
- this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
33
- this._len = 0;
34
- this._zlibs = [];
35
- for (var i = 0; i < 4; i++) {
36
- this._zlibs[i] = new _inflator["default"]();
37
- }
38
- }
39
- return _createClass(TightDecoder, [{
40
- key: "decodeRect",
41
- value: function decodeRect(x, y, width, height, sock, display, depth) {
42
- if (this._ctl === null) {
43
- if (sock.rQwait("TIGHT compression-control", 1)) {
44
- return false;
45
- }
46
- this._ctl = sock.rQshift8();
47
-
48
- // Reset streams if the server requests it
49
- for (var i = 0; i < 4; i++) {
50
- if (this._ctl >> i & 1) {
51
- this._zlibs[i].reset();
52
- Log.Info("Reset zlib stream " + i);
53
- }
54
- }
55
-
56
- // Figure out filter
57
- this._ctl = this._ctl >> 4;
58
- }
59
- var ret;
60
- if (this._ctl === 0x08) {
61
- ret = this._fillRect(x, y, width, height, sock, display, depth);
62
- } else if (this._ctl === 0x09) {
63
- ret = this._jpegRect(x, y, width, height, sock, display, depth);
64
- } else if (this._ctl === 0x0A) {
65
- ret = this._pngRect(x, y, width, height, sock, display, depth);
66
- } else if ((this._ctl & 0x08) == 0) {
67
- ret = this._basicRect(this._ctl, x, y, width, height, sock, display, depth);
68
- } else {
69
- throw new Error("Illegal tight compression received (ctl: " + this._ctl + ")");
70
- }
71
- if (ret) {
72
- this._ctl = null;
73
- }
74
- return ret;
75
- }
76
- }, {
77
- key: "_fillRect",
78
- value: function _fillRect(x, y, width, height, sock, display, depth) {
79
- if (sock.rQwait("TIGHT", 3)) {
80
- return false;
81
- }
82
- var pixel = sock.rQshiftBytes(3);
83
- display.fillRect(x, y, width, height, pixel, false);
84
- return true;
85
- }
86
- }, {
87
- key: "_jpegRect",
88
- value: function _jpegRect(x, y, width, height, sock, display, depth) {
89
- var data = this._readData(sock);
90
- if (data === null) {
91
- return false;
92
- }
93
- display.imageRect(x, y, width, height, "image/jpeg", data);
94
- return true;
95
- }
96
- }, {
97
- key: "_pngRect",
98
- value: function _pngRect(x, y, width, height, sock, display, depth) {
99
- throw new Error("PNG received in standard Tight rect");
100
- }
101
- }, {
102
- key: "_basicRect",
103
- value: function _basicRect(ctl, x, y, width, height, sock, display, depth) {
104
- if (this._filter === null) {
105
- if (ctl & 0x4) {
106
- if (sock.rQwait("TIGHT", 1)) {
107
- return false;
108
- }
109
- this._filter = sock.rQshift8();
110
- } else {
111
- // Implicit CopyFilter
112
- this._filter = 0;
113
- }
114
- }
115
- var streamId = ctl & 0x3;
116
- var ret;
117
- switch (this._filter) {
118
- case 0:
119
- // CopyFilter
120
- ret = this._copyFilter(streamId, x, y, width, height, sock, display, depth);
121
- break;
122
- case 1:
123
- // PaletteFilter
124
- ret = this._paletteFilter(streamId, x, y, width, height, sock, display, depth);
125
- break;
126
- case 2:
127
- // GradientFilter
128
- ret = this._gradientFilter(streamId, x, y, width, height, sock, display, depth);
129
- break;
130
- default:
131
- throw new Error("Illegal tight filter received (ctl: " + this._filter + ")");
132
- }
133
- if (ret) {
134
- this._filter = null;
135
- }
136
- return ret;
137
- }
138
- }, {
139
- key: "_copyFilter",
140
- value: function _copyFilter(streamId, x, y, width, height, sock, display, depth) {
141
- var uncompressedSize = width * height * 3;
142
- var data;
143
- if (uncompressedSize === 0) {
144
- return true;
145
- }
146
- if (uncompressedSize < 12) {
147
- if (sock.rQwait("TIGHT", uncompressedSize)) {
148
- return false;
149
- }
150
- data = sock.rQshiftBytes(uncompressedSize);
151
- } else {
152
- data = this._readData(sock);
153
- if (data === null) {
154
- return false;
155
- }
156
- this._zlibs[streamId].setInput(data);
157
- data = this._zlibs[streamId].inflate(uncompressedSize);
158
- this._zlibs[streamId].setInput(null);
159
- }
160
- var rgbx = new Uint8Array(width * height * 4);
161
- for (var i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
162
- rgbx[i] = data[j];
163
- rgbx[i + 1] = data[j + 1];
164
- rgbx[i + 2] = data[j + 2];
165
- rgbx[i + 3] = 255; // Alpha
166
- }
167
- display.blitImage(x, y, width, height, rgbx, 0, false);
168
- return true;
169
- }
170
- }, {
171
- key: "_paletteFilter",
172
- value: function _paletteFilter(streamId, x, y, width, height, sock, display, depth) {
173
- if (this._numColors === 0) {
174
- if (sock.rQwait("TIGHT palette", 1)) {
175
- return false;
176
- }
177
- var numColors = sock.rQpeek8() + 1;
178
- var paletteSize = numColors * 3;
179
- if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
180
- return false;
181
- }
182
- this._numColors = numColors;
183
- sock.rQskipBytes(1);
184
- sock.rQshiftTo(this._palette, paletteSize);
185
- }
186
- var bpp = this._numColors <= 2 ? 1 : 8;
187
- var rowSize = Math.floor((width * bpp + 7) / 8);
188
- var uncompressedSize = rowSize * height;
189
- var data;
190
- if (uncompressedSize === 0) {
191
- return true;
192
- }
193
- if (uncompressedSize < 12) {
194
- if (sock.rQwait("TIGHT", uncompressedSize)) {
195
- return false;
196
- }
197
- data = sock.rQshiftBytes(uncompressedSize);
198
- } else {
199
- data = this._readData(sock);
200
- if (data === null) {
201
- return false;
202
- }
203
- this._zlibs[streamId].setInput(data);
204
- data = this._zlibs[streamId].inflate(uncompressedSize);
205
- this._zlibs[streamId].setInput(null);
206
- }
207
-
208
- // Convert indexed (palette based) image data to RGB
209
- if (this._numColors == 2) {
210
- this._monoRect(x, y, width, height, data, this._palette, display);
211
- } else {
212
- this._paletteRect(x, y, width, height, data, this._palette, display);
213
- }
214
- this._numColors = 0;
215
- return true;
216
- }
217
- }, {
218
- key: "_monoRect",
219
- value: function _monoRect(x, y, width, height, data, palette, display) {
220
- // Convert indexed (palette based) image data to RGB
221
- // TODO: reduce number of calculations inside loop
222
- var dest = this._getScratchBuffer(width * height * 4);
223
- var w = Math.floor((width + 7) / 8);
224
- var w1 = Math.floor(width / 8);
225
- for (var _y = 0; _y < height; _y++) {
226
- var dp = void 0,
227
- sp = void 0,
228
- _x = void 0;
229
- for (_x = 0; _x < w1; _x++) {
230
- for (var b = 7; b >= 0; b--) {
231
- dp = (_y * width + _x * 8 + 7 - b) * 4;
232
- sp = (data[_y * w + _x] >> b & 1) * 3;
233
- dest[dp] = palette[sp];
234
- dest[dp + 1] = palette[sp + 1];
235
- dest[dp + 2] = palette[sp + 2];
236
- dest[dp + 3] = 255;
237
- }
238
- }
239
- for (var _b = 7; _b >= 8 - width % 8; _b--) {
240
- dp = (_y * width + _x * 8 + 7 - _b) * 4;
241
- sp = (data[_y * w + _x] >> _b & 1) * 3;
242
- dest[dp] = palette[sp];
243
- dest[dp + 1] = palette[sp + 1];
244
- dest[dp + 2] = palette[sp + 2];
245
- dest[dp + 3] = 255;
246
- }
247
- }
248
- display.blitImage(x, y, width, height, dest, 0, false);
249
- }
250
- }, {
251
- key: "_paletteRect",
252
- value: function _paletteRect(x, y, width, height, data, palette, display) {
253
- // Convert indexed (palette based) image data to RGB
254
- var dest = this._getScratchBuffer(width * height * 4);
255
- var total = width * height * 4;
256
- for (var i = 0, j = 0; i < total; i += 4, j++) {
257
- var sp = data[j] * 3;
258
- dest[i] = palette[sp];
259
- dest[i + 1] = palette[sp + 1];
260
- dest[i + 2] = palette[sp + 2];
261
- dest[i + 3] = 255;
262
- }
263
- display.blitImage(x, y, width, height, dest, 0, false);
264
- }
265
- }, {
266
- key: "_gradientFilter",
267
- value: function _gradientFilter(streamId, x, y, width, height, sock, display, depth) {
268
- // assume the TPIXEL is 3 bytes long
269
- var uncompressedSize = width * height * 3;
270
- var data;
271
- if (uncompressedSize === 0) {
272
- return true;
273
- }
274
- if (uncompressedSize < 12) {
275
- if (sock.rQwait("TIGHT", uncompressedSize)) {
276
- return false;
277
- }
278
- data = sock.rQshiftBytes(uncompressedSize);
279
- } else {
280
- data = this._readData(sock);
281
- if (data === null) {
282
- return false;
283
- }
284
- this._zlibs[streamId].setInput(data);
285
- data = this._zlibs[streamId].inflate(uncompressedSize);
286
- this._zlibs[streamId].setInput(null);
287
- }
288
- var rgbx = new Uint8Array(4 * width * height);
289
- var rgbxIndex = 0,
290
- dataIndex = 0;
291
- var left = new Uint8Array(3);
292
- for (var _x2 = 0; _x2 < width; _x2++) {
293
- for (var c = 0; c < 3; c++) {
294
- var prediction = left[c];
295
- var value = data[dataIndex++] + prediction;
296
- rgbx[rgbxIndex++] = value;
297
- left[c] = value;
298
- }
299
- rgbx[rgbxIndex++] = 255;
300
- }
301
- var upperIndex = 0;
302
- var upper = new Uint8Array(3),
303
- upperleft = new Uint8Array(3);
304
- for (var _y2 = 1; _y2 < height; _y2++) {
305
- left.fill(0);
306
- upperleft.fill(0);
307
- for (var _x3 = 0; _x3 < width; _x3++) {
308
- for (var _c = 0; _c < 3; _c++) {
309
- upper[_c] = rgbx[upperIndex++];
310
- var _prediction = left[_c] + upper[_c] - upperleft[_c];
311
- if (_prediction < 0) {
312
- _prediction = 0;
313
- } else if (_prediction > 255) {
314
- _prediction = 255;
315
- }
316
- var _value = data[dataIndex++] + _prediction;
317
- rgbx[rgbxIndex++] = _value;
318
- upperleft[_c] = upper[_c];
319
- left[_c] = _value;
320
- }
321
- rgbx[rgbxIndex++] = 255;
322
- upperIndex++;
323
- }
324
- }
325
- display.blitImage(x, y, width, height, rgbx, 0, false);
326
- return true;
327
- }
328
- }, {
329
- key: "_readData",
330
- value: function _readData(sock) {
331
- if (this._len === 0) {
332
- if (sock.rQwait("TIGHT", 3)) {
333
- return null;
334
- }
335
- var _byte;
336
- _byte = sock.rQshift8();
337
- this._len = _byte & 0x7f;
338
- if (_byte & 0x80) {
339
- _byte = sock.rQshift8();
340
- this._len |= (_byte & 0x7f) << 7;
341
- if (_byte & 0x80) {
342
- _byte = sock.rQshift8();
343
- this._len |= _byte << 14;
344
- }
345
- }
346
- }
347
- if (sock.rQwait("TIGHT", this._len)) {
348
- return null;
349
- }
350
- var data = sock.rQshiftBytes(this._len, false);
351
- this._len = 0;
352
- return data;
353
- }
354
- }, {
355
- key: "_getScratchBuffer",
356
- value: function _getScratchBuffer(size) {
357
- if (!this._scratchBuffer || this._scratchBuffer.length < size) {
358
- this._scratchBuffer = new Uint8Array(size);
359
- }
360
- return this._scratchBuffer;
361
- }
362
- }]);
363
- }();