@novnc/novnc 1.2.0 → 1.3.0-g0ef7582

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 (75) hide show
  1. package/LICENSE.txt +0 -6
  2. package/README.md +16 -6
  3. package/core/decoders/copyrect.js +5 -0
  4. package/core/decoders/hextile.js +57 -3
  5. package/core/decoders/jpeg.js +141 -0
  6. package/core/decoders/raw.js +12 -2
  7. package/core/decoders/tight.js +24 -8
  8. package/core/decoders/zrle.js +185 -0
  9. package/core/display.js +21 -151
  10. package/core/encodings.js +4 -0
  11. package/core/input/domkeytable.js +25 -21
  12. package/core/input/keyboard.js +22 -127
  13. package/core/input/util.js +18 -35
  14. package/core/input/vkeys.js +0 -1
  15. package/core/input/xtscancodes.js +5 -3
  16. package/core/ra2.js +567 -0
  17. package/core/rfb.js +487 -171
  18. package/core/util/browser.js +0 -17
  19. package/core/util/cursor.js +1 -11
  20. package/core/util/events.js +0 -4
  21. package/core/util/md5.js +79 -0
  22. package/core/websock.js +76 -17
  23. package/docs/API.md +107 -6
  24. package/docs/LIBRARY.md +3 -7
  25. package/lib/base64.js +24 -38
  26. package/lib/decoders/copyrect.js +6 -11
  27. package/lib/decoders/hextile.js +68 -44
  28. package/lib/decoders/jpeg.js +146 -0
  29. package/lib/decoders/raw.js +14 -21
  30. package/lib/decoders/rre.js +3 -17
  31. package/lib/decoders/tight.js +43 -93
  32. package/lib/decoders/tightpng.js +11 -33
  33. package/lib/decoders/zrle.js +185 -0
  34. package/lib/deflator.js +9 -26
  35. package/lib/des.js +22 -38
  36. package/lib/display.js +100 -315
  37. package/lib/encodings.js +7 -8
  38. package/lib/inflator.js +6 -22
  39. package/lib/input/domkeytable.js +240 -208
  40. package/lib/input/fixedkeys.js +10 -5
  41. package/lib/input/gesturehandler.js +84 -154
  42. package/lib/input/keyboard.js +87 -238
  43. package/lib/input/keysym.js +16 -272
  44. package/lib/input/keysymdef.js +7 -9
  45. package/lib/input/util.js +69 -156
  46. package/lib/input/vkeys.js +2 -7
  47. package/lib/input/xtscancodes.js +10 -171
  48. package/lib/ra2.js +1033 -0
  49. package/lib/rfb.js +947 -1149
  50. package/lib/util/browser.js +25 -52
  51. package/lib/util/cursor.js +25 -81
  52. package/lib/util/element.js +3 -5
  53. package/lib/util/events.js +26 -35
  54. package/lib/util/eventtarget.js +4 -16
  55. package/lib/util/int.js +2 -3
  56. package/lib/util/logging.js +3 -21
  57. package/lib/util/md5.js +83 -0
  58. package/lib/util/strings.js +3 -5
  59. package/lib/vendor/pako/lib/utils/common.js +10 -19
  60. package/lib/vendor/pako/lib/zlib/adler32.js +4 -8
  61. package/lib/vendor/pako/lib/zlib/constants.js +4 -7
  62. package/lib/vendor/pako/lib/zlib/crc32.js +6 -13
  63. package/lib/vendor/pako/lib/zlib/deflate.js +304 -708
  64. package/lib/vendor/pako/lib/zlib/gzheader.js +2 -14
  65. package/lib/vendor/pako/lib/zlib/inffast.js +61 -177
  66. package/lib/vendor/pako/lib/zlib/inflate.js +421 -909
  67. package/lib/vendor/pako/lib/zlib/inftrees.js +66 -172
  68. package/lib/vendor/pako/lib/zlib/messages.js +3 -13
  69. package/lib/vendor/pako/lib/zlib/trees.js +250 -592
  70. package/lib/vendor/pako/lib/zlib/zstream.js +3 -19
  71. package/lib/websock.js +119 -111
  72. package/package.json +2 -10
  73. package/core/util/polyfill.js +0 -61
  74. package/lib/util/polyfill.js +0 -72
  75. package/lib/vendor/promise.js +0 -255
package/lib/rfb.js CHANGED
@@ -1,153 +1,150 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.default = void 0;
7
-
7
+ exports["default"] = void 0;
8
8
  var _int = require("./util/int.js");
9
-
10
9
  var Log = _interopRequireWildcard(require("./util/logging.js"));
11
-
12
10
  var _strings = require("./util/strings.js");
13
-
14
11
  var _browser = require("./util/browser.js");
15
-
16
12
  var _element = require("./util/element.js");
17
-
18
13
  var _events = require("./util/events.js");
19
-
20
14
  var _eventtarget = _interopRequireDefault(require("./util/eventtarget.js"));
21
-
22
15
  var _display = _interopRequireDefault(require("./display.js"));
23
-
24
16
  var _inflator = _interopRequireDefault(require("./inflator.js"));
25
-
26
17
  var _deflator = _interopRequireDefault(require("./deflator.js"));
27
-
28
18
  var _keyboard = _interopRequireDefault(require("./input/keyboard.js"));
29
-
30
19
  var _gesturehandler = _interopRequireDefault(require("./input/gesturehandler.js"));
31
-
32
20
  var _cursor = _interopRequireDefault(require("./util/cursor.js"));
33
-
34
21
  var _websock = _interopRequireDefault(require("./websock.js"));
35
-
36
22
  var _des = _interopRequireDefault(require("./des.js"));
37
-
38
23
  var _keysym = _interopRequireDefault(require("./input/keysym.js"));
39
-
40
24
  var _xtscancodes = _interopRequireDefault(require("./input/xtscancodes.js"));
41
-
42
25
  var _encodings = require("./encodings.js");
43
-
44
- require("./util/polyfill.js");
45
-
26
+ var _ra = _interopRequireDefault(require("./ra2.js"));
27
+ var _md = require("./util/md5.js");
46
28
  var _raw = _interopRequireDefault(require("./decoders/raw.js"));
47
-
48
29
  var _copyrect = _interopRequireDefault(require("./decoders/copyrect.js"));
49
-
50
30
  var _rre = _interopRequireDefault(require("./decoders/rre.js"));
51
-
52
31
  var _hextile = _interopRequireDefault(require("./decoders/hextile.js"));
53
-
54
32
  var _tight = _interopRequireDefault(require("./decoders/tight.js"));
55
-
56
33
  var _tightpng = _interopRequireDefault(require("./decoders/tightpng.js"));
57
-
58
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
-
60
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
61
-
62
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
63
-
64
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
65
-
34
+ var _zrle = _interopRequireDefault(require("./decoders/zrle.js"));
35
+ var _jpeg = _interopRequireDefault(require("./decoders/jpeg.js"));
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
37
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
38
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
39
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
40
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
41
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
42
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
44
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
45
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
46
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
47
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
48
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
66
49
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
67
-
68
50
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
69
-
70
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
71
-
72
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
73
-
74
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
75
-
51
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
52
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
53
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
76
54
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
77
-
78
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
79
-
55
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
80
56
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
81
-
82
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
83
-
84
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
85
-
57
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
58
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
86
59
  // How many seconds to wait for a disconnect to finish
87
60
  var DISCONNECT_TIMEOUT = 3;
88
- var DEFAULT_BACKGROUND = 'rgb(40, 40, 40)'; // Minimum wait (ms) between two mouse moves
61
+ var DEFAULT_BACKGROUND = 'rgb(40, 40, 40)';
89
62
 
90
- var MOUSE_MOVE_DELAY = 17; // Wheel thresholds
63
+ // Minimum wait (ms) between two mouse moves
64
+ var MOUSE_MOVE_DELAY = 17;
91
65
 
66
+ // Wheel thresholds
92
67
  var WHEEL_STEP = 50; // Pixels needed for one step
93
-
94
68
  var WHEEL_LINE_HEIGHT = 19; // Assumed pixels for one line step
95
- // Gesture thresholds
96
69
 
70
+ // Gesture thresholds
97
71
  var GESTURE_ZOOMSENS = 75;
98
72
  var GESTURE_SCRLSENS = 50;
99
73
  var DOUBLE_TAP_TIMEOUT = 1000;
100
- var DOUBLE_TAP_THRESHOLD = 50; // Extended clipboard pseudo-encoding formats
74
+ var DOUBLE_TAP_THRESHOLD = 50;
75
+
76
+ // Security types
77
+ var securityTypeNone = 1;
78
+ var securityTypeVNCAuth = 2;
79
+ var securityTypeRA2ne = 6;
80
+ var securityTypeTight = 16;
81
+ var securityTypeVeNCrypt = 19;
82
+ var securityTypeXVP = 22;
83
+ var securityTypeARD = 30;
84
+
85
+ // Special Tight security types
86
+ var securityTypeUnixLogon = 129;
101
87
 
88
+ // VeNCrypt security types
89
+ var securityTypePlain = 256;
90
+
91
+ // Extended clipboard pseudo-encoding formats
102
92
  var extendedClipboardFormatText = 1;
103
93
  /*eslint-disable no-unused-vars */
104
-
105
94
  var extendedClipboardFormatRtf = 1 << 1;
106
95
  var extendedClipboardFormatHtml = 1 << 2;
107
96
  var extendedClipboardFormatDib = 1 << 3;
108
97
  var extendedClipboardFormatFiles = 1 << 4;
109
98
  /*eslint-enable */
110
- // Extended clipboard pseudo-encoding actions
111
99
 
100
+ // Extended clipboard pseudo-encoding actions
112
101
  var extendedClipboardActionCaps = 1 << 24;
113
102
  var extendedClipboardActionRequest = 1 << 25;
114
103
  var extendedClipboardActionPeek = 1 << 26;
115
104
  var extendedClipboardActionNotify = 1 << 27;
116
105
  var extendedClipboardActionProvide = 1 << 28;
117
-
118
106
  var RFB = /*#__PURE__*/function (_EventTargetMixin) {
119
107
  _inherits(RFB, _EventTargetMixin);
120
-
121
108
  var _super = _createSuper(RFB);
122
-
123
- function RFB(target, url, options) {
109
+ function RFB(target, urlOrChannel, options) {
124
110
  var _this;
125
-
126
111
  _classCallCheck(this, RFB);
127
-
128
112
  if (!target) {
129
113
  throw new Error("Must specify target");
130
114
  }
131
-
132
- if (!url) {
133
- throw new Error("Must specify URL");
115
+ if (!urlOrChannel) {
116
+ throw new Error("Must specify URL, WebSocket or RTCDataChannel");
134
117
  }
135
118
 
119
+ // We rely on modern APIs which might not be available in an
120
+ // insecure context
121
+ if (!window.isSecureContext) {
122
+ Log.Error("noVNC requires a secure context (TLS). Expect crashes!");
123
+ }
136
124
  _this = _super.call(this);
137
125
  _this._target = target;
138
- _this._url = url; // Connection details
126
+ if (typeof urlOrChannel === "string") {
127
+ _this._url = urlOrChannel;
128
+ } else {
129
+ _this._url = null;
130
+ _this._rawChannel = urlOrChannel;
131
+ }
139
132
 
133
+ // Connection details
140
134
  options = options || {};
141
135
  _this._rfbCredentials = options.credentials || {};
142
136
  _this._shared = 'shared' in options ? !!options.shared : true;
143
137
  _this._repeaterID = options.repeaterID || '';
144
- _this._wsProtocols = options.wsProtocols || []; // Internal state
138
+ _this._wsProtocols = options.wsProtocols || [];
145
139
 
140
+ // Internal state
146
141
  _this._rfbConnectionState = '';
147
142
  _this._rfbInitState = '';
148
143
  _this._rfbAuthScheme = -1;
149
- _this._rfbCleanDisconnect = true; // Server capabilities
144
+ _this._rfbCleanDisconnect = true;
145
+ _this._rfbRSAAESAuthenticationState = null;
150
146
 
147
+ // Server capabilities
151
148
  _this._rfbVersion = 0;
152
149
  _this._rfbMaxVersion = 3.8;
153
150
  _this._rfbTightVNC = false;
@@ -168,25 +165,22 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
168
165
  _this._qemuExtKeyEventSupported = false;
169
166
  _this._clipboardText = null;
170
167
  _this._clipboardServerCapabilitiesActions = {};
171
- _this._clipboardServerCapabilitiesFormats = {}; // Internal objects
168
+ _this._clipboardServerCapabilitiesFormats = {};
172
169
 
170
+ // Internal objects
173
171
  _this._sock = null; // Websock object
174
-
175
172
  _this._display = null; // Display object
176
-
177
173
  _this._flushing = false; // Display flushing state
178
-
179
174
  _this._keyboard = null; // Keyboard input handler object
180
-
181
175
  _this._gestures = null; // Gesture input handler object
182
- // Timers
176
+ _this._resizeObserver = null; // Resize observer object
183
177
 
178
+ // Timers
184
179
  _this._disconnTimer = null; // disconnection timer
185
-
186
180
  _this._resizeTimeout = null; // resize rate limiting
181
+ _this._mouseMoveTimer = null;
187
182
 
188
- _this._mouseMoveTimer = null; // Decoder states
189
-
183
+ // Decoder states
190
184
  _this._decoders = {};
191
185
  _this._FBU = {
192
186
  rects: 0,
@@ -195,8 +189,9 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
195
189
  width: 0,
196
190
  height: 0,
197
191
  encoding: null
198
- }; // Mouse state
192
+ };
199
193
 
194
+ // Mouse state
200
195
  _this._mousePos = {};
201
196
  _this._mouseButtonMask = 0;
202
197
  _this._mouseLastMoveTime = 0;
@@ -204,23 +199,29 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
204
199
  _this._viewportDragPos = {};
205
200
  _this._viewportHasMoved = false;
206
201
  _this._accumulatedWheelDeltaX = 0;
207
- _this._accumulatedWheelDeltaY = 0; // Gesture state
202
+ _this._accumulatedWheelDeltaY = 0;
208
203
 
204
+ // Gesture state
209
205
  _this._gestureLastTapTime = null;
210
206
  _this._gestureFirstDoubleTapEv = null;
211
207
  _this._gestureLastMagnitudeX = 0;
212
- _this._gestureLastMagnitudeY = 0; // Bound event handlers
208
+ _this._gestureLastMagnitudeY = 0;
213
209
 
210
+ // Bound event handlers
214
211
  _this._eventHandlers = {
215
212
  focusCanvas: _this._focusCanvas.bind(_assertThisInitialized(_this)),
216
- windowResize: _this._windowResize.bind(_assertThisInitialized(_this)),
213
+ handleResize: _this._handleResize.bind(_assertThisInitialized(_this)),
217
214
  handleMouse: _this._handleMouse.bind(_assertThisInitialized(_this)),
218
215
  handleWheel: _this._handleWheel.bind(_assertThisInitialized(_this)),
219
- handleGesture: _this._handleGesture.bind(_assertThisInitialized(_this))
220
- }; // main setup
216
+ handleGesture: _this._handleGesture.bind(_assertThisInitialized(_this)),
217
+ handleRSAAESCredentialsRequired: _this._handleRSAAESCredentialsRequired.bind(_assertThisInitialized(_this)),
218
+ handleRSAAESServerVerification: _this._handleRSAAESServerVerification.bind(_assertThisInitialized(_this))
219
+ };
221
220
 
222
- Log.Debug(">> RFB.constructor"); // Create DOM elements
221
+ // main setup
222
+ Log.Debug(">> RFB.constructor");
223
223
 
224
+ // Create DOM elements
224
225
  _this._screen = document.createElement('div');
225
226
  _this._screen.style.display = 'flex';
226
227
  _this._screen.style.width = '100%';
@@ -228,19 +229,18 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
228
229
  _this._screen.style.overflow = 'auto';
229
230
  _this._screen.style.background = DEFAULT_BACKGROUND;
230
231
  _this._canvas = document.createElement('canvas');
231
- _this._canvas.style.margin = 'auto'; // Some browsers add an outline on focus
232
-
233
- _this._canvas.style.outline = 'none'; // IE miscalculates width without this :(
234
-
235
- _this._canvas.style.flexShrink = '0';
232
+ _this._canvas.style.margin = 'auto';
233
+ // Some browsers add an outline on focus
234
+ _this._canvas.style.outline = 'none';
236
235
  _this._canvas.width = 0;
237
236
  _this._canvas.height = 0;
238
237
  _this._canvas.tabIndex = -1;
238
+ _this._screen.appendChild(_this._canvas);
239
239
 
240
- _this._screen.appendChild(_this._canvas); // Cursor
240
+ // Cursor
241
+ _this._cursor = new _cursor["default"]();
241
242
 
242
-
243
- _this._cursor = new _cursor.default(); // XXX: TightVNC 2.8.11 sends no cursor at all until Windows changes
243
+ // XXX: TightVNC 2.8.11 sends no cursor at all until Windows changes
244
244
  // it. Result: no cursor at all until a window border or an edit field
245
245
  // is hit blindly. But there are also VNC servers that draw the cursor
246
246
  // in the framebuffer and don't send the empty local cursor. There is
@@ -249,99 +249,44 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
249
249
  // The spec is unclear on this "initial cursor" issue. Many other
250
250
  // viewers (TigerVNC, RealVNC, Remmina) display an arrow as the
251
251
  // initial cursor instead.
252
-
253
- _this._cursorImage = RFB.cursors.none; // populate decoder array with objects
254
-
255
- _this._decoders[_encodings.encodings.encodingRaw] = new _raw.default();
256
- _this._decoders[_encodings.encodings.encodingCopyRect] = new _copyrect.default();
257
- _this._decoders[_encodings.encodings.encodingRRE] = new _rre.default();
258
- _this._decoders[_encodings.encodings.encodingHextile] = new _hextile.default();
259
- _this._decoders[_encodings.encodings.encodingTight] = new _tight.default();
260
- _this._decoders[_encodings.encodings.encodingTightPNG] = new _tightpng.default(); // NB: nothing that needs explicit teardown should be done
252
+ _this._cursorImage = RFB.cursors.none;
253
+
254
+ // populate decoder array with objects
255
+ _this._decoders[_encodings.encodings.encodingRaw] = new _raw["default"]();
256
+ _this._decoders[_encodings.encodings.encodingCopyRect] = new _copyrect["default"]();
257
+ _this._decoders[_encodings.encodings.encodingRRE] = new _rre["default"]();
258
+ _this._decoders[_encodings.encodings.encodingHextile] = new _hextile["default"]();
259
+ _this._decoders[_encodings.encodings.encodingTight] = new _tight["default"]();
260
+ _this._decoders[_encodings.encodings.encodingTightPNG] = new _tightpng["default"]();
261
+ _this._decoders[_encodings.encodings.encodingZRLE] = new _zrle["default"]();
262
+ _this._decoders[_encodings.encodings.encodingJPEG] = new _jpeg["default"]();
263
+
264
+ // NB: nothing that needs explicit teardown should be done
261
265
  // before this point, since this can throw an exception
262
-
263
266
  try {
264
- _this._display = new _display.default(_this._canvas);
267
+ _this._display = new _display["default"](_this._canvas);
265
268
  } catch (exc) {
266
269
  Log.Error("Display exception: " + exc);
267
270
  throw exc;
268
271
  }
269
-
270
272
  _this._display.onflush = _this._onFlush.bind(_assertThisInitialized(_this));
271
- _this._keyboard = new _keyboard.default(_this._canvas);
273
+ _this._keyboard = new _keyboard["default"](_this._canvas);
272
274
  _this._keyboard.onkeyevent = _this._handleKeyEvent.bind(_assertThisInitialized(_this));
273
- _this._gestures = new _gesturehandler.default();
274
- _this._sock = new _websock.default();
275
-
276
- _this._sock.on('message', function () {
277
- _this._handleMessage();
278
- });
279
-
280
- _this._sock.on('open', function () {
281
- if (_this._rfbConnectionState === 'connecting' && _this._rfbInitState === '') {
282
- _this._rfbInitState = 'ProtocolVersion';
283
- Log.Debug("Starting VNC handshake");
284
- } else {
285
- _this._fail("Unexpected server connection while " + _this._rfbConnectionState);
286
- }
287
- });
288
-
289
- _this._sock.on('close', function (e) {
290
- Log.Debug("WebSocket on-close event");
291
- var msg = "";
292
-
293
- if (e.code) {
294
- msg = "(code: " + e.code;
295
-
296
- if (e.reason) {
297
- msg += ", reason: " + e.reason;
298
- }
299
-
300
- msg += ")";
301
- }
302
-
303
- switch (_this._rfbConnectionState) {
304
- case 'connecting':
305
- _this._fail("Connection closed " + msg);
306
-
307
- break;
308
-
309
- case 'connected':
310
- // Handle disconnects that were initiated server-side
311
- _this._updateConnectionState('disconnecting');
312
-
313
- _this._updateConnectionState('disconnected');
314
-
315
- break;
316
-
317
- case 'disconnecting':
318
- // Normal disconnection path
319
- _this._updateConnectionState('disconnected');
320
-
321
- break;
322
-
323
- case 'disconnected':
324
- _this._fail("Unexpected server disconnect " + "when already disconnected " + msg);
325
-
326
- break;
327
-
328
- default:
329
- _this._fail("Unexpected server disconnect before connecting " + msg);
330
-
331
- break;
332
- }
333
-
334
- _this._sock.off('close');
335
- });
336
-
337
- _this._sock.on('error', function (e) {
338
- return Log.Warn("WebSocket on-error event");
339
- }); // Slight delay of the actual connection so that the caller has
340
- // time to set up callbacks
341
-
342
-
343
- setTimeout(_this._updateConnectionState.bind(_assertThisInitialized(_this), 'connecting'));
344
- Log.Debug("<< RFB.constructor"); // ===== PROPERTIES =====
275
+ _this._gestures = new _gesturehandler["default"]();
276
+ _this._sock = new _websock["default"]();
277
+ _this._sock.on('open', _this._socketOpen.bind(_assertThisInitialized(_this)));
278
+ _this._sock.on('close', _this._socketClose.bind(_assertThisInitialized(_this)));
279
+ _this._sock.on('message', _this._handleMessage.bind(_assertThisInitialized(_this)));
280
+ _this._sock.on('error', _this._socketError.bind(_assertThisInitialized(_this)));
281
+ _this._expectedClientWidth = null;
282
+ _this._expectedClientHeight = null;
283
+ _this._resizeObserver = new ResizeObserver(_this._eventHandlers.handleResize);
284
+
285
+ // All prepared, kick off the connection
286
+ _this._updateConnectionState('connecting');
287
+ Log.Debug("<< RFB.constructor");
288
+
289
+ // ===== PROPERTIES =====
345
290
 
346
291
  _this.dragViewport = false;
347
292
  _this.focusOnClick = true;
@@ -350,35 +295,159 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
350
295
  _this._scaleViewport = false;
351
296
  _this._resizeSession = false;
352
297
  _this._showDotCursor = false;
353
-
354
298
  if (options.showDotCursor !== undefined) {
355
299
  Log.Warn("Specifying showDotCursor as a RFB constructor argument is deprecated");
356
300
  _this._showDotCursor = options.showDotCursor;
357
301
  }
358
-
359
302
  _this._qualityLevel = 6;
360
303
  _this._compressionLevel = 2;
361
304
  return _this;
362
- } // ===== PROPERTIES =====
363
-
305
+ }
364
306
 
307
+ // ===== PROPERTIES =====
365
308
  _createClass(RFB, [{
366
- key: "disconnect",
309
+ key: "viewOnly",
310
+ get: function get() {
311
+ return this._viewOnly;
312
+ },
313
+ set: function set(viewOnly) {
314
+ this._viewOnly = viewOnly;
315
+ if (this._rfbConnectionState === "connecting" || this._rfbConnectionState === "connected") {
316
+ if (viewOnly) {
317
+ this._keyboard.ungrab();
318
+ } else {
319
+ this._keyboard.grab();
320
+ }
321
+ }
322
+ }
323
+ }, {
324
+ key: "capabilities",
325
+ get: function get() {
326
+ return this._capabilities;
327
+ }
328
+ }, {
329
+ key: "touchButton",
330
+ get: function get() {
331
+ return 0;
332
+ },
333
+ set: function set(button) {
334
+ Log.Warn("Using old API!");
335
+ }
336
+ }, {
337
+ key: "clipViewport",
338
+ get: function get() {
339
+ return this._clipViewport;
340
+ },
341
+ set: function set(viewport) {
342
+ this._clipViewport = viewport;
343
+ this._updateClip();
344
+ }
345
+ }, {
346
+ key: "scaleViewport",
347
+ get: function get() {
348
+ return this._scaleViewport;
349
+ },
350
+ set: function set(scale) {
351
+ this._scaleViewport = scale;
352
+ // Scaling trumps clipping, so we may need to adjust
353
+ // clipping when enabling or disabling scaling
354
+ if (scale && this._clipViewport) {
355
+ this._updateClip();
356
+ }
357
+ this._updateScale();
358
+ if (!scale && this._clipViewport) {
359
+ this._updateClip();
360
+ }
361
+ }
362
+ }, {
363
+ key: "resizeSession",
364
+ get: function get() {
365
+ return this._resizeSession;
366
+ },
367
+ set: function set(resize) {
368
+ this._resizeSession = resize;
369
+ if (resize) {
370
+ this._requestRemoteResize();
371
+ }
372
+ }
373
+ }, {
374
+ key: "showDotCursor",
375
+ get: function get() {
376
+ return this._showDotCursor;
377
+ },
378
+ set: function set(show) {
379
+ this._showDotCursor = show;
380
+ this._refreshCursor();
381
+ }
382
+ }, {
383
+ key: "background",
384
+ get: function get() {
385
+ return this._screen.style.background;
386
+ },
387
+ set: function set(cssValue) {
388
+ this._screen.style.background = cssValue;
389
+ }
390
+ }, {
391
+ key: "qualityLevel",
392
+ get: function get() {
393
+ return this._qualityLevel;
394
+ },
395
+ set: function set(qualityLevel) {
396
+ if (!Number.isInteger(qualityLevel) || qualityLevel < 0 || qualityLevel > 9) {
397
+ Log.Error("qualityLevel must be an integer between 0 and 9");
398
+ return;
399
+ }
400
+ if (this._qualityLevel === qualityLevel) {
401
+ return;
402
+ }
403
+ this._qualityLevel = qualityLevel;
404
+ if (this._rfbConnectionState === 'connected') {
405
+ this._sendEncodings();
406
+ }
407
+ }
408
+ }, {
409
+ key: "compressionLevel",
410
+ get: function get() {
411
+ return this._compressionLevel;
412
+ },
413
+ set: function set(compressionLevel) {
414
+ if (!Number.isInteger(compressionLevel) || compressionLevel < 0 || compressionLevel > 9) {
415
+ Log.Error("compressionLevel must be an integer between 0 and 9");
416
+ return;
417
+ }
418
+ if (this._compressionLevel === compressionLevel) {
419
+ return;
420
+ }
421
+ this._compressionLevel = compressionLevel;
422
+ if (this._rfbConnectionState === 'connected') {
423
+ this._sendEncodings();
424
+ }
425
+ }
426
+
367
427
  // ===== PUBLIC METHODS =====
428
+ }, {
429
+ key: "disconnect",
368
430
  value: function disconnect() {
369
431
  this._updateConnectionState('disconnecting');
370
-
371
432
  this._sock.off('error');
372
-
373
433
  this._sock.off('message');
374
-
375
434
  this._sock.off('open');
435
+ if (this._rfbRSAAESAuthenticationState !== null) {
436
+ this._rfbRSAAESAuthenticationState.disconnect();
437
+ }
438
+ }
439
+ }, {
440
+ key: "approveServer",
441
+ value: function approveServer() {
442
+ if (this._rfbRSAAESAuthenticationState !== null) {
443
+ this._rfbRSAAESAuthenticationState.approveServer();
444
+ }
376
445
  }
377
446
  }, {
378
447
  key: "sendCredentials",
379
448
  value: function sendCredentials(creds) {
380
449
  this._rfbCredentials = creds;
381
- setTimeout(this._initMsg.bind(this), 0);
450
+ this._resumeAuthentication();
382
451
  }
383
452
  }, {
384
453
  key: "sendCtrlAltDel",
@@ -386,14 +455,13 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
386
455
  if (this._rfbConnectionState !== 'connected' || this._viewOnly) {
387
456
  return;
388
457
  }
389
-
390
458
  Log.Info("Sending Ctrl-Alt-Del");
391
- this.sendKey(_keysym.default.XK_Control_L, "ControlLeft", true);
392
- this.sendKey(_keysym.default.XK_Alt_L, "AltLeft", true);
393
- this.sendKey(_keysym.default.XK_Delete, "Delete", true);
394
- this.sendKey(_keysym.default.XK_Delete, "Delete", false);
395
- this.sendKey(_keysym.default.XK_Alt_L, "AltLeft", false);
396
- this.sendKey(_keysym.default.XK_Control_L, "ControlLeft", false);
459
+ this.sendKey(_keysym["default"].XK_Control_L, "ControlLeft", true);
460
+ this.sendKey(_keysym["default"].XK_Alt_L, "AltLeft", true);
461
+ this.sendKey(_keysym["default"].XK_Delete, "Delete", true);
462
+ this.sendKey(_keysym["default"].XK_Delete, "Delete", false);
463
+ this.sendKey(_keysym["default"].XK_Alt_L, "AltLeft", false);
464
+ this.sendKey(_keysym["default"].XK_Control_L, "ControlLeft", false);
397
465
  }
398
466
  }, {
399
467
  key: "machineShutdown",
@@ -409,24 +477,22 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
409
477
  key: "machineReset",
410
478
  value: function machineReset() {
411
479
  this._xvpOp(1, 4);
412
- } // Send a key press. If 'down' is not specified then send a down key
413
- // followed by an up key.
480
+ }
414
481
 
482
+ // Send a key press. If 'down' is not specified then send a down key
483
+ // followed by an up key.
415
484
  }, {
416
485
  key: "sendKey",
417
486
  value: function sendKey(keysym, code, down) {
418
487
  if (this._rfbConnectionState !== 'connected' || this._viewOnly) {
419
488
  return;
420
489
  }
421
-
422
490
  if (down === undefined) {
423
491
  this.sendKey(keysym, code, true);
424
492
  this.sendKey(keysym, code, false);
425
493
  return;
426
494
  }
427
-
428
- var scancode = _xtscancodes.default[code];
429
-
495
+ var scancode = _xtscancodes["default"][code];
430
496
  if (this._qemuExtKeyEventSupported && scancode) {
431
497
  // 0 is NoSymbol
432
498
  keysym = keysym || 0;
@@ -436,15 +502,14 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
436
502
  if (!keysym) {
437
503
  return;
438
504
  }
439
-
440
505
  Log.Info("Sending keysym (" + (down ? "down" : "up") + "): " + keysym);
441
506
  RFB.messages.keyEvent(this._sock, keysym, down ? 1 : 0);
442
507
  }
443
508
  }
444
509
  }, {
445
510
  key: "focus",
446
- value: function focus() {
447
- this._canvas.focus();
511
+ value: function focus(options) {
512
+ this._canvas.focus(options);
448
513
  }
449
514
  }, {
450
515
  key: "blur",
@@ -457,141 +522,214 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
457
522
  if (this._rfbConnectionState !== 'connected' || this._viewOnly) {
458
523
  return;
459
524
  }
460
-
461
525
  if (this._clipboardServerCapabilitiesFormats[extendedClipboardFormatText] && this._clipboardServerCapabilitiesActions[extendedClipboardActionNotify]) {
462
526
  this._clipboardText = text;
463
527
  RFB.messages.extendedClipboardNotify(this._sock, [extendedClipboardFormatText]);
464
528
  } else {
465
- var data = new Uint8Array(text.length);
466
-
467
- for (var i = 0; i < text.length; i++) {
468
- // FIXME: text can have values outside of Latin1/Uint8
469
- data[i] = text.charCodeAt(i);
529
+ var length, i;
530
+ var data;
531
+ length = 0;
532
+ // eslint-disable-next-line no-unused-vars
533
+ var _iterator = _createForOfIteratorHelper(text),
534
+ _step;
535
+ try {
536
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
537
+ var codePoint = _step.value;
538
+ length++;
539
+ }
540
+ } catch (err) {
541
+ _iterator.e(err);
542
+ } finally {
543
+ _iterator.f();
470
544
  }
545
+ data = new Uint8Array(length);
546
+ i = 0;
547
+ var _iterator2 = _createForOfIteratorHelper(text),
548
+ _step2;
549
+ try {
550
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
551
+ var _codePoint = _step2.value;
552
+ var code = _codePoint.codePointAt(0);
553
+
554
+ /* Only ISO 8859-1 is supported */
555
+ if (code > 0xff) {
556
+ code = 0x3f; // '?'
557
+ }
471
558
 
559
+ data[i++] = code;
560
+ }
561
+ } catch (err) {
562
+ _iterator2.e(err);
563
+ } finally {
564
+ _iterator2.f();
565
+ }
472
566
  RFB.messages.clientCutText(this._sock, data);
473
567
  }
474
- } // ===== PRIVATE METHODS =====
568
+ }
569
+ }, {
570
+ key: "getImageData",
571
+ value: function getImageData() {
572
+ return this._display.getImageData();
573
+ }
574
+ }, {
575
+ key: "toDataURL",
576
+ value: function toDataURL(type, encoderOptions) {
577
+ return this._display.toDataURL(type, encoderOptions);
578
+ }
579
+ }, {
580
+ key: "toBlob",
581
+ value: function toBlob(callback, type, quality) {
582
+ return this._display.toBlob(callback, type, quality);
583
+ }
475
584
 
585
+ // ===== PRIVATE METHODS =====
476
586
  }, {
477
587
  key: "_connect",
478
588
  value: function _connect() {
479
589
  Log.Debug(">> RFB.connect");
480
- Log.Info("connecting to " + this._url);
481
-
482
- try {
483
- // WebSocket.onopen transitions to the RFB init states
590
+ if (this._url) {
591
+ Log.Info("connecting to ".concat(this._url));
484
592
  this._sock.open(this._url, this._wsProtocols);
485
- } catch (e) {
486
- if (e.name === 'SyntaxError') {
487
- this._fail("Invalid host or port (" + e + ")");
488
- } else {
489
- this._fail("Error when opening socket (" + e + ")");
593
+ } else {
594
+ Log.Info("attaching ".concat(this._rawChannel, " to Websock"));
595
+ this._sock.attach(this._rawChannel);
596
+ if (this._sock.readyState === 'closed') {
597
+ throw Error("Cannot use already closed WebSocket/RTCDataChannel");
490
598
  }
491
- } // Make our elements part of the page
492
-
599
+ if (this._sock.readyState === 'open') {
600
+ // FIXME: _socketOpen() can in theory call _fail(), which
601
+ // isn't allowed this early, but I'm not sure that can
602
+ // happen without a bug messing up our state variables
603
+ this._socketOpen();
604
+ }
605
+ }
493
606
 
607
+ // Make our elements part of the page
494
608
  this._target.appendChild(this._screen);
495
-
496
609
  this._gestures.attach(this._canvas);
497
-
498
610
  this._cursor.attach(this._canvas);
611
+ this._refreshCursor();
499
612
 
500
- this._refreshCursor(); // Monitor size changes of the screen
501
- // FIXME: Use ResizeObserver, or hidden overflow
502
-
503
-
504
- window.addEventListener('resize', this._eventHandlers.windowResize); // Always grab focus on some kind of click event
613
+ // Monitor size changes of the screen element
614
+ this._resizeObserver.observe(this._screen);
505
615
 
616
+ // Always grab focus on some kind of click event
506
617
  this._canvas.addEventListener("mousedown", this._eventHandlers.focusCanvas);
618
+ this._canvas.addEventListener("touchstart", this._eventHandlers.focusCanvas);
507
619
 
508
- this._canvas.addEventListener("touchstart", this._eventHandlers.focusCanvas); // Mouse events
509
-
510
-
620
+ // Mouse events
511
621
  this._canvas.addEventListener('mousedown', this._eventHandlers.handleMouse);
512
-
513
622
  this._canvas.addEventListener('mouseup', this._eventHandlers.handleMouse);
514
-
515
- this._canvas.addEventListener('mousemove', this._eventHandlers.handleMouse); // Prevent middle-click pasting (see handler for why we bind to document)
516
-
517
-
518
- this._canvas.addEventListener('click', this._eventHandlers.handleMouse); // preventDefault() on mousedown doesn't stop this event for some
623
+ this._canvas.addEventListener('mousemove', this._eventHandlers.handleMouse);
624
+ // Prevent middle-click pasting (see handler for why we bind to document)
625
+ this._canvas.addEventListener('click', this._eventHandlers.handleMouse);
626
+ // preventDefault() on mousedown doesn't stop this event for some
519
627
  // reason so we have to explicitly block it
628
+ this._canvas.addEventListener('contextmenu', this._eventHandlers.handleMouse);
520
629
 
630
+ // Wheel events
631
+ this._canvas.addEventListener("wheel", this._eventHandlers.handleWheel);
521
632
 
522
- this._canvas.addEventListener('contextmenu', this._eventHandlers.handleMouse); // Wheel events
523
-
524
-
525
- this._canvas.addEventListener("wheel", this._eventHandlers.handleWheel); // Gesture events
526
-
527
-
633
+ // Gesture events
528
634
  this._canvas.addEventListener("gesturestart", this._eventHandlers.handleGesture);
529
-
530
635
  this._canvas.addEventListener("gesturemove", this._eventHandlers.handleGesture);
531
-
532
636
  this._canvas.addEventListener("gestureend", this._eventHandlers.handleGesture);
533
-
534
637
  Log.Debug("<< RFB.connect");
535
638
  }
536
639
  }, {
537
640
  key: "_disconnect",
538
641
  value: function _disconnect() {
539
642
  Log.Debug(">> RFB.disconnect");
540
-
541
643
  this._cursor.detach();
542
-
543
644
  this._canvas.removeEventListener("gesturestart", this._eventHandlers.handleGesture);
544
-
545
645
  this._canvas.removeEventListener("gesturemove", this._eventHandlers.handleGesture);
546
-
547
646
  this._canvas.removeEventListener("gestureend", this._eventHandlers.handleGesture);
548
-
549
647
  this._canvas.removeEventListener("wheel", this._eventHandlers.handleWheel);
550
-
551
648
  this._canvas.removeEventListener('mousedown', this._eventHandlers.handleMouse);
552
-
553
649
  this._canvas.removeEventListener('mouseup', this._eventHandlers.handleMouse);
554
-
555
650
  this._canvas.removeEventListener('mousemove', this._eventHandlers.handleMouse);
556
-
557
651
  this._canvas.removeEventListener('click', this._eventHandlers.handleMouse);
558
-
559
652
  this._canvas.removeEventListener('contextmenu', this._eventHandlers.handleMouse);
560
-
561
653
  this._canvas.removeEventListener("mousedown", this._eventHandlers.focusCanvas);
562
-
563
654
  this._canvas.removeEventListener("touchstart", this._eventHandlers.focusCanvas);
564
-
565
- window.removeEventListener('resize', this._eventHandlers.windowResize);
566
-
655
+ this._resizeObserver.disconnect();
567
656
  this._keyboard.ungrab();
568
-
569
657
  this._gestures.detach();
570
-
571
658
  this._sock.close();
572
-
573
659
  try {
574
660
  this._target.removeChild(this._screen);
575
661
  } catch (e) {
576
- if (e.name === 'NotFoundError') {// Some cases where the initial connection fails
662
+ if (e.name === 'NotFoundError') {
663
+ // Some cases where the initial connection fails
577
664
  // can disconnect before the _screen is created
578
665
  } else {
579
666
  throw e;
580
667
  }
581
668
  }
582
-
583
669
  clearTimeout(this._resizeTimeout);
584
670
  clearTimeout(this._mouseMoveTimer);
585
671
  Log.Debug("<< RFB.disconnect");
586
672
  }
673
+ }, {
674
+ key: "_socketOpen",
675
+ value: function _socketOpen() {
676
+ if (this._rfbConnectionState === 'connecting' && this._rfbInitState === '') {
677
+ this._rfbInitState = 'ProtocolVersion';
678
+ Log.Debug("Starting VNC handshake");
679
+ } else {
680
+ this._fail("Unexpected server connection while " + this._rfbConnectionState);
681
+ }
682
+ }
683
+ }, {
684
+ key: "_socketClose",
685
+ value: function _socketClose(e) {
686
+ Log.Debug("WebSocket on-close event");
687
+ var msg = "";
688
+ if (e.code) {
689
+ msg = "(code: " + e.code;
690
+ if (e.reason) {
691
+ msg += ", reason: " + e.reason;
692
+ }
693
+ msg += ")";
694
+ }
695
+ switch (this._rfbConnectionState) {
696
+ case 'connecting':
697
+ this._fail("Connection closed " + msg);
698
+ break;
699
+ case 'connected':
700
+ // Handle disconnects that were initiated server-side
701
+ this._updateConnectionState('disconnecting');
702
+ this._updateConnectionState('disconnected');
703
+ break;
704
+ case 'disconnecting':
705
+ // Normal disconnection path
706
+ this._updateConnectionState('disconnected');
707
+ break;
708
+ case 'disconnected':
709
+ this._fail("Unexpected server disconnect " + "when already disconnected " + msg);
710
+ break;
711
+ default:
712
+ this._fail("Unexpected server disconnect before connecting " + msg);
713
+ break;
714
+ }
715
+ this._sock.off('close');
716
+ // Delete reference to raw channel to allow cleanup.
717
+ this._rawChannel = null;
718
+ }
719
+ }, {
720
+ key: "_socketError",
721
+ value: function _socketError(e) {
722
+ Log.Warn("WebSocket on-error event");
723
+ }
587
724
  }, {
588
725
  key: "_focusCanvas",
589
726
  value: function _focusCanvas(event) {
590
727
  if (!this.focusOnClick) {
591
728
  return;
592
729
  }
593
-
594
- this.focus();
730
+ this.focus({
731
+ preventScroll: true
732
+ });
595
733
  }
596
734
  }, {
597
735
  key: "_setDesktopName",
@@ -604,53 +742,77 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
604
742
  }));
605
743
  }
606
744
  }, {
607
- key: "_windowResize",
608
- value: function _windowResize(event) {
745
+ key: "_saveExpectedClientSize",
746
+ value: function _saveExpectedClientSize() {
747
+ this._expectedClientWidth = this._screen.clientWidth;
748
+ this._expectedClientHeight = this._screen.clientHeight;
749
+ }
750
+ }, {
751
+ key: "_currentClientSize",
752
+ value: function _currentClientSize() {
753
+ return [this._screen.clientWidth, this._screen.clientHeight];
754
+ }
755
+ }, {
756
+ key: "_clientHasExpectedSize",
757
+ value: function _clientHasExpectedSize() {
758
+ var _this$_currentClientS = this._currentClientSize(),
759
+ _this$_currentClientS2 = _slicedToArray(_this$_currentClientS, 2),
760
+ currentWidth = _this$_currentClientS2[0],
761
+ currentHeight = _this$_currentClientS2[1];
762
+ return currentWidth == this._expectedClientWidth && currentHeight == this._expectedClientHeight;
763
+ }
764
+ }, {
765
+ key: "_handleResize",
766
+ value: function _handleResize() {
609
767
  var _this2 = this;
610
-
768
+ // Don't change anything if the client size is already as expected
769
+ if (this._clientHasExpectedSize()) {
770
+ return;
771
+ }
611
772
  // If the window resized then our screen element might have
612
773
  // as well. Update the viewport dimensions.
613
774
  window.requestAnimationFrame(function () {
614
775
  _this2._updateClip();
615
-
616
776
  _this2._updateScale();
617
777
  });
618
-
619
778
  if (this._resizeSession) {
620
779
  // Request changing the resolution of the remote display to
621
780
  // the size of the local browser viewport.
781
+
622
782
  // In order to not send multiple requests before the browser-resize
623
783
  // is finished we wait 0.5 seconds before sending the request.
624
784
  clearTimeout(this._resizeTimeout);
625
785
  this._resizeTimeout = setTimeout(this._requestRemoteResize.bind(this), 500);
626
786
  }
627
- } // Update state of clipping in Display object, and make sure the
628
- // configured viewport matches the current screen size
787
+ }
629
788
 
789
+ // Update state of clipping in Display object, and make sure the
790
+ // configured viewport matches the current screen size
630
791
  }, {
631
792
  key: "_updateClip",
632
793
  value: function _updateClip() {
633
794
  var curClip = this._display.clipViewport;
634
795
  var newClip = this._clipViewport;
635
-
636
796
  if (this._scaleViewport) {
637
797
  // Disable viewport clipping if we are scaling
638
798
  newClip = false;
639
799
  }
640
-
641
800
  if (curClip !== newClip) {
642
801
  this._display.clipViewport = newClip;
643
802
  }
644
-
645
803
  if (newClip) {
646
804
  // When clipping is enabled, the screen is limited to
647
805
  // the size of the container.
648
806
  var size = this._screenSize();
649
-
650
807
  this._display.viewportChangeSize(size.w, size.h);
651
-
652
808
  this._fixScrollbars();
653
809
  }
810
+
811
+ // When changing clipping we might show or hide scrollbars.
812
+ // This causes the expected client dimensions to change.
813
+ if (curClip !== newClip) {
814
+ this._saveExpectedClientSize();
815
+ }
654
816
  }
655
817
  }, {
656
818
  key: "_updateScale",
@@ -659,35 +821,31 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
659
821
  this._display.scale = 1.0;
660
822
  } else {
661
823
  var size = this._screenSize();
662
-
663
824
  this._display.autoscale(size.w, size.h);
664
825
  }
665
-
666
826
  this._fixScrollbars();
667
- } // Requests a change of remote desktop size. This message is an extension
668
- // and may only be sent if we have received an ExtendedDesktopSize message
827
+ }
669
828
 
829
+ // Requests a change of remote desktop size. This message is an extension
830
+ // and may only be sent if we have received an ExtendedDesktopSize message
670
831
  }, {
671
832
  key: "_requestRemoteResize",
672
833
  value: function _requestRemoteResize() {
673
834
  clearTimeout(this._resizeTimeout);
674
835
  this._resizeTimeout = null;
675
-
676
836
  if (!this._resizeSession || this._viewOnly || !this._supportsSetDesktopSize) {
677
837
  return;
678
838
  }
679
-
680
839
  var size = this._screenSize();
681
-
682
840
  RFB.messages.setDesktopSize(this._sock, Math.floor(size.w), Math.floor(size.h), this._screenID, this._screenFlags);
683
841
  Log.Debug('Requested new desktop size: ' + size.w + 'x' + size.h);
684
- } // Gets the the size of the available screen
842
+ }
685
843
 
844
+ // Gets the the size of the available screen
686
845
  }, {
687
846
  key: "_screenSize",
688
847
  value: function _screenSize() {
689
848
  var r = this._screen.getBoundingClientRect();
690
-
691
849
  return {
692
850
  w: r.width,
693
851
  h: r.height
@@ -696,17 +854,18 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
696
854
  }, {
697
855
  key: "_fixScrollbars",
698
856
  value: function _fixScrollbars() {
699
- // This is a hack because Chrome screws up the calculation
700
- // for when scrollbars are needed. So to fix it we temporarily
701
- // toggle them off and on.
857
+ // This is a hack because Safari on macOS screws up the calculation
858
+ // for when scrollbars are needed. We get scrollbars when making the
859
+ // browser smaller, despite remote resize being enabled. So to fix it
860
+ // we temporarily toggle them off and on.
702
861
  var orig = this._screen.style.overflow;
703
- this._screen.style.overflow = 'hidden'; // Force Chrome to recalculate the layout by asking for
862
+ this._screen.style.overflow = 'hidden';
863
+ // Force Safari to recalculate the layout by asking for
704
864
  // an element's dimensions
705
-
706
865
  this._screen.getBoundingClientRect();
707
-
708
866
  this._screen.style.overflow = orig;
709
867
  }
868
+
710
869
  /*
711
870
  * Connection states:
712
871
  * connecting
@@ -714,98 +873,81 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
714
873
  * disconnecting
715
874
  * disconnected - permanent state
716
875
  */
717
-
718
876
  }, {
719
877
  key: "_updateConnectionState",
720
878
  value: function _updateConnectionState(state) {
721
879
  var _this3 = this;
722
-
723
880
  var oldstate = this._rfbConnectionState;
724
-
725
881
  if (state === oldstate) {
726
882
  Log.Debug("Already in state '" + state + "', ignoring");
727
883
  return;
728
- } // The 'disconnected' state is permanent for each RFB object
729
-
884
+ }
730
885
 
886
+ // The 'disconnected' state is permanent for each RFB object
731
887
  if (oldstate === 'disconnected') {
732
888
  Log.Error("Tried changing state of a disconnected RFB object");
733
889
  return;
734
- } // Ensure proper transitions before doing anything
735
-
890
+ }
736
891
 
892
+ // Ensure proper transitions before doing anything
737
893
  switch (state) {
738
894
  case 'connected':
739
895
  if (oldstate !== 'connecting') {
740
896
  Log.Error("Bad transition to connected state, " + "previous connection state: " + oldstate);
741
897
  return;
742
898
  }
743
-
744
899
  break;
745
-
746
900
  case 'disconnected':
747
901
  if (oldstate !== 'disconnecting') {
748
902
  Log.Error("Bad transition to disconnected state, " + "previous connection state: " + oldstate);
749
903
  return;
750
904
  }
751
-
752
905
  break;
753
-
754
906
  case 'connecting':
755
907
  if (oldstate !== '') {
756
908
  Log.Error("Bad transition to connecting state, " + "previous connection state: " + oldstate);
757
909
  return;
758
910
  }
759
-
760
911
  break;
761
-
762
912
  case 'disconnecting':
763
913
  if (oldstate !== 'connected' && oldstate !== 'connecting') {
764
914
  Log.Error("Bad transition to disconnecting state, " + "previous connection state: " + oldstate);
765
915
  return;
766
916
  }
767
-
768
917
  break;
769
-
770
918
  default:
771
919
  Log.Error("Unknown connection state: " + state);
772
920
  return;
773
- } // State change actions
921
+ }
774
922
 
923
+ // State change actions
775
924
 
776
925
  this._rfbConnectionState = state;
777
926
  Log.Debug("New state '" + state + "', was '" + oldstate + "'.");
778
-
779
927
  if (this._disconnTimer && state !== 'disconnecting') {
780
928
  Log.Debug("Clearing disconnect timer");
781
929
  clearTimeout(this._disconnTimer);
782
- this._disconnTimer = null; // make sure we don't get a double event
930
+ this._disconnTimer = null;
783
931
 
932
+ // make sure we don't get a double event
784
933
  this._sock.off('close');
785
934
  }
786
-
787
935
  switch (state) {
788
936
  case 'connecting':
789
937
  this._connect();
790
-
791
938
  break;
792
-
793
939
  case 'connected':
794
940
  this.dispatchEvent(new CustomEvent("connect", {
795
941
  detail: {}
796
942
  }));
797
943
  break;
798
-
799
944
  case 'disconnecting':
800
945
  this._disconnect();
801
-
802
946
  this._disconnTimer = setTimeout(function () {
803
947
  Log.Error("Disconnection timed out.");
804
-
805
948
  _this3._updateConnectionState('disconnected');
806
949
  }, DISCONNECT_TIMEOUT * 1000);
807
950
  break;
808
-
809
951
  case 'disconnected':
810
952
  this.dispatchEvent(new CustomEvent("disconnect", {
811
953
  detail: {
@@ -815,12 +957,12 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
815
957
  break;
816
958
  }
817
959
  }
960
+
818
961
  /* Print errors and disconnect
819
962
  *
820
963
  * The parameter 'details' is used for information that
821
964
  * should be logged but not sent to the user interface.
822
965
  */
823
-
824
966
  }, {
825
967
  key: "_fail",
826
968
  value: function _fail(details) {
@@ -828,27 +970,21 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
828
970
  case 'disconnecting':
829
971
  Log.Error("Failed when disconnecting: " + details);
830
972
  break;
831
-
832
973
  case 'connected':
833
974
  Log.Error("Failed while connected: " + details);
834
975
  break;
835
-
836
976
  case 'connecting':
837
977
  Log.Error("Failed when connecting: " + details);
838
978
  break;
839
-
840
979
  default:
841
980
  Log.Error("RFB failure: " + details);
842
981
  break;
843
982
  }
844
-
845
983
  this._rfbCleanDisconnect = false; //This is sent to the UI
846
- // Transition to disconnected without waiting for socket to close
847
984
 
985
+ // Transition to disconnected without waiting for socket to close
848
986
  this._updateConnectionState('disconnecting');
849
-
850
987
  this._updateConnectionState('disconnected');
851
-
852
988
  return false;
853
989
  }
854
990
  }, {
@@ -868,32 +1004,32 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
868
1004
  Log.Warn("handleMessage called on an empty receive queue");
869
1005
  return;
870
1006
  }
871
-
872
1007
  switch (this._rfbConnectionState) {
873
1008
  case 'disconnected':
874
1009
  Log.Error("Got data while disconnected");
875
1010
  break;
876
-
877
1011
  case 'connected':
878
1012
  while (true) {
879
1013
  if (this._flushing) {
880
1014
  break;
881
1015
  }
882
-
883
1016
  if (!this._normalMsg()) {
884
1017
  break;
885
1018
  }
886
-
887
1019
  if (this._sock.rQlen === 0) {
888
1020
  break;
889
1021
  }
890
1022
  }
891
-
892
1023
  break;
893
-
1024
+ case 'connecting':
1025
+ while (this._rfbConnectionState === 'connecting') {
1026
+ if (!this._initMsg()) {
1027
+ break;
1028
+ }
1029
+ }
1030
+ break;
894
1031
  default:
895
- this._initMsg();
896
-
1032
+ Log.Error("Got data while in an invalid state");
897
1033
  break;
898
1034
  }
899
1035
  }
@@ -909,6 +1045,7 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
909
1045
  * We don't check connection status or viewOnly here as the
910
1046
  * mouse events might be used to control the viewport
911
1047
  */
1048
+
912
1049
  if (ev.type === 'click') {
913
1050
  /*
914
1051
  * Note: This is only needed for the 'click' event as it fails
@@ -918,35 +1055,26 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
918
1055
  if (ev.target !== this._canvas) {
919
1056
  return;
920
1057
  }
921
- } // FIXME: if we're in view-only and not dragging,
922
- // should we stop events?
923
-
1058
+ }
924
1059
 
1060
+ // FIXME: if we're in view-only and not dragging,
1061
+ // should we stop events?
925
1062
  ev.stopPropagation();
926
1063
  ev.preventDefault();
927
-
928
1064
  if (ev.type === 'click' || ev.type === 'contextmenu') {
929
1065
  return;
930
1066
  }
931
-
932
1067
  var pos = (0, _element.clientToElement)(ev.clientX, ev.clientY, this._canvas);
933
-
934
1068
  switch (ev.type) {
935
1069
  case 'mousedown':
936
1070
  (0, _events.setCapture)(this._canvas);
937
-
938
1071
  this._handleMouseButton(pos.x, pos.y, true, 1 << ev.button);
939
-
940
1072
  break;
941
-
942
1073
  case 'mouseup':
943
1074
  this._handleMouseButton(pos.x, pos.y, false, 1 << ev.button);
944
-
945
1075
  break;
946
-
947
1076
  case 'mousemove':
948
1077
  this._handleMouseMove(pos.x, pos.y);
949
-
950
1078
  break;
951
1079
  }
952
1080
  }
@@ -960,74 +1088,68 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
960
1088
  'x': x,
961
1089
  'y': y
962
1090
  };
963
- this._viewportHasMoved = false; // Skip sending mouse events
1091
+ this._viewportHasMoved = false;
964
1092
 
1093
+ // Skip sending mouse events
965
1094
  return;
966
1095
  } else {
967
- this._viewportDragging = false; // If we actually performed a drag then we are done
968
- // here and should not send any mouse events
1096
+ this._viewportDragging = false;
969
1097
 
1098
+ // If we actually performed a drag then we are done
1099
+ // here and should not send any mouse events
970
1100
  if (this._viewportHasMoved) {
971
1101
  return;
972
- } // Otherwise we treat this as a mouse click event.
1102
+ }
1103
+
1104
+ // Otherwise we treat this as a mouse click event.
973
1105
  // Send the button down event here, as the button up
974
1106
  // event is sent at the end of this function.
975
-
976
-
977
1107
  this._sendMouse(x, y, bmask);
978
1108
  }
979
- } // Flush waiting move event first
980
-
1109
+ }
981
1110
 
1111
+ // Flush waiting move event first
982
1112
  if (this._mouseMoveTimer !== null) {
983
1113
  clearTimeout(this._mouseMoveTimer);
984
1114
  this._mouseMoveTimer = null;
985
-
986
1115
  this._sendMouse(x, y, this._mouseButtonMask);
987
1116
  }
988
-
989
1117
  if (down) {
990
1118
  this._mouseButtonMask |= bmask;
991
1119
  } else {
992
1120
  this._mouseButtonMask &= ~bmask;
993
1121
  }
994
-
995
1122
  this._sendMouse(x, y, this._mouseButtonMask);
996
1123
  }
997
1124
  }, {
998
1125
  key: "_handleMouseMove",
999
1126
  value: function _handleMouseMove(x, y) {
1000
1127
  var _this4 = this;
1001
-
1002
1128
  if (this._viewportDragging) {
1003
1129
  var deltaX = this._viewportDragPos.x - x;
1004
1130
  var deltaY = this._viewportDragPos.y - y;
1005
-
1006
1131
  if (this._viewportHasMoved || Math.abs(deltaX) > _browser.dragThreshold || Math.abs(deltaY) > _browser.dragThreshold) {
1007
1132
  this._viewportHasMoved = true;
1008
1133
  this._viewportDragPos = {
1009
1134
  'x': x,
1010
1135
  'y': y
1011
1136
  };
1012
-
1013
1137
  this._display.viewportChangePos(deltaX, deltaY);
1014
- } // Skip sending mouse events
1015
-
1138
+ }
1016
1139
 
1140
+ // Skip sending mouse events
1017
1141
  return;
1018
1142
  }
1019
-
1020
1143
  this._mousePos = {
1021
1144
  'x': x,
1022
1145
  'y': y
1023
- }; // Limit many mouse move events to one every MOUSE_MOVE_DELAY ms
1146
+ };
1024
1147
 
1148
+ // Limit many mouse move events to one every MOUSE_MOVE_DELAY ms
1025
1149
  if (this._mouseMoveTimer == null) {
1026
1150
  var timeSinceLastMove = Date.now() - this._mouseLastMoveTime;
1027
-
1028
1151
  if (timeSinceLastMove > MOUSE_MOVE_DELAY) {
1029
1152
  this._sendMouse(x, y, this._mouseButtonMask);
1030
-
1031
1153
  this._mouseLastMoveTime = Date.now();
1032
1154
  } else {
1033
1155
  // Too soon since the latest move, wait the remaining time
@@ -1041,9 +1163,7 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1041
1163
  key: "_handleDelayedMouseMove",
1042
1164
  value: function _handleDelayedMouseMove() {
1043
1165
  this._mouseMoveTimer = null;
1044
-
1045
1166
  this._sendMouse(this._mousePos.x, this._mousePos.y, this._mouseButtonMask);
1046
-
1047
1167
  this._mouseLastMoveTime = Date.now();
1048
1168
  }
1049
1169
  }, {
@@ -1052,12 +1172,10 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1052
1172
  if (this._rfbConnectionState !== 'connected') {
1053
1173
  return;
1054
1174
  }
1055
-
1056
1175
  if (this._viewOnly) {
1057
1176
  return;
1058
1177
  } // View only, skip mouse events
1059
1178
 
1060
-
1061
1179
  RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), mask);
1062
1180
  }
1063
1181
  }, {
@@ -1066,59 +1184,52 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1066
1184
  if (this._rfbConnectionState !== 'connected') {
1067
1185
  return;
1068
1186
  }
1069
-
1070
1187
  if (this._viewOnly) {
1071
1188
  return;
1072
1189
  } // View only, skip mouse events
1073
1190
 
1074
-
1075
1191
  ev.stopPropagation();
1076
1192
  ev.preventDefault();
1077
1193
  var pos = (0, _element.clientToElement)(ev.clientX, ev.clientY, this._canvas);
1078
1194
  var dX = ev.deltaX;
1079
- var dY = ev.deltaY; // Pixel units unless it's non-zero.
1195
+ var dY = ev.deltaY;
1196
+
1197
+ // Pixel units unless it's non-zero.
1080
1198
  // Note that if deltamode is line or page won't matter since we aren't
1081
1199
  // sending the mouse wheel delta to the server anyway.
1082
1200
  // The difference between pixel and line can be important however since
1083
1201
  // we have a threshold that can be smaller than the line height.
1084
-
1085
1202
  if (ev.deltaMode !== 0) {
1086
1203
  dX *= WHEEL_LINE_HEIGHT;
1087
1204
  dY *= WHEEL_LINE_HEIGHT;
1088
- } // Mouse wheel events are sent in steps over VNC. This means that the VNC
1205
+ }
1206
+
1207
+ // Mouse wheel events are sent in steps over VNC. This means that the VNC
1089
1208
  // protocol can't handle a wheel event with specific distance or speed.
1090
1209
  // Therefor, if we get a lot of small mouse wheel events we combine them.
1091
-
1092
-
1093
1210
  this._accumulatedWheelDeltaX += dX;
1094
- this._accumulatedWheelDeltaY += dY; // Generate a mouse wheel step event when the accumulated delta
1095
- // for one of the axes is large enough.
1211
+ this._accumulatedWheelDeltaY += dY;
1096
1212
 
1213
+ // Generate a mouse wheel step event when the accumulated delta
1214
+ // for one of the axes is large enough.
1097
1215
  if (Math.abs(this._accumulatedWheelDeltaX) >= WHEEL_STEP) {
1098
1216
  if (this._accumulatedWheelDeltaX < 0) {
1099
1217
  this._handleMouseButton(pos.x, pos.y, true, 1 << 5);
1100
-
1101
1218
  this._handleMouseButton(pos.x, pos.y, false, 1 << 5);
1102
1219
  } else if (this._accumulatedWheelDeltaX > 0) {
1103
1220
  this._handleMouseButton(pos.x, pos.y, true, 1 << 6);
1104
-
1105
1221
  this._handleMouseButton(pos.x, pos.y, false, 1 << 6);
1106
1222
  }
1107
-
1108
1223
  this._accumulatedWheelDeltaX = 0;
1109
1224
  }
1110
-
1111
1225
  if (Math.abs(this._accumulatedWheelDeltaY) >= WHEEL_STEP) {
1112
1226
  if (this._accumulatedWheelDeltaY < 0) {
1113
1227
  this._handleMouseButton(pos.x, pos.y, true, 1 << 3);
1114
-
1115
1228
  this._handleMouseButton(pos.x, pos.y, false, 1 << 3);
1116
1229
  } else if (this._accumulatedWheelDeltaY > 0) {
1117
1230
  this._handleMouseButton(pos.x, pos.y, true, 1 << 4);
1118
-
1119
1231
  this._handleMouseButton(pos.x, pos.y, false, 1 << 4);
1120
1232
  }
1121
-
1122
1233
  this._accumulatedWheelDeltaY = 0;
1123
1234
  }
1124
1235
  }
@@ -1126,20 +1237,20 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1126
1237
  key: "_fakeMouseMove",
1127
1238
  value: function _fakeMouseMove(ev, elementX, elementY) {
1128
1239
  this._handleMouseMove(elementX, elementY);
1129
-
1130
1240
  this._cursor.move(ev.detail.clientX, ev.detail.clientY);
1131
1241
  }
1132
1242
  }, {
1133
1243
  key: "_handleTapEvent",
1134
1244
  value: function _handleTapEvent(ev, bmask) {
1135
- var pos = (0, _element.clientToElement)(ev.detail.clientX, ev.detail.clientY, this._canvas); // If the user quickly taps multiple times we assume they meant to
1245
+ var pos = (0, _element.clientToElement)(ev.detail.clientX, ev.detail.clientY, this._canvas);
1246
+
1247
+ // If the user quickly taps multiple times we assume they meant to
1136
1248
  // hit the same spot, so slightly adjust coordinates
1137
1249
 
1138
1250
  if (this._gestureLastTapTime !== null && Date.now() - this._gestureLastTapTime < DOUBLE_TAP_TIMEOUT && this._gestureFirstDoubleTapEv.detail.type === ev.detail.type) {
1139
1251
  var dx = this._gestureFirstDoubleTapEv.detail.clientX - ev.detail.clientX;
1140
1252
  var dy = this._gestureFirstDoubleTapEv.detail.clientY - ev.detail.clientY;
1141
1253
  var distance = Math.hypot(dx, dy);
1142
-
1143
1254
  if (distance < DOUBLE_TAP_THRESHOLD) {
1144
1255
  pos = (0, _element.clientToElement)(this._gestureFirstDoubleTapEv.detail.clientX, this._gestureFirstDoubleTapEv.detail.clientY, this._canvas);
1145
1256
  } else {
@@ -1148,13 +1259,9 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1148
1259
  } else {
1149
1260
  this._gestureFirstDoubleTapEv = ev;
1150
1261
  }
1151
-
1152
1262
  this._gestureLastTapTime = Date.now();
1153
-
1154
1263
  this._fakeMouseMove(this._gestureFirstDoubleTapEv, pos.x, pos.y);
1155
-
1156
1264
  this._handleMouseButton(pos.x, pos.y, true, bmask);
1157
-
1158
1265
  this._handleMouseButton(pos.x, pos.y, false, bmask);
1159
1266
  }
1160
1267
  }, {
@@ -1162,145 +1269,96 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1162
1269
  value: function _handleGesture(ev) {
1163
1270
  var magnitude;
1164
1271
  var pos = (0, _element.clientToElement)(ev.detail.clientX, ev.detail.clientY, this._canvas);
1165
-
1166
1272
  switch (ev.type) {
1167
1273
  case 'gesturestart':
1168
1274
  switch (ev.detail.type) {
1169
1275
  case 'onetap':
1170
1276
  this._handleTapEvent(ev, 0x1);
1171
-
1172
1277
  break;
1173
-
1174
1278
  case 'twotap':
1175
1279
  this._handleTapEvent(ev, 0x4);
1176
-
1177
1280
  break;
1178
-
1179
1281
  case 'threetap':
1180
1282
  this._handleTapEvent(ev, 0x2);
1181
-
1182
1283
  break;
1183
-
1184
1284
  case 'drag':
1185
1285
  this._fakeMouseMove(ev, pos.x, pos.y);
1186
-
1187
1286
  this._handleMouseButton(pos.x, pos.y, true, 0x1);
1188
-
1189
1287
  break;
1190
-
1191
1288
  case 'longpress':
1192
1289
  this._fakeMouseMove(ev, pos.x, pos.y);
1193
-
1194
1290
  this._handleMouseButton(pos.x, pos.y, true, 0x4);
1195
-
1196
1291
  break;
1197
-
1198
1292
  case 'twodrag':
1199
1293
  this._gestureLastMagnitudeX = ev.detail.magnitudeX;
1200
1294
  this._gestureLastMagnitudeY = ev.detail.magnitudeY;
1201
-
1202
1295
  this._fakeMouseMove(ev, pos.x, pos.y);
1203
-
1204
1296
  break;
1205
-
1206
1297
  case 'pinch':
1207
1298
  this._gestureLastMagnitudeX = Math.hypot(ev.detail.magnitudeX, ev.detail.magnitudeY);
1208
-
1209
1299
  this._fakeMouseMove(ev, pos.x, pos.y);
1210
-
1211
1300
  break;
1212
1301
  }
1213
-
1214
1302
  break;
1215
-
1216
1303
  case 'gesturemove':
1217
1304
  switch (ev.detail.type) {
1218
1305
  case 'onetap':
1219
1306
  case 'twotap':
1220
1307
  case 'threetap':
1221
1308
  break;
1222
-
1223
1309
  case 'drag':
1224
1310
  case 'longpress':
1225
1311
  this._fakeMouseMove(ev, pos.x, pos.y);
1226
-
1227
1312
  break;
1228
-
1229
1313
  case 'twodrag':
1230
1314
  // Always scroll in the same position.
1231
1315
  // We don't know if the mouse was moved so we need to move it
1232
1316
  // every update.
1233
1317
  this._fakeMouseMove(ev, pos.x, pos.y);
1234
-
1235
1318
  while (ev.detail.magnitudeY - this._gestureLastMagnitudeY > GESTURE_SCRLSENS) {
1236
1319
  this._handleMouseButton(pos.x, pos.y, true, 0x8);
1237
-
1238
1320
  this._handleMouseButton(pos.x, pos.y, false, 0x8);
1239
-
1240
1321
  this._gestureLastMagnitudeY += GESTURE_SCRLSENS;
1241
1322
  }
1242
-
1243
1323
  while (ev.detail.magnitudeY - this._gestureLastMagnitudeY < -GESTURE_SCRLSENS) {
1244
1324
  this._handleMouseButton(pos.x, pos.y, true, 0x10);
1245
-
1246
1325
  this._handleMouseButton(pos.x, pos.y, false, 0x10);
1247
-
1248
1326
  this._gestureLastMagnitudeY -= GESTURE_SCRLSENS;
1249
1327
  }
1250
-
1251
1328
  while (ev.detail.magnitudeX - this._gestureLastMagnitudeX > GESTURE_SCRLSENS) {
1252
1329
  this._handleMouseButton(pos.x, pos.y, true, 0x20);
1253
-
1254
1330
  this._handleMouseButton(pos.x, pos.y, false, 0x20);
1255
-
1256
1331
  this._gestureLastMagnitudeX += GESTURE_SCRLSENS;
1257
1332
  }
1258
-
1259
1333
  while (ev.detail.magnitudeX - this._gestureLastMagnitudeX < -GESTURE_SCRLSENS) {
1260
1334
  this._handleMouseButton(pos.x, pos.y, true, 0x40);
1261
-
1262
1335
  this._handleMouseButton(pos.x, pos.y, false, 0x40);
1263
-
1264
1336
  this._gestureLastMagnitudeX -= GESTURE_SCRLSENS;
1265
1337
  }
1266
-
1267
1338
  break;
1268
-
1269
1339
  case 'pinch':
1270
1340
  // Always scroll in the same position.
1271
1341
  // We don't know if the mouse was moved so we need to move it
1272
1342
  // every update.
1273
1343
  this._fakeMouseMove(ev, pos.x, pos.y);
1274
-
1275
1344
  magnitude = Math.hypot(ev.detail.magnitudeX, ev.detail.magnitudeY);
1276
-
1277
1345
  if (Math.abs(magnitude - this._gestureLastMagnitudeX) > GESTURE_ZOOMSENS) {
1278
- this._handleKeyEvent(_keysym.default.XK_Control_L, "ControlLeft", true);
1279
-
1346
+ this._handleKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
1280
1347
  while (magnitude - this._gestureLastMagnitudeX > GESTURE_ZOOMSENS) {
1281
1348
  this._handleMouseButton(pos.x, pos.y, true, 0x8);
1282
-
1283
1349
  this._handleMouseButton(pos.x, pos.y, false, 0x8);
1284
-
1285
1350
  this._gestureLastMagnitudeX += GESTURE_ZOOMSENS;
1286
1351
  }
1287
-
1288
1352
  while (magnitude - this._gestureLastMagnitudeX < -GESTURE_ZOOMSENS) {
1289
1353
  this._handleMouseButton(pos.x, pos.y, true, 0x10);
1290
-
1291
1354
  this._handleMouseButton(pos.x, pos.y, false, 0x10);
1292
-
1293
1355
  this._gestureLastMagnitudeX -= GESTURE_ZOOMSENS;
1294
1356
  }
1295
1357
  }
1296
-
1297
- this._handleKeyEvent(_keysym.default.XK_Control_L, "ControlLeft", false);
1298
-
1358
+ this._handleKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", false);
1299
1359
  break;
1300
1360
  }
1301
-
1302
1361
  break;
1303
-
1304
1362
  case 'gestureend':
1305
1363
  switch (ev.detail.type) {
1306
1364
  case 'onetap':
@@ -1309,161 +1367,131 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1309
1367
  case 'pinch':
1310
1368
  case 'twodrag':
1311
1369
  break;
1312
-
1313
1370
  case 'drag':
1314
1371
  this._fakeMouseMove(ev, pos.x, pos.y);
1315
-
1316
1372
  this._handleMouseButton(pos.x, pos.y, false, 0x1);
1317
-
1318
1373
  break;
1319
-
1320
1374
  case 'longpress':
1321
1375
  this._fakeMouseMove(ev, pos.x, pos.y);
1322
-
1323
1376
  this._handleMouseButton(pos.x, pos.y, false, 0x4);
1324
-
1325
1377
  break;
1326
1378
  }
1327
-
1328
1379
  break;
1329
1380
  }
1330
- } // Message Handlers
1381
+ }
1331
1382
 
1383
+ // Message Handlers
1332
1384
  }, {
1333
1385
  key: "_negotiateProtocolVersion",
1334
1386
  value: function _negotiateProtocolVersion() {
1335
1387
  if (this._sock.rQwait("version", 12)) {
1336
1388
  return false;
1337
1389
  }
1338
-
1339
1390
  var sversion = this._sock.rQshiftStr(12).substr(4, 7);
1340
-
1341
1391
  Log.Info("Server ProtocolVersion: " + sversion);
1342
1392
  var isRepeater = 0;
1343
-
1344
1393
  switch (sversion) {
1345
1394
  case "000.000":
1346
1395
  // UltraVNC repeater
1347
1396
  isRepeater = 1;
1348
1397
  break;
1349
-
1350
1398
  case "003.003":
1351
- case "003.006": // UltraVNC
1352
-
1353
- case "003.889":
1354
- // Apple Remote Desktop
1399
+ case "003.006":
1400
+ // UltraVNC
1355
1401
  this._rfbVersion = 3.3;
1356
1402
  break;
1357
-
1358
1403
  case "003.007":
1359
1404
  this._rfbVersion = 3.7;
1360
1405
  break;
1361
-
1362
1406
  case "003.008":
1407
+ case "003.889": // Apple Remote Desktop
1363
1408
  case "004.000": // Intel AMT KVM
1364
-
1365
1409
  case "004.001": // RealVNC 4.6
1366
-
1367
1410
  case "005.000":
1368
1411
  // RealVNC 5.3
1369
1412
  this._rfbVersion = 3.8;
1370
1413
  break;
1371
-
1372
1414
  default:
1373
1415
  return this._fail("Invalid server version " + sversion);
1374
1416
  }
1375
-
1376
1417
  if (isRepeater) {
1377
1418
  var repeaterID = "ID:" + this._repeaterID;
1378
-
1379
1419
  while (repeaterID.length < 250) {
1380
1420
  repeaterID += "\0";
1381
1421
  }
1382
-
1383
1422
  this._sock.sendString(repeaterID);
1384
-
1385
1423
  return true;
1386
1424
  }
1387
-
1388
1425
  if (this._rfbVersion > this._rfbMaxVersion) {
1389
1426
  this._rfbVersion = this._rfbMaxVersion;
1390
1427
  }
1391
-
1392
1428
  var cversion = "00" + parseInt(this._rfbVersion, 10) + ".00" + this._rfbVersion * 10 % 10;
1393
-
1394
1429
  this._sock.sendString("RFB " + cversion + "\n");
1395
-
1396
1430
  Log.Debug('Sent ProtocolVersion: ' + cversion);
1397
1431
  this._rfbInitState = 'Security';
1398
1432
  }
1433
+ }, {
1434
+ key: "_isSupportedSecurityType",
1435
+ value: function _isSupportedSecurityType(type) {
1436
+ var clientTypes = [securityTypeNone, securityTypeVNCAuth, securityTypeRA2ne, securityTypeTight, securityTypeVeNCrypt, securityTypeXVP, securityTypeARD, securityTypePlain];
1437
+ return clientTypes.includes(type);
1438
+ }
1399
1439
  }, {
1400
1440
  key: "_negotiateSecurity",
1401
1441
  value: function _negotiateSecurity() {
1402
- // Polyfill since IE and PhantomJS doesn't have
1403
- // TypedArray.includes()
1404
- function includes(item, array) {
1405
- for (var i = 0; i < array.length; i++) {
1406
- if (array[i] === item) {
1407
- return true;
1408
- }
1409
- }
1410
-
1411
- return false;
1412
- }
1413
-
1414
1442
  if (this._rfbVersion >= 3.7) {
1415
1443
  // Server sends supported list, client decides
1416
1444
  var numTypes = this._sock.rQshift8();
1417
-
1418
1445
  if (this._sock.rQwait("security type", numTypes, 1)) {
1419
1446
  return false;
1420
1447
  }
1421
-
1422
1448
  if (numTypes === 0) {
1423
1449
  this._rfbInitState = "SecurityReason";
1424
1450
  this._securityContext = "no security types";
1425
1451
  this._securityStatus = 1;
1426
- return this._initMsg();
1452
+ return true;
1427
1453
  }
1428
-
1429
1454
  var types = this._sock.rQshiftBytes(numTypes);
1430
-
1431
- Log.Debug("Server security types: " + types); // Look for each auth in preferred order
1432
-
1433
- if (includes(1, types)) {
1434
- this._rfbAuthScheme = 1; // None
1435
- } else if (includes(22, types)) {
1436
- this._rfbAuthScheme = 22; // XVP
1437
- } else if (includes(16, types)) {
1438
- this._rfbAuthScheme = 16; // Tight
1439
- } else if (includes(2, types)) {
1440
- this._rfbAuthScheme = 2; // VNC Auth
1441
- } else if (includes(19, types)) {
1442
- this._rfbAuthScheme = 19; // VeNCrypt Auth
1443
- } else {
1455
+ Log.Debug("Server security types: " + types);
1456
+
1457
+ // Look for a matching security type in the order that the
1458
+ // server prefers
1459
+ this._rfbAuthScheme = -1;
1460
+ var _iterator3 = _createForOfIteratorHelper(types),
1461
+ _step3;
1462
+ try {
1463
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1464
+ var type = _step3.value;
1465
+ if (this._isSupportedSecurityType(type)) {
1466
+ this._rfbAuthScheme = type;
1467
+ break;
1468
+ }
1469
+ }
1470
+ } catch (err) {
1471
+ _iterator3.e(err);
1472
+ } finally {
1473
+ _iterator3.f();
1474
+ }
1475
+ if (this._rfbAuthScheme === -1) {
1444
1476
  return this._fail("Unsupported security types (types: " + types + ")");
1445
1477
  }
1446
-
1447
1478
  this._sock.send([this._rfbAuthScheme]);
1448
1479
  } else {
1449
1480
  // Server decides
1450
1481
  if (this._sock.rQwait("security scheme", 4)) {
1451
1482
  return false;
1452
1483
  }
1453
-
1454
1484
  this._rfbAuthScheme = this._sock.rQshift32();
1455
-
1456
1485
  if (this._rfbAuthScheme == 0) {
1457
1486
  this._rfbInitState = "SecurityReason";
1458
1487
  this._securityContext = "authentication scheme";
1459
1488
  this._securityStatus = 1;
1460
- return this._initMsg();
1489
+ return true;
1461
1490
  }
1462
1491
  }
1463
-
1464
1492
  this._rfbInitState = 'Authentication';
1465
1493
  Log.Debug('Authenticating using scheme: ' + this._rfbAuthScheme);
1466
- return this._initMsg(); // jump to authentication
1494
+ return true;
1467
1495
  }
1468
1496
  }, {
1469
1497
  key: "_handleSecurityReason",
@@ -1471,19 +1499,14 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1471
1499
  if (this._sock.rQwait("reason length", 4)) {
1472
1500
  return false;
1473
1501
  }
1474
-
1475
1502
  var strlen = this._sock.rQshift32();
1476
-
1477
1503
  var reason = "";
1478
-
1479
1504
  if (strlen > 0) {
1480
1505
  if (this._sock.rQwait("reason", strlen, 4)) {
1481
1506
  return false;
1482
1507
  }
1483
-
1484
1508
  reason = this._sock.rQshiftStr(strlen);
1485
1509
  }
1486
-
1487
1510
  if (reason !== "") {
1488
1511
  this.dispatchEvent(new CustomEvent("securityfailure", {
1489
1512
  detail: {
@@ -1500,8 +1523,9 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1500
1523
  }));
1501
1524
  return this._fail("Security negotiation failed on " + this._securityContext);
1502
1525
  }
1503
- } // authentication
1526
+ }
1504
1527
 
1528
+ // authentication
1505
1529
  }, {
1506
1530
  key: "_negotiateXvpAuth",
1507
1531
  value: function _negotiateXvpAuth() {
@@ -1513,15 +1537,13 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1513
1537
  }));
1514
1538
  return false;
1515
1539
  }
1516
-
1517
1540
  var xvpAuthStr = String.fromCharCode(this._rfbCredentials.username.length) + String.fromCharCode(this._rfbCredentials.target.length) + this._rfbCredentials.username + this._rfbCredentials.target;
1518
-
1519
1541
  this._sock.sendString(xvpAuthStr);
1520
-
1521
- this._rfbAuthScheme = 2;
1542
+ this._rfbAuthScheme = securityTypeVNCAuth;
1522
1543
  return this._negotiateAuthentication();
1523
- } // VeNCrypt authentication, currently only supports version 0.2 and only Plain subtype
1544
+ }
1524
1545
 
1546
+ // VeNCrypt authentication, currently only supports version 0.2 and only Plain subtype
1525
1547
  }, {
1526
1548
  key: "_negotiateVeNCryptAuth",
1527
1549
  value: function _negotiateVeNCryptAuth() {
@@ -1530,109 +1552,100 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1530
1552
  if (this._sock.rQwait("vencrypt version", 2)) {
1531
1553
  return false;
1532
1554
  }
1533
-
1534
1555
  var major = this._sock.rQshift8();
1535
-
1536
1556
  var minor = this._sock.rQshift8();
1537
-
1538
1557
  if (!(major == 0 && minor == 2)) {
1539
1558
  return this._fail("Unsupported VeNCrypt version " + major + "." + minor);
1540
1559
  }
1541
-
1542
1560
  this._sock.send([0, 2]);
1543
-
1544
1561
  this._rfbVeNCryptState = 1;
1545
- } // waiting for ACK
1546
-
1562
+ }
1547
1563
 
1564
+ // waiting for ACK
1548
1565
  if (this._rfbVeNCryptState == 1) {
1549
1566
  if (this._sock.rQwait("vencrypt ack", 1)) {
1550
1567
  return false;
1551
1568
  }
1552
-
1553
1569
  var res = this._sock.rQshift8();
1554
-
1555
1570
  if (res != 0) {
1556
1571
  return this._fail("VeNCrypt failure " + res);
1557
1572
  }
1558
-
1559
1573
  this._rfbVeNCryptState = 2;
1560
- } // must fall through here (i.e. no "else if"), beacause we may have already received
1574
+ }
1575
+ // must fall through here (i.e. no "else if"), beacause we may have already received
1561
1576
  // the subtypes length and won't be called again
1562
1577
 
1563
-
1564
1578
  if (this._rfbVeNCryptState == 2) {
1565
1579
  // waiting for subtypes length
1566
1580
  if (this._sock.rQwait("vencrypt subtypes length", 1)) {
1567
1581
  return false;
1568
1582
  }
1569
-
1570
1583
  var subtypesLength = this._sock.rQshift8();
1571
-
1572
1584
  if (subtypesLength < 1) {
1573
1585
  return this._fail("VeNCrypt subtypes empty");
1574
1586
  }
1575
-
1576
1587
  this._rfbVeNCryptSubtypesLength = subtypesLength;
1577
1588
  this._rfbVeNCryptState = 3;
1578
- } // waiting for subtypes list
1579
-
1589
+ }
1580
1590
 
1591
+ // waiting for subtypes list
1581
1592
  if (this._rfbVeNCryptState == 3) {
1582
1593
  if (this._sock.rQwait("vencrypt subtypes", 4 * this._rfbVeNCryptSubtypesLength)) {
1583
1594
  return false;
1584
1595
  }
1585
-
1586
1596
  var subtypes = [];
1587
-
1588
1597
  for (var i = 0; i < this._rfbVeNCryptSubtypesLength; i++) {
1589
1598
  subtypes.push(this._sock.rQshift32());
1590
- } // 256 = Plain subtype
1591
-
1592
-
1593
- if (subtypes.indexOf(256) != -1) {
1594
- // 0x100 = 256
1595
- this._sock.send([0, 0, 1, 0]);
1596
-
1597
- this._rfbVeNCryptState = 4;
1598
- } else {
1599
- return this._fail("VeNCrypt Plain subtype not offered by server");
1600
1599
  }
1601
- } // negotiated Plain subtype, server waits for password
1602
-
1603
1600
 
1604
- if (this._rfbVeNCryptState == 4) {
1605
- if (!this._rfbCredentials.username || !this._rfbCredentials.password) {
1606
- this.dispatchEvent(new CustomEvent("credentialsrequired", {
1607
- detail: {
1608
- types: ["username", "password"]
1609
- }
1610
- }));
1611
- return false;
1601
+ // Look for a matching security type in the order that the
1602
+ // server prefers
1603
+ this._rfbAuthScheme = -1;
1604
+ for (var _i2 = 0, _subtypes = subtypes; _i2 < _subtypes.length; _i2++) {
1605
+ var type = _subtypes[_i2];
1606
+ // Avoid getting in to a loop
1607
+ if (type === securityTypeVeNCrypt) {
1608
+ continue;
1609
+ }
1610
+ if (this._isSupportedSecurityType(type)) {
1611
+ this._rfbAuthScheme = type;
1612
+ break;
1613
+ }
1612
1614
  }
1613
-
1614
- var user = (0, _strings.encodeUTF8)(this._rfbCredentials.username);
1615
- var pass = (0, _strings.encodeUTF8)(this._rfbCredentials.password); // XXX we assume lengths are <= 255 (should not be an issue in the real world)
1616
-
1617
- this._sock.send([0, 0, 0, user.length]);
1618
-
1619
- this._sock.send([0, 0, 0, pass.length]);
1620
-
1621
- this._sock.sendString(user);
1622
-
1623
- this._sock.sendString(pass);
1624
-
1625
- this._rfbInitState = "SecurityResult";
1615
+ if (this._rfbAuthScheme === -1) {
1616
+ return this._fail("Unsupported security types (types: " + subtypes + ")");
1617
+ }
1618
+ this._sock.send([this._rfbAuthScheme >> 24, this._rfbAuthScheme >> 16, this._rfbAuthScheme >> 8, this._rfbAuthScheme]);
1619
+ this._rfbVeNCryptState == 4;
1626
1620
  return true;
1627
1621
  }
1628
1622
  }
1623
+ }, {
1624
+ key: "_negotiatePlainAuth",
1625
+ value: function _negotiatePlainAuth() {
1626
+ if (this._rfbCredentials.username === undefined || this._rfbCredentials.password === undefined) {
1627
+ this.dispatchEvent(new CustomEvent("credentialsrequired", {
1628
+ detail: {
1629
+ types: ["username", "password"]
1630
+ }
1631
+ }));
1632
+ return false;
1633
+ }
1634
+ var user = (0, _strings.encodeUTF8)(this._rfbCredentials.username);
1635
+ var pass = (0, _strings.encodeUTF8)(this._rfbCredentials.password);
1636
+ this._sock.send([user.length >> 24 & 0xFF, user.length >> 16 & 0xFF, user.length >> 8 & 0xFF, user.length & 0xFF]);
1637
+ this._sock.send([pass.length >> 24 & 0xFF, pass.length >> 16 & 0xFF, pass.length >> 8 & 0xFF, pass.length & 0xFF]);
1638
+ this._sock.sendString(user);
1639
+ this._sock.sendString(pass);
1640
+ this._rfbInitState = "SecurityResult";
1641
+ return true;
1642
+ }
1629
1643
  }, {
1630
1644
  key: "_negotiateStdVNCAuth",
1631
1645
  value: function _negotiateStdVNCAuth() {
1632
1646
  if (this._sock.rQwait("auth challenge", 16)) {
1633
1647
  return false;
1634
1648
  }
1635
-
1636
1649
  if (this._rfbCredentials.password === undefined) {
1637
1650
  this.dispatchEvent(new CustomEvent("credentialsrequired", {
1638
1651
  detail: {
@@ -1640,17 +1653,183 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1640
1653
  }
1641
1654
  }));
1642
1655
  return false;
1643
- } // TODO(directxman12): make genDES not require an Array
1644
-
1656
+ }
1645
1657
 
1658
+ // TODO(directxman12): make genDES not require an Array
1646
1659
  var challenge = Array.prototype.slice.call(this._sock.rQshiftBytes(16));
1647
1660
  var response = RFB.genDES(this._rfbCredentials.password, challenge);
1648
-
1649
1661
  this._sock.send(response);
1650
-
1651
1662
  this._rfbInitState = "SecurityResult";
1652
1663
  return true;
1653
1664
  }
1665
+ }, {
1666
+ key: "_negotiateARDAuth",
1667
+ value: function _negotiateARDAuth() {
1668
+ if (this._rfbCredentials.username === undefined || this._rfbCredentials.password === undefined) {
1669
+ this.dispatchEvent(new CustomEvent("credentialsrequired", {
1670
+ detail: {
1671
+ types: ["username", "password"]
1672
+ }
1673
+ }));
1674
+ return false;
1675
+ }
1676
+ if (this._rfbCredentials.ardPublicKey != undefined && this._rfbCredentials.ardCredentials != undefined) {
1677
+ // if the async web crypto is done return the results
1678
+ this._sock.send(this._rfbCredentials.ardCredentials);
1679
+ this._sock.send(this._rfbCredentials.ardPublicKey);
1680
+ this._rfbCredentials.ardCredentials = null;
1681
+ this._rfbCredentials.ardPublicKey = null;
1682
+ this._rfbInitState = "SecurityResult";
1683
+ return true;
1684
+ }
1685
+ if (this._sock.rQwait("read ard", 4)) {
1686
+ return false;
1687
+ }
1688
+ var generator = this._sock.rQshiftBytes(2); // DH base generator value
1689
+
1690
+ var keyLength = this._sock.rQshift16();
1691
+ if (this._sock.rQwait("read ard keylength", keyLength * 2, 4)) {
1692
+ return false;
1693
+ }
1694
+
1695
+ // read the server values
1696
+ var prime = this._sock.rQshiftBytes(keyLength); // predetermined prime modulus
1697
+ var serverPublicKey = this._sock.rQshiftBytes(keyLength); // other party's public key
1698
+
1699
+ var clientPrivateKey = window.crypto.getRandomValues(new Uint8Array(keyLength));
1700
+ var padding = Array.from(window.crypto.getRandomValues(new Uint8Array(64)), function (_byte) {
1701
+ return String.fromCharCode(65 + _byte % 26);
1702
+ }).join('');
1703
+ this._negotiateARDAuthAsync(generator, keyLength, prime, serverPublicKey, clientPrivateKey, padding);
1704
+ return false;
1705
+ }
1706
+ }, {
1707
+ key: "_modPow",
1708
+ value: function _modPow(base, exponent, modulus) {
1709
+ var baseHex = "0x" + Array.from(base, function (_byte2) {
1710
+ return ('0' + (_byte2 & 0xFF).toString(16)).slice(-2);
1711
+ }).join('');
1712
+ var exponentHex = "0x" + Array.from(exponent, function (_byte3) {
1713
+ return ('0' + (_byte3 & 0xFF).toString(16)).slice(-2);
1714
+ }).join('');
1715
+ var modulusHex = "0x" + Array.from(modulus, function (_byte4) {
1716
+ return ('0' + (_byte4 & 0xFF).toString(16)).slice(-2);
1717
+ }).join('');
1718
+ var b = BigInt(baseHex);
1719
+ var e = BigInt(exponentHex);
1720
+ var m = BigInt(modulusHex);
1721
+ var r = 1n;
1722
+ b = b % m;
1723
+ while (e > 0) {
1724
+ if (e % 2n === 1n) {
1725
+ r = r * b % m;
1726
+ }
1727
+ e = e / 2n;
1728
+ b = b * b % m;
1729
+ }
1730
+ var hexResult = r.toString(16);
1731
+ while (hexResult.length / 2 < exponent.length || hexResult.length % 2 != 0) {
1732
+ hexResult = "0" + hexResult;
1733
+ }
1734
+ var bytesResult = [];
1735
+ for (var c = 0; c < hexResult.length; c += 2) {
1736
+ bytesResult.push(parseInt(hexResult.substr(c, 2), 16));
1737
+ }
1738
+ return bytesResult;
1739
+ }
1740
+ }, {
1741
+ key: "_aesEcbEncrypt",
1742
+ value: function () {
1743
+ var _aesEcbEncrypt2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(string, key) {
1744
+ var keyString, aesKey, data, i, encrypted, _i3, block, encryptedBlock;
1745
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1746
+ while (1) {
1747
+ switch (_context.prev = _context.next) {
1748
+ case 0:
1749
+ // perform AES-ECB blocks
1750
+ keyString = Array.from(key, function (_byte5) {
1751
+ return String.fromCharCode(_byte5);
1752
+ }).join('');
1753
+ _context.next = 3;
1754
+ return window.crypto.subtle.importKey("raw", (0, _md.MD5)(keyString), {
1755
+ name: "AES-CBC"
1756
+ }, false, ["encrypt"]);
1757
+ case 3:
1758
+ aesKey = _context.sent;
1759
+ data = new Uint8Array(string.length);
1760
+ for (i = 0; i < string.length; ++i) {
1761
+ data[i] = string.charCodeAt(i);
1762
+ }
1763
+ encrypted = new Uint8Array(data.length);
1764
+ _i3 = 0;
1765
+ case 8:
1766
+ if (!(_i3 < data.length)) {
1767
+ _context.next = 17;
1768
+ break;
1769
+ }
1770
+ block = data.slice(_i3, _i3 + 16);
1771
+ _context.next = 12;
1772
+ return window.crypto.subtle.encrypt({
1773
+ name: "AES-CBC",
1774
+ iv: block
1775
+ }, aesKey, new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
1776
+ case 12:
1777
+ encryptedBlock = _context.sent;
1778
+ encrypted.set(new Uint8Array(encryptedBlock).slice(0, 16), _i3);
1779
+ case 14:
1780
+ _i3 += 16;
1781
+ _context.next = 8;
1782
+ break;
1783
+ case 17:
1784
+ return _context.abrupt("return", encrypted);
1785
+ case 18:
1786
+ case "end":
1787
+ return _context.stop();
1788
+ }
1789
+ }
1790
+ }, _callee);
1791
+ }));
1792
+ function _aesEcbEncrypt(_x, _x2) {
1793
+ return _aesEcbEncrypt2.apply(this, arguments);
1794
+ }
1795
+ return _aesEcbEncrypt;
1796
+ }()
1797
+ }, {
1798
+ key: "_negotiateARDAuthAsync",
1799
+ value: function () {
1800
+ var _negotiateARDAuthAsync2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(generator, keyLength, prime, serverPublicKey, clientPrivateKey, padding) {
1801
+ var clientPublicKey, sharedKey, username, password, paddedUsername, paddedPassword, credentials, encrypted;
1802
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1803
+ while (1) {
1804
+ switch (_context2.prev = _context2.next) {
1805
+ case 0:
1806
+ // calculate the DH keys
1807
+ clientPublicKey = this._modPow(generator, clientPrivateKey, prime);
1808
+ sharedKey = this._modPow(serverPublicKey, clientPrivateKey, prime);
1809
+ username = (0, _strings.encodeUTF8)(this._rfbCredentials.username).substring(0, 63);
1810
+ password = (0, _strings.encodeUTF8)(this._rfbCredentials.password).substring(0, 63);
1811
+ paddedUsername = username + '\0' + padding.substring(0, 63);
1812
+ paddedPassword = password + '\0' + padding.substring(0, 63);
1813
+ credentials = paddedUsername.substring(0, 64) + paddedPassword.substring(0, 64);
1814
+ _context2.next = 9;
1815
+ return this._aesEcbEncrypt(credentials, sharedKey);
1816
+ case 9:
1817
+ encrypted = _context2.sent;
1818
+ this._rfbCredentials.ardCredentials = encrypted;
1819
+ this._rfbCredentials.ardPublicKey = clientPublicKey;
1820
+ this._resumeAuthentication();
1821
+ case 13:
1822
+ case "end":
1823
+ return _context2.stop();
1824
+ }
1825
+ }
1826
+ }, _callee2, this);
1827
+ }));
1828
+ function _negotiateARDAuthAsync(_x3, _x4, _x5, _x6, _x7, _x8) {
1829
+ return _negotiateARDAuthAsync2.apply(this, arguments);
1830
+ }
1831
+ return _negotiateARDAuthAsync;
1832
+ }()
1654
1833
  }, {
1655
1834
  key: "_negotiateTightUnixAuth",
1656
1835
  value: function _negotiateTightUnixAuth() {
@@ -1662,15 +1841,10 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1662
1841
  }));
1663
1842
  return false;
1664
1843
  }
1665
-
1666
1844
  this._sock.send([0, 0, 0, this._rfbCredentials.username.length]);
1667
-
1668
1845
  this._sock.send([0, 0, 0, this._rfbCredentials.password.length]);
1669
-
1670
1846
  this._sock.sendString(this._rfbCredentials.username);
1671
-
1672
1847
  this._sock.sendString(this._rfbCredentials.password);
1673
-
1674
1848
  this._rfbInitState = "SecurityResult";
1675
1849
  return true;
1676
1850
  }
@@ -1683,44 +1857,37 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1683
1857
  signature: 'NOTUNNEL'
1684
1858
  }
1685
1859
  };
1686
- var serverSupportedTunnelTypes = {}; // receive tunnel capabilities
1687
-
1860
+ var serverSupportedTunnelTypes = {};
1861
+ // receive tunnel capabilities
1688
1862
  for (var i = 0; i < numTunnels; i++) {
1689
1863
  var capCode = this._sock.rQshift32();
1690
-
1691
1864
  var capVendor = this._sock.rQshiftStr(4);
1692
-
1693
1865
  var capSignature = this._sock.rQshiftStr(8);
1694
-
1695
1866
  serverSupportedTunnelTypes[capCode] = {
1696
1867
  vendor: capVendor,
1697
1868
  signature: capSignature
1698
1869
  };
1699
1870
  }
1871
+ Log.Debug("Server Tight tunnel types: " + serverSupportedTunnelTypes);
1700
1872
 
1701
- Log.Debug("Server Tight tunnel types: " + serverSupportedTunnelTypes); // Siemens touch panels have a VNC server that supports NOTUNNEL,
1873
+ // Siemens touch panels have a VNC server that supports NOTUNNEL,
1702
1874
  // but forgets to advertise it. Try to detect such servers by
1703
1875
  // looking for their custom tunnel type.
1704
-
1705
1876
  if (serverSupportedTunnelTypes[1] && serverSupportedTunnelTypes[1].vendor === "SICR" && serverSupportedTunnelTypes[1].signature === "SCHANNEL") {
1706
1877
  Log.Debug("Detected Siemens server. Assuming NOTUNNEL support.");
1707
1878
  serverSupportedTunnelTypes[0] = {
1708
1879
  vendor: 'TGHT',
1709
1880
  signature: 'NOTUNNEL'
1710
1881
  };
1711
- } // choose the notunnel type
1712
-
1882
+ }
1713
1883
 
1884
+ // choose the notunnel type
1714
1885
  if (serverSupportedTunnelTypes[0]) {
1715
1886
  if (serverSupportedTunnelTypes[0].vendor != clientSupportedTunnelTypes[0].vendor || serverSupportedTunnelTypes[0].signature != clientSupportedTunnelTypes[0].signature) {
1716
1887
  return this._fail("Client's tunnel type had the incorrect " + "vendor or signature");
1717
1888
  }
1718
-
1719
1889
  Log.Debug("Selected tunnel type: " + clientSupportedTunnelTypes[0]);
1720
-
1721
1890
  this._sock.send([0, 0, 0, 0]); // use NOTUNNEL
1722
-
1723
-
1724
1891
  return false; // wait until we receive the sub auth count to continue
1725
1892
  } else {
1726
1893
  return this._fail("Server wanted tunnels, but doesn't support " + "the notunnel type");
@@ -1734,121 +1901,126 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1734
1901
  if (this._sock.rQwait("num tunnels", 4)) {
1735
1902
  return false;
1736
1903
  }
1737
-
1738
1904
  var numTunnels = this._sock.rQshift32();
1739
-
1740
1905
  if (numTunnels > 0 && this._sock.rQwait("tunnel capabilities", 16 * numTunnels, 4)) {
1741
1906
  return false;
1742
1907
  }
1743
-
1744
1908
  this._rfbTightVNC = true;
1745
-
1746
1909
  if (numTunnels > 0) {
1747
1910
  this._negotiateTightTunnels(numTunnels);
1748
-
1749
1911
  return false; // wait until we receive the sub auth to continue
1750
1912
  }
1751
- } // second pass, do the sub-auth negotiation
1752
-
1913
+ }
1753
1914
 
1915
+ // second pass, do the sub-auth negotiation
1754
1916
  if (this._sock.rQwait("sub auth count", 4)) {
1755
1917
  return false;
1756
1918
  }
1757
-
1758
1919
  var subAuthCount = this._sock.rQshift32();
1759
-
1760
1920
  if (subAuthCount === 0) {
1761
1921
  // empty sub-auth list received means 'no auth' subtype selected
1762
1922
  this._rfbInitState = 'SecurityResult';
1763
1923
  return true;
1764
1924
  }
1765
-
1766
1925
  if (this._sock.rQwait("sub auth capabilities", 16 * subAuthCount, 4)) {
1767
1926
  return false;
1768
1927
  }
1769
-
1770
1928
  var clientSupportedTypes = {
1771
1929
  'STDVNOAUTH__': 1,
1772
1930
  'STDVVNCAUTH_': 2,
1773
1931
  'TGHTULGNAUTH': 129
1774
1932
  };
1775
1933
  var serverSupportedTypes = [];
1776
-
1777
1934
  for (var i = 0; i < subAuthCount; i++) {
1778
1935
  this._sock.rQshift32(); // capNum
1779
-
1780
-
1781
1936
  var capabilities = this._sock.rQshiftStr(12);
1782
-
1783
1937
  serverSupportedTypes.push(capabilities);
1784
1938
  }
1785
-
1786
1939
  Log.Debug("Server Tight authentication types: " + serverSupportedTypes);
1787
-
1788
1940
  for (var authType in clientSupportedTypes) {
1789
1941
  if (serverSupportedTypes.indexOf(authType) != -1) {
1790
1942
  this._sock.send([0, 0, 0, clientSupportedTypes[authType]]);
1791
-
1792
1943
  Log.Debug("Selected authentication type: " + authType);
1793
-
1794
1944
  switch (authType) {
1795
1945
  case 'STDVNOAUTH__':
1796
1946
  // no auth
1797
1947
  this._rfbInitState = 'SecurityResult';
1798
1948
  return true;
1799
-
1800
1949
  case 'STDVVNCAUTH_':
1801
- // VNC auth
1802
- this._rfbAuthScheme = 2;
1803
- return this._initMsg();
1804
-
1950
+ this._rfbAuthScheme = securityTypeVNCAuth;
1951
+ return true;
1805
1952
  case 'TGHTULGNAUTH':
1806
- // UNIX auth
1807
- this._rfbAuthScheme = 129;
1808
- return this._initMsg();
1809
-
1953
+ this._rfbAuthScheme = securityTypeUnixLogon;
1954
+ return true;
1810
1955
  default:
1811
1956
  return this._fail("Unsupported tiny auth scheme " + "(scheme: " + authType + ")");
1812
1957
  }
1813
1958
  }
1814
1959
  }
1815
-
1816
1960
  return this._fail("No supported sub-auth types!");
1817
1961
  }
1962
+ }, {
1963
+ key: "_handleRSAAESCredentialsRequired",
1964
+ value: function _handleRSAAESCredentialsRequired(event) {
1965
+ this.dispatchEvent(event);
1966
+ }
1967
+ }, {
1968
+ key: "_handleRSAAESServerVerification",
1969
+ value: function _handleRSAAESServerVerification(event) {
1970
+ this.dispatchEvent(event);
1971
+ }
1972
+ }, {
1973
+ key: "_negotiateRA2neAuth",
1974
+ value: function _negotiateRA2neAuth() {
1975
+ var _this5 = this;
1976
+ if (this._rfbRSAAESAuthenticationState === null) {
1977
+ this._rfbRSAAESAuthenticationState = new _ra["default"](this._sock, function () {
1978
+ return _this5._rfbCredentials;
1979
+ });
1980
+ this._rfbRSAAESAuthenticationState.addEventListener("serververification", this._eventHandlers.handleRSAAESServerVerification);
1981
+ this._rfbRSAAESAuthenticationState.addEventListener("credentialsrequired", this._eventHandlers.handleRSAAESCredentialsRequired);
1982
+ }
1983
+ this._rfbRSAAESAuthenticationState.checkInternalEvents();
1984
+ if (!this._rfbRSAAESAuthenticationState.hasStarted) {
1985
+ this._rfbRSAAESAuthenticationState.negotiateRA2neAuthAsync()["catch"](function (e) {
1986
+ if (e.message !== "disconnect normally") {
1987
+ _this5._fail(e.message);
1988
+ }
1989
+ }).then(function () {
1990
+ _this5.dispatchEvent(new CustomEvent('securityresult'));
1991
+ _this5._rfbInitState = "SecurityResult";
1992
+ return true;
1993
+ })["finally"](function () {
1994
+ _this5._rfbRSAAESAuthenticationState.removeEventListener("serververification", _this5._eventHandlers.handleRSAAESServerVerification);
1995
+ _this5._rfbRSAAESAuthenticationState.removeEventListener("credentialsrequired", _this5._eventHandlers.handleRSAAESCredentialsRequired);
1996
+ _this5._rfbRSAAESAuthenticationState = null;
1997
+ });
1998
+ }
1999
+ return false;
2000
+ }
1818
2001
  }, {
1819
2002
  key: "_negotiateAuthentication",
1820
2003
  value: function _negotiateAuthentication() {
1821
2004
  switch (this._rfbAuthScheme) {
1822
- case 1:
1823
- // no auth
1824
- if (this._rfbVersion >= 3.8) {
1825
- this._rfbInitState = 'SecurityResult';
1826
- return true;
1827
- }
1828
-
1829
- this._rfbInitState = 'ClientInitialisation';
1830
- return this._initMsg();
1831
-
1832
- case 22:
1833
- // XVP auth
2005
+ case securityTypeNone:
2006
+ this._rfbInitState = 'SecurityResult';
2007
+ return true;
2008
+ case securityTypeXVP:
1834
2009
  return this._negotiateXvpAuth();
1835
-
1836
- case 2:
1837
- // VNC authentication
2010
+ case securityTypeARD:
2011
+ return this._negotiateARDAuth();
2012
+ case securityTypeVNCAuth:
1838
2013
  return this._negotiateStdVNCAuth();
1839
-
1840
- case 16:
1841
- // TightVNC Security Type
2014
+ case securityTypeTight:
1842
2015
  return this._negotiateTightAuth();
1843
-
1844
- case 19:
1845
- // VeNCrypt Security Type
2016
+ case securityTypeVeNCrypt:
1846
2017
  return this._negotiateVeNCryptAuth();
1847
-
1848
- case 129:
1849
- // TightVNC UNIX Security Type
2018
+ case securityTypePlain:
2019
+ return this._negotiatePlainAuth();
2020
+ case securityTypeUnixLogon:
1850
2021
  return this._negotiateTightUnixAuth();
1851
-
2022
+ case securityTypeRA2ne:
2023
+ return this._negotiateRA2neAuth();
1852
2024
  default:
1853
2025
  return this._fail("Unsupported auth scheme (scheme: " + this._rfbAuthScheme + ")");
1854
2026
  }
@@ -1856,23 +2028,27 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1856
2028
  }, {
1857
2029
  key: "_handleSecurityResult",
1858
2030
  value: function _handleSecurityResult() {
2031
+ // There is no security choice, and hence no security result
2032
+ // until RFB 3.7
2033
+ if (this._rfbVersion < 3.7) {
2034
+ this._rfbInitState = 'ClientInitialisation';
2035
+ return true;
2036
+ }
1859
2037
  if (this._sock.rQwait('VNC auth response ', 4)) {
1860
2038
  return false;
1861
2039
  }
1862
-
1863
2040
  var status = this._sock.rQshift32();
1864
-
1865
2041
  if (status === 0) {
1866
2042
  // OK
1867
2043
  this._rfbInitState = 'ClientInitialisation';
1868
2044
  Log.Debug('Authentication OK');
1869
- return this._initMsg();
2045
+ return true;
1870
2046
  } else {
1871
2047
  if (this._rfbVersion >= 3.8) {
1872
2048
  this._rfbInitState = "SecurityReason";
1873
2049
  this._securityContext = "security result";
1874
2050
  this._securityStatus = status;
1875
- return this._initMsg();
2051
+ return true;
1876
2052
  } else {
1877
2053
  this.dispatchEvent(new CustomEvent("securityfailure", {
1878
2054
  detail: {
@@ -1889,130 +2065,102 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
1889
2065
  if (this._sock.rQwait("server initialization", 24)) {
1890
2066
  return false;
1891
2067
  }
1892
- /* Screen size */
1893
-
1894
2068
 
2069
+ /* Screen size */
1895
2070
  var width = this._sock.rQshift16();
1896
-
1897
2071
  var height = this._sock.rQshift16();
1898
- /* PIXEL_FORMAT */
1899
-
1900
2072
 
2073
+ /* PIXEL_FORMAT */
1901
2074
  var bpp = this._sock.rQshift8();
1902
-
1903
2075
  var depth = this._sock.rQshift8();
1904
-
1905
2076
  var bigEndian = this._sock.rQshift8();
1906
-
1907
2077
  var trueColor = this._sock.rQshift8();
1908
-
1909
2078
  var redMax = this._sock.rQshift16();
1910
-
1911
2079
  var greenMax = this._sock.rQshift16();
1912
-
1913
2080
  var blueMax = this._sock.rQshift16();
1914
-
1915
2081
  var redShift = this._sock.rQshift8();
1916
-
1917
2082
  var greenShift = this._sock.rQshift8();
1918
-
1919
2083
  var blueShift = this._sock.rQshift8();
1920
-
1921
2084
  this._sock.rQskipBytes(3); // padding
2085
+
1922
2086
  // NB(directxman12): we don't want to call any callbacks or print messages until
1923
2087
  // *after* we're past the point where we could backtrack
1924
2088
 
1925
2089
  /* Connection name/title */
1926
-
1927
-
1928
2090
  var nameLength = this._sock.rQshift32();
1929
-
1930
2091
  if (this._sock.rQwait('server init name', nameLength, 24)) {
1931
2092
  return false;
1932
2093
  }
1933
-
1934
2094
  var name = this._sock.rQshiftStr(nameLength);
1935
-
1936
2095
  name = (0, _strings.decodeUTF8)(name, true);
1937
-
1938
2096
  if (this._rfbTightVNC) {
1939
2097
  if (this._sock.rQwait('TightVNC extended server init header', 8, 24 + nameLength)) {
1940
2098
  return false;
1941
- } // In TightVNC mode, ServerInit message is extended
1942
-
1943
-
2099
+ }
2100
+ // In TightVNC mode, ServerInit message is extended
1944
2101
  var numServerMessages = this._sock.rQshift16();
1945
-
1946
2102
  var numClientMessages = this._sock.rQshift16();
1947
-
1948
2103
  var numEncodings = this._sock.rQshift16();
1949
-
1950
2104
  this._sock.rQskipBytes(2); // padding
1951
2105
 
1952
-
1953
2106
  var totalMessagesLength = (numServerMessages + numClientMessages + numEncodings) * 16;
1954
-
1955
2107
  if (this._sock.rQwait('TightVNC extended server init header', totalMessagesLength, 32 + nameLength)) {
1956
2108
  return false;
1957
- } // we don't actually do anything with the capability information that TIGHT sends,
1958
- // so we just skip the all of this.
1959
- // TIGHT server message capabilities
1960
-
1961
-
1962
- this._sock.rQskipBytes(16 * numServerMessages); // TIGHT client message capabilities
2109
+ }
1963
2110
 
2111
+ // we don't actually do anything with the capability information that TIGHT sends,
2112
+ // so we just skip the all of this.
1964
2113
 
1965
- this._sock.rQskipBytes(16 * numClientMessages); // TIGHT encoding capabilities
2114
+ // TIGHT server message capabilities
2115
+ this._sock.rQskipBytes(16 * numServerMessages);
1966
2116
 
2117
+ // TIGHT client message capabilities
2118
+ this._sock.rQskipBytes(16 * numClientMessages);
1967
2119
 
2120
+ // TIGHT encoding capabilities
1968
2121
  this._sock.rQskipBytes(16 * numEncodings);
1969
- } // NB(directxman12): these are down here so that we don't run them multiple times
1970
- // if we backtrack
1971
-
2122
+ }
1972
2123
 
1973
- Log.Info("Screen: " + width + "x" + height + ", bpp: " + bpp + ", depth: " + depth + ", bigEndian: " + bigEndian + ", trueColor: " + trueColor + ", redMax: " + redMax + ", greenMax: " + greenMax + ", blueMax: " + blueMax + ", redShift: " + redShift + ", greenShift: " + greenShift + ", blueShift: " + blueShift); // we're past the point where we could backtrack, so it's safe to call this
2124
+ // NB(directxman12): these are down here so that we don't run them multiple times
2125
+ // if we backtrack
2126
+ Log.Info("Screen: " + width + "x" + height + ", bpp: " + bpp + ", depth: " + depth + ", bigEndian: " + bigEndian + ", trueColor: " + trueColor + ", redMax: " + redMax + ", greenMax: " + greenMax + ", blueMax: " + blueMax + ", redShift: " + redShift + ", greenShift: " + greenShift + ", blueShift: " + blueShift);
1974
2127
 
2128
+ // we're past the point where we could backtrack, so it's safe to call this
1975
2129
  this._setDesktopName(name);
1976
-
1977
2130
  this._resize(width, height);
1978
-
1979
2131
  if (!this._viewOnly) {
1980
2132
  this._keyboard.grab();
1981
2133
  }
1982
-
1983
2134
  this._fbDepth = 24;
1984
-
1985
2135
  if (this._fbName === "Intel(r) AMT KVM") {
1986
2136
  Log.Warn("Intel AMT KVM only supports 8/16 bit depths. Using low color mode.");
1987
2137
  this._fbDepth = 8;
1988
2138
  }
1989
-
1990
2139
  RFB.messages.pixelFormat(this._sock, this._fbDepth, true);
1991
-
1992
2140
  this._sendEncodings();
1993
-
1994
2141
  RFB.messages.fbUpdateRequest(this._sock, false, 0, 0, this._fbWidth, this._fbHeight);
1995
-
1996
2142
  this._updateConnectionState('connected');
1997
-
1998
2143
  return true;
1999
2144
  }
2000
2145
  }, {
2001
2146
  key: "_sendEncodings",
2002
2147
  value: function _sendEncodings() {
2003
- var encs = []; // In preference order
2004
-
2005
- encs.push(_encodings.encodings.encodingCopyRect); // Only supported with full depth support
2148
+ var encs = [];
2006
2149
 
2150
+ // In preference order
2151
+ encs.push(_encodings.encodings.encodingCopyRect);
2152
+ // Only supported with full depth support
2007
2153
  if (this._fbDepth == 24) {
2008
2154
  encs.push(_encodings.encodings.encodingTight);
2009
2155
  encs.push(_encodings.encodings.encodingTightPNG);
2156
+ encs.push(_encodings.encodings.encodingZRLE);
2157
+ encs.push(_encodings.encodings.encodingJPEG);
2010
2158
  encs.push(_encodings.encodings.encodingHextile);
2011
2159
  encs.push(_encodings.encodings.encodingRRE);
2012
2160
  }
2161
+ encs.push(_encodings.encodings.encodingRaw);
2013
2162
 
2014
- encs.push(_encodings.encodings.encodingRaw); // Psuedo-encoding settings
2015
-
2163
+ // Psuedo-encoding settings
2016
2164
  encs.push(_encodings.encodings.pseudoEncodingQualityLevel0 + this._qualityLevel);
2017
2165
  encs.push(_encodings.encodings.pseudoEncodingCompressLevel0 + this._compressionLevel);
2018
2166
  encs.push(_encodings.encodings.pseudoEncodingDesktopSize);
@@ -2024,14 +2172,13 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2024
2172
  encs.push(_encodings.encodings.pseudoEncodingContinuousUpdates);
2025
2173
  encs.push(_encodings.encodings.pseudoEncodingDesktopName);
2026
2174
  encs.push(_encodings.encodings.pseudoEncodingExtendedClipboard);
2027
-
2028
2175
  if (this._fbDepth == 24) {
2029
2176
  encs.push(_encodings.encodings.pseudoEncodingVMwareCursor);
2030
2177
  encs.push(_encodings.encodings.pseudoEncodingCursor);
2031
2178
  }
2032
-
2033
2179
  RFB.messages.clientEncodings(this._sock, encs);
2034
2180
  }
2181
+
2035
2182
  /* RFB protocol initialization states:
2036
2183
  * ProtocolVersion
2037
2184
  * Security
@@ -2040,40 +2187,40 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2040
2187
  * ClientInitialization - not triggered by server message
2041
2188
  * ServerInitialization
2042
2189
  */
2043
-
2044
2190
  }, {
2045
2191
  key: "_initMsg",
2046
2192
  value: function _initMsg() {
2047
2193
  switch (this._rfbInitState) {
2048
2194
  case 'ProtocolVersion':
2049
2195
  return this._negotiateProtocolVersion();
2050
-
2051
2196
  case 'Security':
2052
2197
  return this._negotiateSecurity();
2053
-
2054
2198
  case 'Authentication':
2055
2199
  return this._negotiateAuthentication();
2056
-
2057
2200
  case 'SecurityResult':
2058
2201
  return this._handleSecurityResult();
2059
-
2060
2202
  case 'SecurityReason':
2061
2203
  return this._handleSecurityReason();
2062
-
2063
2204
  case 'ClientInitialisation':
2064
2205
  this._sock.send([this._shared ? 1 : 0]); // ClientInitialisation
2065
-
2066
-
2067
2206
  this._rfbInitState = 'ServerInitialisation';
2068
2207
  return true;
2069
-
2070
2208
  case 'ServerInitialisation':
2071
2209
  return this._negotiateServerInit();
2072
-
2073
2210
  default:
2074
2211
  return this._fail("Unknown init state (state: " + this._rfbInitState + ")");
2075
2212
  }
2076
2213
  }
2214
+
2215
+ // Resume authentication handshake after it was paused for some
2216
+ // reason, e.g. waiting for a password from the user
2217
+ }, {
2218
+ key: "_resumeAuthentication",
2219
+ value: function _resumeAuthentication() {
2220
+ // We use setTimeout() so it's run in its own context, just like
2221
+ // it originally did via the WebSocket's event handler
2222
+ setTimeout(this._initMsg.bind(this), 0);
2223
+ }
2077
2224
  }, {
2078
2225
  key: "_handleSetColourMapMsg",
2079
2226
  value: function _handleSetColourMapMsg() {
@@ -2084,30 +2231,22 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2084
2231
  key: "_handleServerCutText",
2085
2232
  value: function _handleServerCutText() {
2086
2233
  Log.Debug("ServerCutText");
2087
-
2088
2234
  if (this._sock.rQwait("ServerCutText header", 7, 1)) {
2089
2235
  return false;
2090
2236
  }
2091
-
2092
2237
  this._sock.rQskipBytes(3); // Padding
2093
2238
 
2094
-
2095
2239
  var length = this._sock.rQshift32();
2096
-
2097
2240
  length = (0, _int.toSigned32bit)(length);
2098
-
2099
2241
  if (this._sock.rQwait("ServerCutText content", Math.abs(length), 8)) {
2100
2242
  return false;
2101
2243
  }
2102
-
2103
2244
  if (length >= 0) {
2104
2245
  //Standard msg
2105
2246
  var text = this._sock.rQshiftStr(length);
2106
-
2107
2247
  if (this._viewOnly) {
2108
2248
  return true;
2109
2249
  }
2110
-
2111
2250
  this.dispatchEvent(new CustomEvent("clipboard", {
2112
2251
  detail: {
2113
2252
  text: text
@@ -2116,38 +2255,35 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2116
2255
  } else {
2117
2256
  //Extended msg.
2118
2257
  length = Math.abs(length);
2119
-
2120
2258
  var flags = this._sock.rQshift32();
2121
-
2122
2259
  var formats = flags & 0x0000FFFF;
2123
2260
  var actions = flags & 0xFF000000;
2124
2261
  var isCaps = !!(actions & extendedClipboardActionCaps);
2125
-
2126
2262
  if (isCaps) {
2127
2263
  this._clipboardServerCapabilitiesFormats = {};
2128
- this._clipboardServerCapabilitiesActions = {}; // Update our server capabilities for Formats
2264
+ this._clipboardServerCapabilitiesActions = {};
2129
2265
 
2266
+ // Update our server capabilities for Formats
2130
2267
  for (var i = 0; i <= 15; i++) {
2131
- var index = 1 << i; // Check if format flag is set.
2268
+ var index = 1 << i;
2132
2269
 
2270
+ // Check if format flag is set.
2133
2271
  if (formats & index) {
2134
- this._clipboardServerCapabilitiesFormats[index] = true; // We don't send unsolicited clipboard, so we
2272
+ this._clipboardServerCapabilitiesFormats[index] = true;
2273
+ // We don't send unsolicited clipboard, so we
2135
2274
  // ignore the size
2136
-
2137
2275
  this._sock.rQshift32();
2138
2276
  }
2139
- } // Update our server capabilities for Actions
2140
-
2141
-
2142
- for (var _i = 24; _i <= 31; _i++) {
2143
- var _index = 1 << _i;
2277
+ }
2144
2278
 
2279
+ // Update our server capabilities for Actions
2280
+ for (var _i4 = 24; _i4 <= 31; _i4++) {
2281
+ var _index = 1 << _i4;
2145
2282
  this._clipboardServerCapabilitiesActions[_index] = !!(actions & _index);
2146
2283
  }
2284
+
2147
2285
  /* Caps handling done, send caps with the clients
2148
2286
  capabilities set as a response */
2149
-
2150
-
2151
2287
  var clientActions = [extendedClipboardActionCaps, extendedClipboardActionRequest, extendedClipboardActionPeek, extendedClipboardActionNotify, extendedClipboardActionProvide];
2152
2288
  RFB.messages.extendedClipboardCaps(this._sock, clientActions, {
2153
2289
  extendedClipboardFormatText: 0
@@ -2155,9 +2291,9 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2155
2291
  } else if (actions === extendedClipboardActionRequest) {
2156
2292
  if (this._viewOnly) {
2157
2293
  return true;
2158
- } // Check if server has told us it can handle Provide and there is clipboard data to send.
2159
-
2294
+ }
2160
2295
 
2296
+ // Check if server has told us it can handle Provide and there is clipboard data to send.
2161
2297
  if (this._clipboardText != null && this._clipboardServerCapabilitiesActions[extendedClipboardActionProvide]) {
2162
2298
  if (formats & extendedClipboardFormatText) {
2163
2299
  RFB.messages.extendedClipboardProvide(this._sock, [extendedClipboardFormatText], [this._clipboardText]);
@@ -2167,7 +2303,6 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2167
2303
  if (this._viewOnly) {
2168
2304
  return true;
2169
2305
  }
2170
-
2171
2306
  if (this._clipboardServerCapabilitiesActions[extendedClipboardActionNotify]) {
2172
2307
  if (this._clipboardText != null) {
2173
2308
  RFB.messages.extendedClipboardNotify(this._sock, [extendedClipboardFormatText]);
@@ -2179,7 +2314,6 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2179
2314
  if (this._viewOnly) {
2180
2315
  return true;
2181
2316
  }
2182
-
2183
2317
  if (this._clipboardServerCapabilitiesActions[extendedClipboardActionRequest]) {
2184
2318
  if (formats & extendedClipboardFormatText) {
2185
2319
  RFB.messages.extendedClipboardRequest(this._sock, [extendedClipboardFormatText]);
@@ -2189,23 +2323,19 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2189
2323
  if (this._viewOnly) {
2190
2324
  return true;
2191
2325
  }
2192
-
2193
2326
  if (!(formats & extendedClipboardFormatText)) {
2194
2327
  return true;
2195
- } // Ignore what we had in our clipboard client side.
2196
-
2197
-
2198
- this._clipboardText = null; // FIXME: Should probably verify that this data was actually requested
2328
+ }
2329
+ // Ignore what we had in our clipboard client side.
2330
+ this._clipboardText = null;
2199
2331
 
2332
+ // FIXME: Should probably verify that this data was actually requested
2200
2333
  var zlibStream = this._sock.rQshiftBytes(length - 4);
2201
-
2202
- var streamInflator = new _inflator.default();
2334
+ var streamInflator = new _inflator["default"]();
2203
2335
  var textData = null;
2204
2336
  streamInflator.setInput(zlibStream);
2205
-
2206
- for (var _i2 = 0; _i2 <= 15; _i2++) {
2207
- var format = 1 << _i2;
2208
-
2337
+ for (var _i5 = 0; _i5 <= 15; _i5++) {
2338
+ var format = 1 << _i5;
2209
2339
  if (formats & format) {
2210
2340
  var size = 0x00;
2211
2341
  var sizeArray = streamInflator.inflate(4);
@@ -2214,29 +2344,22 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2214
2344
  size |= sizeArray[2] << 8;
2215
2345
  size |= sizeArray[3];
2216
2346
  var chunk = streamInflator.inflate(size);
2217
-
2218
2347
  if (format === extendedClipboardFormatText) {
2219
2348
  textData = chunk;
2220
2349
  }
2221
2350
  }
2222
2351
  }
2223
-
2224
2352
  streamInflator.setInput(null);
2225
-
2226
2353
  if (textData !== null) {
2227
2354
  var tmpText = "";
2228
-
2229
- for (var _i3 = 0; _i3 < textData.length; _i3++) {
2230
- tmpText += String.fromCharCode(textData[_i3]);
2355
+ for (var _i6 = 0; _i6 < textData.length; _i6++) {
2356
+ tmpText += String.fromCharCode(textData[_i6]);
2231
2357
  }
2232
-
2233
2358
  textData = tmpText;
2234
2359
  textData = (0, _strings.decodeUTF8)(textData);
2235
-
2236
2360
  if (textData.length > 0 && "\0" === textData.charAt(textData.length - 1)) {
2237
2361
  textData = textData.slice(0, -1);
2238
2362
  }
2239
-
2240
2363
  textData = textData.replace("\r\n", "\n");
2241
2364
  this.dispatchEvent(new CustomEvent("clipboard", {
2242
2365
  detail: {
@@ -2248,7 +2371,6 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2248
2371
  return this._fail("Unexpected action in extended clipboard message: " + actions);
2249
2372
  }
2250
2373
  }
2251
-
2252
2374
  return true;
2253
2375
  }
2254
2376
  }, {
@@ -2257,26 +2379,19 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2257
2379
  if (this._sock.rQwait("ServerFence header", 8, 1)) {
2258
2380
  return false;
2259
2381
  }
2260
-
2261
2382
  this._sock.rQskipBytes(3); // Padding
2262
-
2263
-
2264
2383
  var flags = this._sock.rQshift32();
2265
-
2266
2384
  var length = this._sock.rQshift8();
2267
-
2268
2385
  if (this._sock.rQwait("ServerFence payload", length, 9)) {
2269
2386
  return false;
2270
2387
  }
2271
-
2272
2388
  if (length > 64) {
2273
2389
  Log.Warn("Bad payload length (" + length + ") in fence response");
2274
2390
  length = 64;
2275
2391
  }
2276
-
2277
2392
  var payload = this._sock.rQshiftStr(length);
2278
-
2279
2393
  this._supportsFence = true;
2394
+
2280
2395
  /*
2281
2396
  * Fence flags
2282
2397
  *
@@ -2288,14 +2403,15 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2288
2403
 
2289
2404
  if (!(flags & 1 << 31)) {
2290
2405
  return this._fail("Unexpected fence response");
2291
- } // Filter out unsupported flags
2292
- // FIXME: support syncNext
2406
+ }
2293
2407
 
2408
+ // Filter out unsupported flags
2409
+ // FIXME: support syncNext
2410
+ flags &= 1 << 0 | 1 << 1;
2294
2411
 
2295
- flags &= 1 << 0 | 1 << 1; // BlockBefore and BlockAfter are automatically handled by
2412
+ // BlockBefore and BlockAfter are automatically handled by
2296
2413
  // the fact that we process each incoming message
2297
2414
  // synchronuosly.
2298
-
2299
2415
  RFB.messages.clientFence(this._sock, flags, payload);
2300
2416
  return true;
2301
2417
  }
@@ -2305,65 +2421,47 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2305
2421
  if (this._sock.rQwait("XVP version and message", 3, 1)) {
2306
2422
  return false;
2307
2423
  }
2308
-
2309
2424
  this._sock.rQskipBytes(1); // Padding
2310
-
2311
-
2312
2425
  var xvpVer = this._sock.rQshift8();
2313
-
2314
2426
  var xvpMsg = this._sock.rQshift8();
2315
-
2316
2427
  switch (xvpMsg) {
2317
2428
  case 0:
2318
2429
  // XVP_FAIL
2319
2430
  Log.Error("XVP Operation Failed");
2320
2431
  break;
2321
-
2322
2432
  case 1:
2323
2433
  // XVP_INIT
2324
2434
  this._rfbXvpVer = xvpVer;
2325
2435
  Log.Info("XVP extensions enabled (version " + this._rfbXvpVer + ")");
2326
-
2327
2436
  this._setCapability("power", true);
2328
-
2329
2437
  break;
2330
-
2331
2438
  default:
2332
2439
  this._fail("Illegal server XVP message (msg: " + xvpMsg + ")");
2333
-
2334
2440
  break;
2335
2441
  }
2336
-
2337
2442
  return true;
2338
2443
  }
2339
2444
  }, {
2340
2445
  key: "_normalMsg",
2341
2446
  value: function _normalMsg() {
2342
2447
  var msgType;
2343
-
2344
2448
  if (this._FBU.rects > 0) {
2345
2449
  msgType = 0;
2346
2450
  } else {
2347
2451
  msgType = this._sock.rQshift8();
2348
2452
  }
2349
-
2350
2453
  var first, ret;
2351
-
2352
2454
  switch (msgType) {
2353
2455
  case 0:
2354
2456
  // FramebufferUpdate
2355
2457
  ret = this._framebufferUpdate();
2356
-
2357
2458
  if (ret && !this._enabledContinuousUpdates) {
2358
2459
  RFB.messages.fbUpdateRequest(this._sock, true, 0, 0, this._fbWidth, this._fbHeight);
2359
2460
  }
2360
-
2361
2461
  return ret;
2362
-
2363
2462
  case 1:
2364
2463
  // SetColorMapEntries
2365
2464
  return this._handleSetColourMapMsg();
2366
-
2367
2465
  case 2:
2368
2466
  // Bell
2369
2467
  Log.Debug("Bell");
@@ -2371,40 +2469,31 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2371
2469
  detail: {}
2372
2470
  }));
2373
2471
  return true;
2374
-
2375
2472
  case 3:
2376
2473
  // ServerCutText
2377
2474
  return this._handleServerCutText();
2378
-
2379
2475
  case 150:
2380
2476
  // EndOfContinuousUpdates
2381
2477
  first = !this._supportsContinuousUpdates;
2382
2478
  this._supportsContinuousUpdates = true;
2383
2479
  this._enabledContinuousUpdates = false;
2384
-
2385
2480
  if (first) {
2386
2481
  this._enabledContinuousUpdates = true;
2387
-
2388
2482
  this._updateContinuousUpdates();
2389
-
2390
2483
  Log.Info("Enabling continuous updates.");
2391
- } else {// FIXME: We need to send a framebufferupdaterequest here
2484
+ } else {
2485
+ // FIXME: We need to send a framebufferupdaterequest here
2392
2486
  // if we add support for turning off continuous updates
2393
2487
  }
2394
-
2395
2488
  return true;
2396
-
2397
2489
  case 248:
2398
2490
  // ServerFence
2399
2491
  return this._handleServerFenceMsg();
2400
-
2401
2492
  case 250:
2402
2493
  // XVP
2403
2494
  return this._handleXvpMsg();
2404
-
2405
2495
  default:
2406
2496
  this._fail("Unexpected server message (type " + msgType + ")");
2407
-
2408
2497
  Log.Debug("sock.rQslice(0, 30): " + this._sock.rQslice(0, 30));
2409
2498
  return true;
2410
2499
  }
@@ -2412,8 +2501,8 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2412
2501
  }, {
2413
2502
  key: "_onFlush",
2414
2503
  value: function _onFlush() {
2415
- this._flushing = false; // Resume processing
2416
-
2504
+ this._flushing = false;
2505
+ // Resume processing
2417
2506
  if (this._sock.rQlen > 0) {
2418
2507
  this._handleMessage();
2419
2508
  }
@@ -2425,22 +2514,17 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2425
2514
  if (this._sock.rQwait("FBU header", 3, 1)) {
2426
2515
  return false;
2427
2516
  }
2428
-
2429
2517
  this._sock.rQskipBytes(1); // Padding
2518
+ this._FBU.rects = this._sock.rQshift16();
2430
2519
 
2431
-
2432
- this._FBU.rects = this._sock.rQshift16(); // Make sure the previous frame is fully rendered first
2520
+ // Make sure the previous frame is fully rendered first
2433
2521
  // to avoid building up an excessive queue
2434
-
2435
2522
  if (this._display.pending()) {
2436
2523
  this._flushing = true;
2437
-
2438
2524
  this._display.flush();
2439
-
2440
2525
  return false;
2441
2526
  }
2442
2527
  }
2443
-
2444
2528
  while (this._FBU.rects > 0) {
2445
2529
  if (this._FBU.encoding === null) {
2446
2530
  if (this._sock.rQwait("rect header", 12)) {
@@ -2448,26 +2532,20 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2448
2532
  }
2449
2533
  /* New FramebufferUpdate */
2450
2534
 
2451
-
2452
2535
  var hdr = this._sock.rQshiftBytes(12);
2453
-
2454
2536
  this._FBU.x = (hdr[0] << 8) + hdr[1];
2455
2537
  this._FBU.y = (hdr[2] << 8) + hdr[3];
2456
2538
  this._FBU.width = (hdr[4] << 8) + hdr[5];
2457
2539
  this._FBU.height = (hdr[6] << 8) + hdr[7];
2458
2540
  this._FBU.encoding = parseInt((hdr[8] << 24) + (hdr[9] << 16) + (hdr[10] << 8) + hdr[11], 10);
2459
2541
  }
2460
-
2461
2542
  if (!this._handleRect()) {
2462
2543
  return false;
2463
2544
  }
2464
-
2465
2545
  this._FBU.rects--;
2466
2546
  this._FBU.encoding = null;
2467
2547
  }
2468
-
2469
2548
  this._display.flip();
2470
-
2471
2549
  return true; // We finished this FBU
2472
2550
  }
2473
2551
  }, {
@@ -2476,39 +2554,21 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2476
2554
  switch (this._FBU.encoding) {
2477
2555
  case _encodings.encodings.pseudoEncodingLastRect:
2478
2556
  this._FBU.rects = 1; // Will be decreased when we return
2479
-
2480
2557
  return true;
2481
-
2482
2558
  case _encodings.encodings.pseudoEncodingVMwareCursor:
2483
2559
  return this._handleVMwareCursor();
2484
-
2485
2560
  case _encodings.encodings.pseudoEncodingCursor:
2486
2561
  return this._handleCursor();
2487
-
2488
2562
  case _encodings.encodings.pseudoEncodingQEMUExtendedKeyEvent:
2489
- // Old Safari doesn't support creating keyboard events
2490
- try {
2491
- var keyboardEvent = document.createEvent("keyboardEvent");
2492
-
2493
- if (keyboardEvent.code !== undefined) {
2494
- this._qemuExtKeyEventSupported = true;
2495
- }
2496
- } catch (err) {// Do nothing
2497
- }
2498
-
2563
+ this._qemuExtKeyEventSupported = true;
2499
2564
  return true;
2500
-
2501
2565
  case _encodings.encodings.pseudoEncodingDesktopName:
2502
2566
  return this._handleDesktopName();
2503
-
2504
2567
  case _encodings.encodings.pseudoEncodingDesktopSize:
2505
2568
  this._resize(this._FBU.width, this._FBU.height);
2506
-
2507
2569
  return true;
2508
-
2509
2570
  case _encodings.encodings.pseudoEncodingExtendedDesktopSize:
2510
2571
  return this._handleExtendedDesktopSize();
2511
-
2512
2572
  default:
2513
2573
  return this._handleDataRect();
2514
2574
  }
@@ -2517,46 +2577,35 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2517
2577
  key: "_handleVMwareCursor",
2518
2578
  value: function _handleVMwareCursor() {
2519
2579
  var hotx = this._FBU.x; // hotspot-x
2520
-
2521
2580
  var hoty = this._FBU.y; // hotspot-y
2522
-
2523
2581
  var w = this._FBU.width;
2524
2582
  var h = this._FBU.height;
2525
-
2526
2583
  if (this._sock.rQwait("VMware cursor encoding", 1)) {
2527
2584
  return false;
2528
2585
  }
2529
-
2530
2586
  var cursorType = this._sock.rQshift8();
2531
-
2532
2587
  this._sock.rQshift8(); //Padding
2533
2588
 
2534
-
2535
2589
  var rgba;
2536
- var bytesPerPixel = 4; //Classic cursor
2590
+ var bytesPerPixel = 4;
2537
2591
 
2592
+ //Classic cursor
2538
2593
  if (cursorType == 0) {
2539
2594
  //Used to filter away unimportant bits.
2540
2595
  //OR is used for correct conversion in js.
2541
2596
  var PIXEL_MASK = 0xffffff00 | 0;
2542
2597
  rgba = new Array(w * h * bytesPerPixel);
2543
-
2544
2598
  if (this._sock.rQwait("VMware cursor classic encoding", w * h * bytesPerPixel * 2, 2)) {
2545
2599
  return false;
2546
2600
  }
2547
-
2548
2601
  var andMask = new Array(w * h);
2549
-
2550
2602
  for (var pixel = 0; pixel < w * h; pixel++) {
2551
2603
  andMask[pixel] = this._sock.rQshift32();
2552
2604
  }
2553
-
2554
2605
  var xorMask = new Array(w * h);
2555
-
2556
2606
  for (var _pixel = 0; _pixel < w * h; _pixel++) {
2557
2607
  xorMask[_pixel] = this._sock.rQshift32();
2558
2608
  }
2559
-
2560
2609
  for (var _pixel2 = 0; _pixel2 < w * h; _pixel2++) {
2561
2610
  if (andMask[_pixel2] == 0) {
2562
2611
  //Fully opaque pixel
@@ -2565,11 +2614,8 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2565
2614
  var g = bgr >> 16 & 0xff;
2566
2615
  var b = bgr >> 24 & 0xff;
2567
2616
  rgba[_pixel2 * bytesPerPixel] = r; //r
2568
-
2569
2617
  rgba[_pixel2 * bytesPerPixel + 1] = g; //g
2570
-
2571
2618
  rgba[_pixel2 * bytesPerPixel + 2] = b; //b
2572
-
2573
2619
  rgba[_pixel2 * bytesPerPixel + 3] = 0xff; //a
2574
2620
  } else if ((andMask[_pixel2] & PIXEL_MASK) == PIXEL_MASK) {
2575
2621
  //Only screen value matters, no mouse colouring
@@ -2600,60 +2646,47 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2600
2646
  rgba[_pixel2 * bytesPerPixel + 2] = 0x00;
2601
2647
  rgba[_pixel2 * bytesPerPixel + 3] = 0xff;
2602
2648
  }
2603
- } //Alpha cursor.
2649
+ }
2604
2650
 
2651
+ //Alpha cursor.
2605
2652
  } else if (cursorType == 1) {
2606
2653
  if (this._sock.rQwait("VMware cursor alpha encoding", w * h * 4, 2)) {
2607
2654
  return false;
2608
2655
  }
2609
-
2610
2656
  rgba = new Array(w * h * bytesPerPixel);
2611
-
2612
2657
  for (var _pixel3 = 0; _pixel3 < w * h; _pixel3++) {
2613
2658
  var data = this._sock.rQshift32();
2614
-
2615
2659
  rgba[_pixel3 * 4] = data >> 24 & 0xff; //r
2616
-
2617
2660
  rgba[_pixel3 * 4 + 1] = data >> 16 & 0xff; //g
2618
-
2619
2661
  rgba[_pixel3 * 4 + 2] = data >> 8 & 0xff; //b
2620
-
2621
2662
  rgba[_pixel3 * 4 + 3] = data & 0xff; //a
2622
2663
  }
2623
2664
  } else {
2624
2665
  Log.Warn("The given cursor type is not supported: " + cursorType + " given.");
2625
2666
  return false;
2626
2667
  }
2627
-
2628
2668
  this._updateCursor(rgba, hotx, hoty, w, h);
2629
-
2630
2669
  return true;
2631
2670
  }
2632
2671
  }, {
2633
2672
  key: "_handleCursor",
2634
2673
  value: function _handleCursor() {
2635
2674
  var hotx = this._FBU.x; // hotspot-x
2636
-
2637
2675
  var hoty = this._FBU.y; // hotspot-y
2638
-
2639
2676
  var w = this._FBU.width;
2640
2677
  var h = this._FBU.height;
2641
2678
  var pixelslength = w * h * 4;
2642
2679
  var masklength = Math.ceil(w / 8) * h;
2643
2680
  var bytes = pixelslength + masklength;
2644
-
2645
2681
  if (this._sock.rQwait("cursor encoding", bytes)) {
2646
2682
  return false;
2647
- } // Decode from BGRX pixels + bit mask to RGBA
2648
-
2683
+ }
2649
2684
 
2685
+ // Decode from BGRX pixels + bit mask to RGBA
2650
2686
  var pixels = this._sock.rQshiftBytes(pixelslength);
2651
-
2652
2687
  var mask = this._sock.rQshiftBytes(masklength);
2653
-
2654
2688
  var rgba = new Uint8Array(w * h * 4);
2655
2689
  var pixIdx = 0;
2656
-
2657
2690
  for (var y = 0; y < h; y++) {
2658
2691
  for (var x = 0; x < w; x++) {
2659
2692
  var maskIdx = y * Math.ceil(w / 8) + Math.floor(x / 8);
@@ -2665,9 +2698,7 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2665
2698
  pixIdx += 4;
2666
2699
  }
2667
2700
  }
2668
-
2669
2701
  this._updateCursor(rgba, hotx, hoty, w, h);
2670
-
2671
2702
  return true;
2672
2703
  }
2673
2704
  }, {
@@ -2676,19 +2707,13 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2676
2707
  if (this._sock.rQwait("DesktopName", 4)) {
2677
2708
  return false;
2678
2709
  }
2679
-
2680
2710
  var length = this._sock.rQshift32();
2681
-
2682
2711
  if (this._sock.rQwait("DesktopName", length, 4)) {
2683
2712
  return false;
2684
2713
  }
2685
-
2686
2714
  var name = this._sock.rQshiftStr(length);
2687
-
2688
2715
  name = (0, _strings.decodeUTF8)(name, true);
2689
-
2690
2716
  this._setDesktopName(name);
2691
-
2692
2717
  return true;
2693
2718
  }
2694
2719
  }, {
@@ -2697,53 +2722,38 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2697
2722
  if (this._sock.rQwait("ExtendedDesktopSize", 4)) {
2698
2723
  return false;
2699
2724
  }
2700
-
2701
2725
  var numberOfScreens = this._sock.rQpeek8();
2702
-
2703
2726
  var bytes = 4 + numberOfScreens * 16;
2704
-
2705
2727
  if (this._sock.rQwait("ExtendedDesktopSize", bytes)) {
2706
2728
  return false;
2707
2729
  }
2708
-
2709
2730
  var firstUpdate = !this._supportsSetDesktopSize;
2710
- this._supportsSetDesktopSize = true; // Normally we only apply the current resize mode after a
2731
+ this._supportsSetDesktopSize = true;
2732
+
2733
+ // Normally we only apply the current resize mode after a
2711
2734
  // window resize event. However there is no such trigger on the
2712
2735
  // initial connect. And we don't know if the server supports
2713
2736
  // resizing until we've gotten here.
2714
-
2715
2737
  if (firstUpdate) {
2716
2738
  this._requestRemoteResize();
2717
2739
  }
2718
-
2719
2740
  this._sock.rQskipBytes(1); // number-of-screens
2720
-
2721
-
2722
2741
  this._sock.rQskipBytes(3); // padding
2723
2742
 
2724
-
2725
2743
  for (var i = 0; i < numberOfScreens; i += 1) {
2726
2744
  // Save the id and flags of the first screen
2727
2745
  if (i === 0) {
2728
2746
  this._screenID = this._sock.rQshiftBytes(4); // id
2729
-
2730
2747
  this._sock.rQskipBytes(2); // x-position
2731
-
2732
-
2733
2748
  this._sock.rQskipBytes(2); // y-position
2734
-
2735
-
2736
2749
  this._sock.rQskipBytes(2); // width
2737
-
2738
-
2739
2750
  this._sock.rQskipBytes(2); // height
2740
-
2741
-
2742
2751
  this._screenFlags = this._sock.rQshiftBytes(4); // flags
2743
2752
  } else {
2744
2753
  this._sock.rQskipBytes(16);
2745
2754
  }
2746
2755
  }
2756
+
2747
2757
  /*
2748
2758
  * The x-position indicates the reason for the change:
2749
2759
  *
@@ -2751,53 +2761,43 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2751
2761
  * 1 - this client requested the resize
2752
2762
  * 2 - another client requested the resize
2753
2763
  */
2754
- // We need to handle errors when we requested the resize.
2755
-
2756
2764
 
2765
+ // We need to handle errors when we requested the resize.
2757
2766
  if (this._FBU.x === 1 && this._FBU.y !== 0) {
2758
- var msg = ""; // The y-position indicates the status code from the server
2759
-
2767
+ var msg = "";
2768
+ // The y-position indicates the status code from the server
2760
2769
  switch (this._FBU.y) {
2761
2770
  case 1:
2762
2771
  msg = "Resize is administratively prohibited";
2763
2772
  break;
2764
-
2765
2773
  case 2:
2766
2774
  msg = "Out of resources";
2767
2775
  break;
2768
-
2769
2776
  case 3:
2770
2777
  msg = "Invalid screen layout";
2771
2778
  break;
2772
-
2773
2779
  default:
2774
2780
  msg = "Unknown reason";
2775
2781
  break;
2776
2782
  }
2777
-
2778
2783
  Log.Warn("Server did not accept the resize request: " + msg);
2779
2784
  } else {
2780
2785
  this._resize(this._FBU.width, this._FBU.height);
2781
2786
  }
2782
-
2783
2787
  return true;
2784
2788
  }
2785
2789
  }, {
2786
2790
  key: "_handleDataRect",
2787
2791
  value: function _handleDataRect() {
2788
2792
  var decoder = this._decoders[this._FBU.encoding];
2789
-
2790
2793
  if (!decoder) {
2791
2794
  this._fail("Unsupported encoding (encoding: " + this._FBU.encoding + ")");
2792
-
2793
2795
  return false;
2794
2796
  }
2795
-
2796
2797
  try {
2797
2798
  return decoder.decodeRect(this._FBU.x, this._FBU.y, this._FBU.width, this._FBU.height, this._sock, this._display, this._fbDepth);
2798
2799
  } catch (err) {
2799
2800
  this._fail("Error decoding rect: " + err);
2800
-
2801
2801
  return false;
2802
2802
  }
2803
2803
  }
@@ -2807,7 +2807,6 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2807
2807
  if (!this._enabledContinuousUpdates) {
2808
2808
  return;
2809
2809
  }
2810
-
2811
2810
  RFB.messages.enableContinuousUpdates(this._sock, true, 0, 0, this._fbWidth, this._fbHeight);
2812
2811
  }
2813
2812
  }, {
@@ -2815,15 +2814,15 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2815
2814
  value: function _resize(width, height) {
2816
2815
  this._fbWidth = width;
2817
2816
  this._fbHeight = height;
2817
+ this._display.resize(this._fbWidth, this._fbHeight);
2818
2818
 
2819
- this._display.resize(this._fbWidth, this._fbHeight); // Adjust the visible viewport based on the new dimensions
2820
-
2821
-
2819
+ // Adjust the visible viewport based on the new dimensions
2822
2820
  this._updateClip();
2823
-
2824
2821
  this._updateScale();
2825
-
2826
2822
  this._updateContinuousUpdates();
2823
+
2824
+ // Keep this size until browser client size changes
2825
+ this._saveExpectedClientSize();
2827
2826
  }
2828
2827
  }, {
2829
2828
  key: "_xvpOp",
@@ -2831,7 +2830,6 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2831
2830
  if (this._rfbXvpVer < ver) {
2832
2831
  return;
2833
2832
  }
2834
-
2835
2833
  Log.Info("Sending XVP operation " + op + " (version " + ver + ")");
2836
2834
  RFB.messages.xvpOp(this._sock, ver, op);
2837
2835
  }
@@ -2845,7 +2843,6 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2845
2843
  w: w,
2846
2844
  h: h
2847
2845
  };
2848
-
2849
2846
  this._refreshCursor();
2850
2847
  }
2851
2848
  }, {
@@ -2855,20 +2852,20 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2855
2852
  if (!this._showDotCursor) {
2856
2853
  // User does not want to see the dot, so...
2857
2854
  return false;
2858
- } // The dot should not be shown if the cursor is already visible,
2855
+ }
2856
+
2857
+ // The dot should not be shown if the cursor is already visible,
2859
2858
  // i.e. contains at least one not-fully-transparent pixel.
2860
2859
  // So iterate through all alpha bytes in rgba and stop at the
2861
2860
  // first non-zero.
2862
-
2863
-
2864
2861
  for (var i = 3; i < this._cursorImage.rgbaPixels.length; i += 4) {
2865
2862
  if (this._cursorImage.rgbaPixels[i]) {
2866
2863
  return false;
2867
2864
  }
2868
- } // At this point, we know that the cursor is fully transparent, and
2869
- // the user wants to see the dot instead of this.
2870
-
2865
+ }
2871
2866
 
2867
+ // At this point, we know that the cursor is fully transparent, and
2868
+ // the user wants to see the dot instead of this.
2872
2869
  return true;
2873
2870
  }
2874
2871
  }, {
@@ -2877,162 +2874,26 @@ var RFB = /*#__PURE__*/function (_EventTargetMixin) {
2877
2874
  if (this._rfbConnectionState !== "connecting" && this._rfbConnectionState !== "connected") {
2878
2875
  return;
2879
2876
  }
2880
-
2881
2877
  var image = this._shouldShowDotCursor() ? RFB.cursors.dot : this._cursorImage;
2882
-
2883
2878
  this._cursor.change(image.rgbaPixels, image.hotx, image.hoty, image.w, image.h);
2884
2879
  }
2885
- }, {
2886
- key: "viewOnly",
2887
- get: function get() {
2888
- return this._viewOnly;
2889
- },
2890
- set: function set(viewOnly) {
2891
- this._viewOnly = viewOnly;
2892
-
2893
- if (this._rfbConnectionState === "connecting" || this._rfbConnectionState === "connected") {
2894
- if (viewOnly) {
2895
- this._keyboard.ungrab();
2896
- } else {
2897
- this._keyboard.grab();
2898
- }
2899
- }
2900
- }
2901
- }, {
2902
- key: "capabilities",
2903
- get: function get() {
2904
- return this._capabilities;
2905
- }
2906
- }, {
2907
- key: "touchButton",
2908
- get: function get() {
2909
- return 0;
2910
- },
2911
- set: function set(button) {
2912
- Log.Warn("Using old API!");
2913
- }
2914
- }, {
2915
- key: "clipViewport",
2916
- get: function get() {
2917
- return this._clipViewport;
2918
- },
2919
- set: function set(viewport) {
2920
- this._clipViewport = viewport;
2921
-
2922
- this._updateClip();
2923
- }
2924
- }, {
2925
- key: "scaleViewport",
2926
- get: function get() {
2927
- return this._scaleViewport;
2928
- },
2929
- set: function set(scale) {
2930
- this._scaleViewport = scale; // Scaling trumps clipping, so we may need to adjust
2931
- // clipping when enabling or disabling scaling
2932
-
2933
- if (scale && this._clipViewport) {
2934
- this._updateClip();
2935
- }
2936
-
2937
- this._updateScale();
2938
-
2939
- if (!scale && this._clipViewport) {
2940
- this._updateClip();
2941
- }
2942
- }
2943
- }, {
2944
- key: "resizeSession",
2945
- get: function get() {
2946
- return this._resizeSession;
2947
- },
2948
- set: function set(resize) {
2949
- this._resizeSession = resize;
2950
-
2951
- if (resize) {
2952
- this._requestRemoteResize();
2953
- }
2954
- }
2955
- }, {
2956
- key: "showDotCursor",
2957
- get: function get() {
2958
- return this._showDotCursor;
2959
- },
2960
- set: function set(show) {
2961
- this._showDotCursor = show;
2962
-
2963
- this._refreshCursor();
2964
- }
2965
- }, {
2966
- key: "background",
2967
- get: function get() {
2968
- return this._screen.style.background;
2969
- },
2970
- set: function set(cssValue) {
2971
- this._screen.style.background = cssValue;
2972
- }
2973
- }, {
2974
- key: "qualityLevel",
2975
- get: function get() {
2976
- return this._qualityLevel;
2977
- },
2978
- set: function set(qualityLevel) {
2979
- if (!Number.isInteger(qualityLevel) || qualityLevel < 0 || qualityLevel > 9) {
2980
- Log.Error("qualityLevel must be an integer between 0 and 9");
2981
- return;
2982
- }
2983
-
2984
- if (this._qualityLevel === qualityLevel) {
2985
- return;
2986
- }
2987
-
2988
- this._qualityLevel = qualityLevel;
2989
-
2990
- if (this._rfbConnectionState === 'connected') {
2991
- this._sendEncodings();
2992
- }
2993
- }
2994
- }, {
2995
- key: "compressionLevel",
2996
- get: function get() {
2997
- return this._compressionLevel;
2998
- },
2999
- set: function set(compressionLevel) {
3000
- if (!Number.isInteger(compressionLevel) || compressionLevel < 0 || compressionLevel > 9) {
3001
- Log.Error("compressionLevel must be an integer between 0 and 9");
3002
- return;
3003
- }
3004
-
3005
- if (this._compressionLevel === compressionLevel) {
3006
- return;
3007
- }
3008
-
3009
- this._compressionLevel = compressionLevel;
3010
-
3011
- if (this._rfbConnectionState === 'connected') {
3012
- this._sendEncodings();
3013
- }
3014
- }
3015
2880
  }], [{
3016
2881
  key: "genDES",
3017
2882
  value: function genDES(password, challenge) {
3018
2883
  var passwordChars = password.split('').map(function (c) {
3019
2884
  return c.charCodeAt(0);
3020
2885
  });
3021
- return new _des.default(passwordChars).encrypt(challenge);
2886
+ return new _des["default"](passwordChars).encrypt(challenge);
3022
2887
  }
3023
2888
  }]);
3024
-
3025
2889
  return RFB;
3026
- }(_eventtarget.default); // Class Methods
3027
-
3028
-
3029
- exports.default = RFB;
2890
+ }(_eventtarget["default"]); // Class Methods
2891
+ exports["default"] = RFB;
3030
2892
  RFB.messages = {
3031
2893
  keyEvent: function keyEvent(sock, keysym, down) {
3032
2894
  var buff = sock._sQ;
3033
2895
  var offset = sock._sQlen;
3034
2896
  buff[offset] = 4; // msg-type
3035
-
3036
2897
  buff[offset + 1] = down;
3037
2898
  buff[offset + 2] = 0;
3038
2899
  buff[offset + 3] = 0;
@@ -3047,18 +2908,14 @@ RFB.messages = {
3047
2908
  function getRFBkeycode(xtScanCode) {
3048
2909
  var upperByte = keycode >> 8;
3049
2910
  var lowerByte = keycode & 0x00ff;
3050
-
3051
2911
  if (upperByte === 0xe0 && lowerByte < 0x7f) {
3052
2912
  return lowerByte | 0x80;
3053
2913
  }
3054
-
3055
2914
  return xtScanCode;
3056
2915
  }
3057
-
3058
2916
  var buff = sock._sQ;
3059
2917
  var offset = sock._sQlen;
3060
2918
  buff[offset] = 255; // msg-type
3061
-
3062
2919
  buff[offset + 1] = 0; // sub msg-type
3063
2920
 
3064
2921
  buff[offset + 2] = down >> 8;
@@ -3093,49 +2950,42 @@ RFB.messages = {
3093
2950
  var data = new Uint8Array(4);
3094
2951
  var formatFlag = 0x00000000;
3095
2952
  var actionFlag = 0x00000000;
3096
-
3097
2953
  for (var i = 0; i < actions.length; i++) {
3098
2954
  actionFlag |= actions[i];
3099
2955
  }
3100
-
3101
- for (var _i4 = 0; _i4 < formats.length; _i4++) {
3102
- formatFlag |= formats[_i4];
2956
+ for (var _i7 = 0; _i7 < formats.length; _i7++) {
2957
+ formatFlag |= formats[_i7];
3103
2958
  }
3104
-
3105
2959
  data[0] = actionFlag >> 24; // Actions
3106
-
3107
2960
  data[1] = 0x00; // Reserved
3108
-
3109
2961
  data[2] = 0x00; // Reserved
3110
-
3111
2962
  data[3] = formatFlag; // Formats
3112
2963
 
3113
2964
  return data;
3114
2965
  },
3115
2966
  extendedClipboardProvide: function extendedClipboardProvide(sock, formats, inData) {
3116
2967
  // Deflate incomming data and their sizes
3117
- var deflator = new _deflator.default();
2968
+ var deflator = new _deflator["default"]();
3118
2969
  var dataToDeflate = [];
3119
-
3120
2970
  for (var i = 0; i < formats.length; i++) {
3121
2971
  // We only support the format Text at this time
3122
2972
  if (formats[i] != extendedClipboardFormatText) {
3123
2973
  throw new Error("Unsupported extended clipboard format for Provide message.");
3124
- } // Change lone \r or \n into \r\n as defined in rfbproto
3125
-
2974
+ }
3126
2975
 
3127
- inData[i] = inData[i].replace(/\r\n|\r|\n/gm, "\r\n"); // Check if it already has \0
2976
+ // Change lone \r or \n into \r\n as defined in rfbproto
2977
+ inData[i] = inData[i].replace(/\r\n|\r|\n/gm, "\r\n");
3128
2978
 
2979
+ // Check if it already has \0
3129
2980
  var text = (0, _strings.encodeUTF8)(inData[i] + "\0");
3130
2981
  dataToDeflate.push(text.length >> 24 & 0xFF, text.length >> 16 & 0xFF, text.length >> 8 & 0xFF, text.length & 0xFF);
3131
-
3132
2982
  for (var j = 0; j < text.length; j++) {
3133
2983
  dataToDeflate.push(text.charCodeAt(j));
3134
2984
  }
3135
2985
  }
2986
+ var deflatedData = deflator.deflate(new Uint8Array(dataToDeflate));
3136
2987
 
3137
- var deflatedData = deflator.deflate(new Uint8Array(dataToDeflate)); // Build data to send
3138
-
2988
+ // Build data to send
3139
2989
  var data = new Uint8Array(4 + deflatedData.length);
3140
2990
  data.set(RFB.messages._buildExtendedClipboardFlags([extendedClipboardActionProvide], formats));
3141
2991
  data.set(deflatedData, 4);
@@ -3143,12 +2993,10 @@ RFB.messages = {
3143
2993
  },
3144
2994
  extendedClipboardNotify: function extendedClipboardNotify(sock, formats) {
3145
2995
  var flags = RFB.messages._buildExtendedClipboardFlags([extendedClipboardActionNotify], formats);
3146
-
3147
2996
  RFB.messages.clientCutText(sock, flags, true);
3148
2997
  },
3149
2998
  extendedClipboardRequest: function extendedClipboardRequest(sock, formats) {
3150
2999
  var flags = RFB.messages._buildExtendedClipboardFlags([extendedClipboardActionRequest], formats);
3151
-
3152
3000
  RFB.messages.clientCutText(sock, flags, true);
3153
3001
  },
3154
3002
  extendedClipboardCaps: function extendedClipboardCaps(sock, actions, formats) {
@@ -3162,7 +3010,6 @@ RFB.messages = {
3162
3010
  });
3163
3011
  data.set(RFB.messages._buildExtendedClipboardFlags(actions, []));
3164
3012
  var loopOffset = 4;
3165
-
3166
3013
  for (var i = 0; i < formatKeys.length; i++) {
3167
3014
  data[loopOffset] = formats[formatKeys[i]] >> 24;
3168
3015
  data[loopOffset + 1] = formats[formatKeys[i]] >> 16;
@@ -3181,36 +3028,30 @@ RFB.messages = {
3181
3028
  buff[offset] = 6; // msg-type
3182
3029
 
3183
3030
  buff[offset + 1] = 0; // padding
3184
-
3185
3031
  buff[offset + 2] = 0; // padding
3186
-
3187
3032
  buff[offset + 3] = 0; // padding
3188
3033
 
3189
3034
  var length;
3190
-
3191
3035
  if (extended) {
3192
3036
  length = (0, _int.toUnsigned32bit)(-data.length);
3193
3037
  } else {
3194
3038
  length = data.length;
3195
3039
  }
3196
-
3197
3040
  buff[offset + 4] = length >> 24;
3198
3041
  buff[offset + 5] = length >> 16;
3199
3042
  buff[offset + 6] = length >> 8;
3200
3043
  buff[offset + 7] = length;
3201
- sock._sQlen += 8; // We have to keep track of from where in the data we begin creating the
3202
- // buffer for the flush in the next iteration.
3044
+ sock._sQlen += 8;
3203
3045
 
3046
+ // We have to keep track of from where in the data we begin creating the
3047
+ // buffer for the flush in the next iteration.
3204
3048
  var dataOffset = 0;
3205
3049
  var remaining = data.length;
3206
-
3207
3050
  while (remaining > 0) {
3208
3051
  var flushSize = Math.min(remaining, sock._sQbufferSize - sock._sQlen);
3209
-
3210
3052
  for (var i = 0; i < flushSize; i++) {
3211
3053
  buff[sock._sQlen + i] = data[dataOffset + i];
3212
3054
  }
3213
-
3214
3055
  sock._sQlen += flushSize;
3215
3056
  sock.flush();
3216
3057
  remaining -= flushSize;
@@ -3221,39 +3062,28 @@ RFB.messages = {
3221
3062
  var buff = sock._sQ;
3222
3063
  var offset = sock._sQlen;
3223
3064
  buff[offset] = 251; // msg-type
3224
-
3225
3065
  buff[offset + 1] = 0; // padding
3226
-
3227
3066
  buff[offset + 2] = width >> 8; // width
3228
-
3229
3067
  buff[offset + 3] = width;
3230
3068
  buff[offset + 4] = height >> 8; // height
3231
-
3232
3069
  buff[offset + 5] = height;
3233
3070
  buff[offset + 6] = 1; // number-of-screens
3234
-
3235
3071
  buff[offset + 7] = 0; // padding
3236
- // screen array
3237
3072
 
3073
+ // screen array
3238
3074
  buff[offset + 8] = id >> 24; // id
3239
-
3240
3075
  buff[offset + 9] = id >> 16;
3241
3076
  buff[offset + 10] = id >> 8;
3242
3077
  buff[offset + 11] = id;
3243
3078
  buff[offset + 12] = 0; // x-position
3244
-
3245
3079
  buff[offset + 13] = 0;
3246
3080
  buff[offset + 14] = 0; // y-position
3247
-
3248
3081
  buff[offset + 15] = 0;
3249
3082
  buff[offset + 16] = width >> 8; // width
3250
-
3251
3083
  buff[offset + 17] = width;
3252
3084
  buff[offset + 18] = height >> 8; // height
3253
-
3254
3085
  buff[offset + 19] = height;
3255
3086
  buff[offset + 20] = flags >> 24; // flags
3256
-
3257
3087
  buff[offset + 21] = flags >> 16;
3258
3088
  buff[offset + 22] = flags >> 8;
3259
3089
  buff[offset + 23] = flags;
@@ -3266,13 +3096,10 @@ RFB.messages = {
3266
3096
  buff[offset] = 248; // msg-type
3267
3097
 
3268
3098
  buff[offset + 1] = 0; // padding
3269
-
3270
3099
  buff[offset + 2] = 0; // padding
3271
-
3272
3100
  buff[offset + 3] = 0; // padding
3273
3101
 
3274
3102
  buff[offset + 4] = flags >> 24; // flags
3275
-
3276
3103
  buff[offset + 5] = flags >> 16;
3277
3104
  buff[offset + 6] = flags >> 8;
3278
3105
  buff[offset + 7] = flags;
@@ -3282,7 +3109,6 @@ RFB.messages = {
3282
3109
  for (var i = 0; i < n; i++) {
3283
3110
  buff[offset + 9 + i] = payload.charCodeAt(i);
3284
3111
  }
3285
-
3286
3112
  sock._sQlen += 9 + n;
3287
3113
  sock.flush();
3288
3114
  },
@@ -3290,20 +3116,15 @@ RFB.messages = {
3290
3116
  var buff = sock._sQ;
3291
3117
  var offset = sock._sQlen;
3292
3118
  buff[offset] = 150; // msg-type
3293
-
3294
3119
  buff[offset + 1] = enable; // enable-flag
3295
3120
 
3296
3121
  buff[offset + 2] = x >> 8; // x
3297
-
3298
3122
  buff[offset + 3] = x;
3299
3123
  buff[offset + 4] = y >> 8; // y
3300
-
3301
3124
  buff[offset + 5] = y;
3302
3125
  buff[offset + 6] = width >> 8; // width
3303
-
3304
3126
  buff[offset + 7] = width;
3305
3127
  buff[offset + 8] = height >> 8; // height
3306
-
3307
3128
  buff[offset + 9] = height;
3308
3129
  sock._sQlen += 10;
3309
3130
  sock.flush();
@@ -3312,7 +3133,6 @@ RFB.messages = {
3312
3133
  var buff = sock._sQ;
3313
3134
  var offset = sock._sQlen;
3314
3135
  var bpp;
3315
-
3316
3136
  if (depth > 16) {
3317
3137
  bpp = 32;
3318
3138
  } else if (depth > 8) {
@@ -3320,46 +3140,33 @@ RFB.messages = {
3320
3140
  } else {
3321
3141
  bpp = 8;
3322
3142
  }
3323
-
3324
3143
  var bits = Math.floor(depth / 3);
3325
3144
  buff[offset] = 0; // msg-type
3326
3145
 
3327
3146
  buff[offset + 1] = 0; // padding
3328
-
3329
3147
  buff[offset + 2] = 0; // padding
3330
-
3331
3148
  buff[offset + 3] = 0; // padding
3332
3149
 
3333
3150
  buff[offset + 4] = bpp; // bits-per-pixel
3334
-
3335
3151
  buff[offset + 5] = depth; // depth
3336
-
3337
3152
  buff[offset + 6] = 0; // little-endian
3338
-
3339
3153
  buff[offset + 7] = trueColor ? 1 : 0; // true-color
3340
3154
 
3341
3155
  buff[offset + 8] = 0; // red-max
3342
-
3343
3156
  buff[offset + 9] = (1 << bits) - 1; // red-max
3344
3157
 
3345
3158
  buff[offset + 10] = 0; // green-max
3346
-
3347
3159
  buff[offset + 11] = (1 << bits) - 1; // green-max
3348
3160
 
3349
3161
  buff[offset + 12] = 0; // blue-max
3350
-
3351
3162
  buff[offset + 13] = (1 << bits) - 1; // blue-max
3352
3163
 
3353
- buff[offset + 14] = bits * 2; // red-shift
3354
-
3164
+ buff[offset + 14] = bits * 0; // red-shift
3355
3165
  buff[offset + 15] = bits * 1; // green-shift
3356
-
3357
- buff[offset + 16] = bits * 0; // blue-shift
3166
+ buff[offset + 16] = bits * 2; // blue-shift
3358
3167
 
3359
3168
  buff[offset + 17] = 0; // padding
3360
-
3361
3169
  buff[offset + 18] = 0; // padding
3362
-
3363
3170
  buff[offset + 19] = 0; // padding
3364
3171
 
3365
3172
  sock._sQlen += 20;
@@ -3369,13 +3176,11 @@ RFB.messages = {
3369
3176
  var buff = sock._sQ;
3370
3177
  var offset = sock._sQlen;
3371
3178
  buff[offset] = 2; // msg-type
3372
-
3373
3179
  buff[offset + 1] = 0; // padding
3374
3180
 
3375
3181
  buff[offset + 2] = encodings.length >> 8;
3376
3182
  buff[offset + 3] = encodings.length;
3377
3183
  var j = offset + 4;
3378
-
3379
3184
  for (var i = 0; i < encodings.length; i++) {
3380
3185
  var enc = encodings[i];
3381
3186
  buff[j] = enc >> 24;
@@ -3384,24 +3189,19 @@ RFB.messages = {
3384
3189
  buff[j + 3] = enc;
3385
3190
  j += 4;
3386
3191
  }
3387
-
3388
3192
  sock._sQlen += j - offset;
3389
3193
  sock.flush();
3390
3194
  },
3391
3195
  fbUpdateRequest: function fbUpdateRequest(sock, incremental, x, y, w, h) {
3392
3196
  var buff = sock._sQ;
3393
3197
  var offset = sock._sQlen;
3394
-
3395
3198
  if (typeof x === "undefined") {
3396
3199
  x = 0;
3397
3200
  }
3398
-
3399
3201
  if (typeof y === "undefined") {
3400
3202
  y = 0;
3401
3203
  }
3402
-
3403
3204
  buff[offset] = 3; // msg-type
3404
-
3405
3205
  buff[offset + 1] = incremental ? 1 : 0;
3406
3206
  buff[offset + 2] = x >> 8 & 0xFF;
3407
3207
  buff[offset + 3] = x & 0xFF;
@@ -3418,7 +3218,6 @@ RFB.messages = {
3418
3218
  var buff = sock._sQ;
3419
3219
  var offset = sock._sQlen;
3420
3220
  buff[offset] = 250; // msg-type
3421
-
3422
3221
  buff[offset + 1] = 0; // padding
3423
3222
 
3424
3223
  buff[offset + 2] = ver;
@@ -3438,7 +3237,6 @@ RFB.cursors = {
3438
3237
  dot: {
3439
3238
  /* eslint-disable indent */
3440
3239
  rgbaPixels: new Uint8Array([255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255]),
3441
-
3442
3240
  /* eslint-enable indent */
3443
3241
  w: 3,
3444
3242
  h: 3,