@novnc/novnc 1.3.0 → 1.4.0-beta

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 (64) hide show
  1. package/AUTHORS +2 -2
  2. package/LICENSE.txt +1 -1
  3. package/README.md +23 -7
  4. package/core/decoders/jpeg.js +141 -0
  5. package/core/decoders/raw.js +1 -1
  6. package/core/decoders/zrle.js +185 -0
  7. package/core/des.js +1 -1
  8. package/core/display.js +12 -0
  9. package/core/encodings.js +4 -0
  10. package/core/input/keyboard.js +10 -0
  11. package/core/ra2.js +567 -0
  12. package/core/rfb.js +469 -84
  13. package/core/util/browser.js +56 -7
  14. package/core/util/cursor.js +4 -0
  15. package/core/util/md5.js +79 -0
  16. package/docs/API.md +318 -157
  17. package/lib/base64.js +20 -34
  18. package/lib/decoders/copyrect.js +5 -12
  19. package/lib/decoders/hextile.js +17 -47
  20. package/lib/decoders/jpeg.js +149 -0
  21. package/lib/decoders/raw.js +10 -23
  22. package/lib/decoders/rre.js +5 -16
  23. package/lib/decoders/tight.js +13 -79
  24. package/lib/decoders/tightpng.js +8 -28
  25. package/lib/decoders/zrle.js +188 -0
  26. package/lib/deflator.js +9 -23
  27. package/lib/des.js +24 -37
  28. package/lib/display.js +62 -108
  29. package/lib/encodings.js +7 -8
  30. package/lib/inflator.js +6 -19
  31. package/lib/input/domkeytable.js +77 -48
  32. package/lib/input/fixedkeys.js +8 -3
  33. package/lib/input/gesturehandler.js +86 -153
  34. package/lib/input/keyboard.js +62 -91
  35. package/lib/input/keysym.js +14 -270
  36. package/lib/input/keysymdef.js +5 -7
  37. package/lib/input/util.js +43 -85
  38. package/lib/input/vkeys.js +0 -3
  39. package/lib/input/xtscancodes.js +1 -168
  40. package/lib/ra2.js +1005 -0
  41. package/lib/rfb.js +795 -923
  42. package/lib/util/browser.js +66 -29
  43. package/lib/util/cursor.js +29 -66
  44. package/lib/util/element.js +3 -5
  45. package/lib/util/events.js +23 -30
  46. package/lib/util/eventtarget.js +5 -14
  47. package/lib/util/int.js +1 -2
  48. package/lib/util/logging.js +1 -19
  49. package/lib/util/md5.js +77 -0
  50. package/lib/util/strings.js +3 -5
  51. package/lib/vendor/pako/lib/utils/common.js +8 -17
  52. package/lib/vendor/pako/lib/zlib/adler32.js +3 -7
  53. package/lib/vendor/pako/lib/zlib/constants.js +2 -5
  54. package/lib/vendor/pako/lib/zlib/crc32.js +5 -12
  55. package/lib/vendor/pako/lib/zlib/deflate.js +213 -618
  56. package/lib/vendor/pako/lib/zlib/gzheader.js +1 -13
  57. package/lib/vendor/pako/lib/zlib/inffast.js +60 -176
  58. package/lib/vendor/pako/lib/zlib/inflate.js +398 -888
  59. package/lib/vendor/pako/lib/zlib/inftrees.js +63 -169
  60. package/lib/vendor/pako/lib/zlib/messages.js +1 -11
  61. package/lib/vendor/pako/lib/zlib/trees.js +246 -588
  62. package/lib/vendor/pako/lib/zlib/zstream.js +2 -18
  63. package/lib/websock.js +37 -88
  64. package/package.json +32 -35
@@ -1,59 +1,47 @@
1
1
  "use strict";
2
2
 
3
- 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); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports["default"] = void 0;
9
-
10
7
  var Log = _interopRequireWildcard(require("../util/logging.js"));
11
-
12
8
  var _events = require("../util/events.js");
13
-
14
9
  var KeyboardUtil = _interopRequireWildcard(require("./util.js"));
15
-
16
10
  var _keysym = _interopRequireDefault(require("./keysym.js"));
17
-
18
11
  var browser = _interopRequireWildcard(require("../util/browser.js"));
19
-
20
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
-
22
13
  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); }
23
-
24
14
  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; }
25
-
15
+ 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); }
26
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
-
28
- 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); } }
29
-
30
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31
-
17
+ 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, _toPropertyKey(descriptor.key), descriptor); } }
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
32
21
  //
33
22
  // Keyboard event handler
34
23
  //
35
24
  var Keyboard = /*#__PURE__*/function () {
36
25
  function Keyboard(target) {
37
26
  _classCallCheck(this, Keyboard);
38
-
39
27
  this._target = target || null;
40
28
  this._keyDownList = {}; // List of depressed keys
41
29
  // (even if they are happy)
42
-
43
30
  this._altGrArmed = false; // Windows AltGr detection
44
- // keep these here so we can refer to them later
45
31
 
32
+ // keep these here so we can refer to them later
46
33
  this._eventHandlers = {
47
34
  'keyup': this._handleKeyUp.bind(this),
48
35
  'keydown': this._handleKeyDown.bind(this),
49
36
  'blur': this._allKeysUp.bind(this)
50
- }; // ===== EVENT HANDLERS =====
51
-
52
- this.onkeyevent = function () {}; // Handler for key press/release
37
+ };
53
38
 
54
- } // ===== PRIVATE METHODS =====
39
+ // ===== EVENT HANDLERS =====
55
40
 
41
+ this.onkeyevent = function () {}; // Handler for key press/release
42
+ }
56
43
 
44
+ // ===== PRIVATE METHODS =====
57
45
  _createClass(Keyboard, [{
58
46
  key: "_sendKeyEvent",
59
47
  value: function _sendKeyEvent(keysym, code, down) {
@@ -64,10 +52,8 @@ var Keyboard = /*#__PURE__*/function () {
64
52
  if (!(code in this._keyDownList)) {
65
53
  return;
66
54
  }
67
-
68
55
  delete this._keyDownList[code];
69
56
  }
70
-
71
57
  Log.Debug("onkeyevent " + (down ? "down" : "up") + ", keysym: " + keysym, ", code: " + code);
72
58
  this.onkeyevent(keysym, code, down);
73
59
  }
@@ -75,51 +61,45 @@ var Keyboard = /*#__PURE__*/function () {
75
61
  key: "_getKeyCode",
76
62
  value: function _getKeyCode(e) {
77
63
  var code = KeyboardUtil.getKeycode(e);
78
-
79
64
  if (code !== 'Unidentified') {
80
65
  return code;
81
- } // Unstable, but we don't have anything else to go on
82
-
66
+ }
83
67
 
68
+ // Unstable, but we don't have anything else to go on
84
69
  if (e.keyCode) {
85
70
  // 229 is used for composition events
86
71
  if (e.keyCode !== 229) {
87
72
  return 'Platform' + e.keyCode;
88
73
  }
89
- } // A precursor to the final DOM3 standard. Unfortunately it
90
- // is not layout independent, so it is as bad as using keyCode
91
-
74
+ }
92
75
 
76
+ // A precursor to the final DOM3 standard. Unfortunately it
77
+ // is not layout independent, so it is as bad as using keyCode
93
78
  if (e.keyIdentifier) {
94
79
  // Non-character key?
95
80
  if (e.keyIdentifier.substr(0, 2) !== 'U+') {
96
81
  return e.keyIdentifier;
97
82
  }
98
-
99
83
  var codepoint = parseInt(e.keyIdentifier.substr(2), 16);
100
-
101
84
  var _char = String.fromCharCode(codepoint).toUpperCase();
102
-
103
85
  return 'Platform' + _char.charCodeAt();
104
86
  }
105
-
106
87
  return 'Unidentified';
107
88
  }
108
89
  }, {
109
90
  key: "_handleKeyDown",
110
91
  value: function _handleKeyDown(e) {
111
92
  var code = this._getKeyCode(e);
93
+ var keysym = KeyboardUtil.getKeysym(e);
112
94
 
113
- var keysym = KeyboardUtil.getKeysym(e); // Windows doesn't have a proper AltGr, but handles it using
95
+ // Windows doesn't have a proper AltGr, but handles it using
114
96
  // fake Ctrl+Alt. However the remote end might not be Windows,
115
97
  // so we need to merge those in to a single AltGr event. We
116
98
  // detect this case by seeing the two key events directly after
117
99
  // each other with a very short time between them (<50ms).
118
-
119
100
  if (this._altGrArmed) {
120
101
  this._altGrArmed = false;
121
102
  clearTimeout(this._altGrTimeout);
122
-
123
103
  if (code === "AltRight" && e.timeStamp - this._altGrCtrlTime < 50) {
124
104
  // FIXME: We fail to detect this if either Ctrl key is
125
105
  // first manually pressed as Windows then no
@@ -132,126 +112,118 @@ var Keyboard = /*#__PURE__*/function () {
132
112
  } else {
133
113
  this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
134
114
  }
135
- } // We cannot handle keys we cannot track, but we also need
136
- // to deal with virtual keyboards which omit key info
137
-
115
+ }
138
116
 
117
+ // We cannot handle keys we cannot track, but we also need
118
+ // to deal with virtual keyboards which omit key info
139
119
  if (code === 'Unidentified') {
140
120
  if (keysym) {
141
121
  // If it's a virtual keyboard then it should be
142
122
  // sufficient to just send press and release right
143
123
  // after each other
144
124
  this._sendKeyEvent(keysym, code, true);
145
-
146
125
  this._sendKeyEvent(keysym, code, false);
147
126
  }
148
-
149
127
  (0, _events.stopEvent)(e);
150
128
  return;
151
- } // Alt behaves more like AltGraph on macOS, so shuffle the
129
+ }
130
+
131
+ // Alt behaves more like AltGraph on macOS, so shuffle the
152
132
  // keys around a bit to make things more sane for the remote
153
133
  // server. This method is used by RealVNC and TigerVNC (and
154
134
  // possibly others).
155
-
156
-
157
135
  if (browser.isMac() || browser.isIOS()) {
158
136
  switch (keysym) {
159
137
  case _keysym["default"].XK_Super_L:
160
138
  keysym = _keysym["default"].XK_Alt_L;
161
139
  break;
162
-
163
140
  case _keysym["default"].XK_Super_R:
164
141
  keysym = _keysym["default"].XK_Super_L;
165
142
  break;
166
-
167
143
  case _keysym["default"].XK_Alt_L:
168
144
  keysym = _keysym["default"].XK_Mode_switch;
169
145
  break;
170
-
171
146
  case _keysym["default"].XK_Alt_R:
172
147
  keysym = _keysym["default"].XK_ISO_Level3_Shift;
173
148
  break;
174
149
  }
175
- } // Is this key already pressed? If so, then we must use the
176
- // same keysym or we'll confuse the server
177
-
150
+ }
178
151
 
152
+ // Is this key already pressed? If so, then we must use the
153
+ // same keysym or we'll confuse the server
179
154
  if (code in this._keyDownList) {
180
155
  keysym = this._keyDownList[code];
181
- } // macOS doesn't send proper key events for modifiers, only
156
+ }
157
+
158
+ // macOS doesn't send proper key releases if a key is pressed
159
+ // while meta is held down
160
+ if ((browser.isMac() || browser.isIOS()) && e.metaKey && code !== 'MetaLeft' && code !== 'MetaRight') {
161
+ this._sendKeyEvent(keysym, code, true);
162
+ this._sendKeyEvent(keysym, code, false);
163
+ (0, _events.stopEvent)(e);
164
+ return;
165
+ }
166
+
167
+ // macOS doesn't send proper key events for modifiers, only
182
168
  // state change events. That gets extra confusing for CapsLock
183
169
  // which toggles on each press, but not on release. So pretend
184
170
  // it was a quick press and release of the button.
185
-
186
-
187
171
  if ((browser.isMac() || browser.isIOS()) && code === 'CapsLock') {
188
172
  this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', true);
189
-
190
173
  this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', false);
191
-
192
174
  (0, _events.stopEvent)(e);
193
175
  return;
194
- } // Windows doesn't send proper key releases for a bunch of
195
- // Japanese IM keys so we have to fake the release right away
196
-
176
+ }
197
177
 
178
+ // Windows doesn't send proper key releases for a bunch of
179
+ // Japanese IM keys so we have to fake the release right away
198
180
  var jpBadKeys = [_keysym["default"].XK_Zenkaku_Hankaku, _keysym["default"].XK_Eisu_toggle, _keysym["default"].XK_Katakana, _keysym["default"].XK_Hiragana, _keysym["default"].XK_Romaji];
199
-
200
181
  if (browser.isWindows() && jpBadKeys.includes(keysym)) {
201
182
  this._sendKeyEvent(keysym, code, true);
202
-
203
183
  this._sendKeyEvent(keysym, code, false);
204
-
205
184
  (0, _events.stopEvent)(e);
206
185
  return;
207
186
  }
187
+ (0, _events.stopEvent)(e);
208
188
 
209
- (0, _events.stopEvent)(e); // Possible start of AltGr sequence? (see above)
210
-
189
+ // Possible start of AltGr sequence? (see above)
211
190
  if (code === "ControlLeft" && browser.isWindows() && !("ControlLeft" in this._keyDownList)) {
212
191
  this._altGrArmed = true;
213
192
  this._altGrTimeout = setTimeout(this._handleAltGrTimeout.bind(this), 100);
214
193
  this._altGrCtrlTime = e.timeStamp;
215
194
  return;
216
195
  }
217
-
218
196
  this._sendKeyEvent(keysym, code, true);
219
197
  }
220
198
  }, {
221
199
  key: "_handleKeyUp",
222
200
  value: function _handleKeyUp(e) {
223
201
  (0, _events.stopEvent)(e);
202
+ var code = this._getKeyCode(e);
224
203
 
225
- var code = this._getKeyCode(e); // We can't get a release in the middle of an AltGr sequence, so
204
+ // We can't get a release in the middle of an AltGr sequence, so
226
205
  // abort that detection
227
-
228
-
229
206
  if (this._altGrArmed) {
230
207
  this._altGrArmed = false;
231
208
  clearTimeout(this._altGrTimeout);
232
-
233
209
  this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
234
- } // See comment in _handleKeyDown()
235
-
210
+ }
236
211
 
212
+ // See comment in _handleKeyDown()
237
213
  if ((browser.isMac() || browser.isIOS()) && code === 'CapsLock') {
238
214
  this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', true);
239
-
240
215
  this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', false);
241
-
242
216
  return;
243
217
  }
218
+ this._sendKeyEvent(this._keyDownList[code], code, false);
244
219
 
245
- this._sendKeyEvent(this._keyDownList[code], code, false); // Windows has a rather nasty bug where it won't send key
220
+ // Windows has a rather nasty bug where it won't send key
246
221
  // release events for a Shift button if the other Shift is still
247
222
  // pressed
248
-
249
-
250
223
  if (browser.isWindows() && (code === 'ShiftLeft' || code === 'ShiftRight')) {
251
224
  if ('ShiftRight' in this._keyDownList) {
252
225
  this._sendKeyEvent(this._keyDownList['ShiftRight'], 'ShiftRight', false);
253
226
  }
254
-
255
227
  if ('ShiftLeft' in this._keyDownList) {
256
228
  this._sendKeyEvent(this._keyDownList['ShiftLeft'], 'ShiftLeft', false);
257
229
  }
@@ -262,48 +234,47 @@ var Keyboard = /*#__PURE__*/function () {
262
234
  value: function _handleAltGrTimeout() {
263
235
  this._altGrArmed = false;
264
236
  clearTimeout(this._altGrTimeout);
265
-
266
237
  this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
267
238
  }
268
239
  }, {
269
240
  key: "_allKeysUp",
270
241
  value: function _allKeysUp() {
271
242
  Log.Debug(">> Keyboard.allKeysUp");
272
-
273
243
  for (var code in this._keyDownList) {
274
244
  this._sendKeyEvent(this._keyDownList[code], code, false);
275
245
  }
276
-
277
246
  Log.Debug("<< Keyboard.allKeysUp");
278
- } // ===== PUBLIC METHODS =====
247
+ }
279
248
 
249
+ // ===== PUBLIC METHODS =====
280
250
  }, {
281
251
  key: "grab",
282
252
  value: function grab() {
283
253
  //Log.Debug(">> Keyboard.grab");
284
- this._target.addEventListener('keydown', this._eventHandlers.keydown);
285
254
 
286
- this._target.addEventListener('keyup', this._eventHandlers.keyup); // Release (key up) if window loses focus
255
+ this._target.addEventListener('keydown', this._eventHandlers.keydown);
256
+ this._target.addEventListener('keyup', this._eventHandlers.keyup);
287
257
 
258
+ // Release (key up) if window loses focus
259
+ window.addEventListener('blur', this._eventHandlers.blur);
288
260
 
289
- window.addEventListener('blur', this._eventHandlers.blur); //Log.Debug("<< Keyboard.grab");
261
+ //Log.Debug("<< Keyboard.grab");
290
262
  }
291
263
  }, {
292
264
  key: "ungrab",
293
265
  value: function ungrab() {
294
266
  //Log.Debug(">> Keyboard.ungrab");
295
- this._target.removeEventListener('keydown', this._eventHandlers.keydown);
296
267
 
268
+ this._target.removeEventListener('keydown', this._eventHandlers.keydown);
297
269
  this._target.removeEventListener('keyup', this._eventHandlers.keyup);
270
+ window.removeEventListener('blur', this._eventHandlers.blur);
298
271
 
299
- window.removeEventListener('blur', this._eventHandlers.blur); // Release (key up) all keys that are in a down state
300
-
301
- this._allKeysUp(); //Log.Debug(">> Keyboard.ungrab");
272
+ // Release (key up) all keys that are in a down state
273
+ this._allKeysUp();
302
274
 
275
+ //Log.Debug(">> Keyboard.ungrab");
303
276
  }
304
277
  }]);
305
-
306
278
  return Keyboard;
307
279
  }();
308
-
309
280
  exports["default"] = Keyboard;