cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
1,344 lines • 97.3 kB
JavaScript
import { getDefaultExportFromCjs } from "../../../../_virtual/_commonjsHelpers.mjs";
import { __exports as rfb } from "../../../../_virtual/rfb.mjs";
import "./util/int.mjs";
import "./util/logging.mjs";
import "./util/strings.mjs";
import "./util/browser.mjs";
import "./util/element.mjs";
import "./util/events.mjs";
import "./util/eventtarget.mjs";
import "./display.mjs";
import "./inflator.mjs";
import "./deflator.mjs";
import "./input/keyboard.mjs";
import "./input/gesturehandler.mjs";
import "./util/cursor.mjs";
import "./websock.mjs";
import "./des.mjs";
import "./input/keysym.mjs";
import "./input/xtscancodes.mjs";
import "./encodings.mjs";
import "./decoders/raw.mjs";
import "./decoders/copyrect.mjs";
import "./decoders/rre.mjs";
import "./decoders/hextile.mjs";
import "./decoders/tight.mjs";
import "./decoders/tightpng.mjs";
import { __exports as int } from "../../../../_virtual/int.mjs";
import { __exports as logging } from "../../../../_virtual/logging.mjs";
import { __exports as strings } from "../../../../_virtual/strings.mjs";
import { __exports as eventtarget } from "../../../../_virtual/eventtarget.mjs";
import { __exports as display } from "../../../../_virtual/display.mjs";
import { __exports as inflator } from "../../../../_virtual/inflator.mjs";
import { __exports as deflator } from "../../../../_virtual/deflator.mjs";
import { __exports as keyboard } from "../../../../_virtual/keyboard.mjs";
import { __exports as gesturehandler } from "../../../../_virtual/gesturehandler.mjs";
import { __exports as cursor } from "../../../../_virtual/cursor.mjs";
import { __exports as websock } from "../../../../_virtual/websock.mjs";
import { __exports as des } from "../../../../_virtual/des.mjs";
import { __exports as keysym } from "../../../../_virtual/keysym.mjs";
import { __exports as xtscancodes } from "../../../../_virtual/xtscancodes.mjs";
import { __exports as raw } from "../../../../_virtual/raw.mjs";
import { __exports as copyrect } from "../../../../_virtual/copyrect.mjs";
import { __exports as rre } from "../../../../_virtual/rre.mjs";
import { __exports as hextile } from "../../../../_virtual/hextile.mjs";
import { __exports as tight } from "../../../../_virtual/tight.mjs";
import { __exports as tightpng } from "../../../../_virtual/tightpng.mjs";
import { __exports as browser } from "../../../../_virtual/browser.mjs";
import { __exports as element } from "../../../../_virtual/element.mjs";
import { __exports as events } from "../../../../_virtual/events.mjs";
import { __exports as encodings } from "../../../../_virtual/encodings.mjs";
(function(exports) {
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function _typeof2(obj2) {
return typeof obj2;
};
} else {
_typeof = function _typeof2(obj2) {
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
};
}
return _typeof(obj);
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _int = int;
var Log = _interopRequireWildcard(logging);
var _strings = strings;
var _browser = browser;
var _element = element;
var _events = events;
var _eventtarget = _interopRequireDefault(eventtarget);
var _display = _interopRequireDefault(display);
var _inflator = _interopRequireDefault(inflator);
var _deflator = _interopRequireDefault(deflator);
var _keyboard = _interopRequireDefault(keyboard);
var _gesturehandler = _interopRequireDefault(gesturehandler);
var _cursor = _interopRequireDefault(cursor);
var _websock = _interopRequireDefault(websock);
var _des = _interopRequireDefault(des);
var _keysym = _interopRequireDefault(keysym);
var _xtscancodes = _interopRequireDefault(xtscancodes);
var _encodings = encodings;
var _raw = _interopRequireDefault(raw);
var _copyrect = _interopRequireDefault(copyrect);
var _rre = _interopRequireDefault(rre);
var _hextile = _interopRequireDefault(hextile);
var _tight = _interopRequireDefault(tight);
var _tightpng = _interopRequireDefault(tightpng);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { "default": obj };
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function")
return null;
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
return (_getRequireWildcardCache = function _getRequireWildcardCache2(nodeInterop2) {
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
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;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
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);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps)
_defineProperties(Constructor.prototype, protoProps);
if (staticProps)
_defineProperties(Constructor, staticProps);
return Constructor;
}
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);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
o2.__proto__ = p2;
return o2;
};
return _setPrototypeOf(o, p);
}
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);
};
}
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);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
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;
}
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
return o2.__proto__ || Object.getPrototypeOf(o2);
};
return _getPrototypeOf(o);
}
var DISCONNECT_TIMEOUT = 3;
var DEFAULT_BACKGROUND = "rgb(40, 40, 40)";
var MOUSE_MOVE_DELAY = 17;
var WHEEL_STEP = 50;
var WHEEL_LINE_HEIGHT = 19;
var GESTURE_ZOOMSENS = 75;
var GESTURE_SCRLSENS = 50;
var DOUBLE_TAP_TIMEOUT = 1e3;
var DOUBLE_TAP_THRESHOLD = 50;
var extendedClipboardFormatText = 1;
var extendedClipboardActionCaps = 1 << 24;
var extendedClipboardActionRequest = 1 << 25;
var extendedClipboardActionPeek = 1 << 26;
var extendedClipboardActionNotify = 1 << 27;
var extendedClipboardActionProvide = 1 << 28;
var RFB2 = /* @__PURE__ */ function(_EventTargetMixin) {
_inherits(RFB3, _EventTargetMixin);
var _super = _createSuper(RFB3);
function RFB3(target, urlOrChannel, options) {
var _this;
_classCallCheck(this, RFB3);
if (!target) {
throw new Error("Must specify target");
}
if (!urlOrChannel) {
throw new Error("Must specify URL, WebSocket or RTCDataChannel");
}
_this = _super.call(this);
_this._target = target;
if (typeof urlOrChannel === "string") {
_this._url = urlOrChannel;
} else {
_this._url = null;
_this._rawChannel = urlOrChannel;
}
options = options || {};
_this._rfbCredentials = options.credentials || {};
_this._shared = "shared" in options ? !!options.shared : true;
_this._repeaterID = options.repeaterID || "";
_this._wsProtocols = options.wsProtocols || [];
_this._rfbConnectionState = "";
_this._rfbInitState = "";
_this._rfbAuthScheme = -1;
_this._rfbCleanDisconnect = true;
_this._rfbVersion = 0;
_this._rfbMaxVersion = 3.8;
_this._rfbTightVNC = false;
_this._rfbVeNCryptState = 0;
_this._rfbXvpVer = 0;
_this._fbWidth = 0;
_this._fbHeight = 0;
_this._fbName = "";
_this._capabilities = {
power: false
};
_this._supportsFence = false;
_this._supportsContinuousUpdates = false;
_this._enabledContinuousUpdates = false;
_this._supportsSetDesktopSize = false;
_this._screenID = 0;
_this._screenFlags = 0;
_this._qemuExtKeyEventSupported = false;
_this._clipboardText = null;
_this._clipboardServerCapabilitiesActions = {};
_this._clipboardServerCapabilitiesFormats = {};
_this._sock = null;
_this._display = null;
_this._flushing = false;
_this._keyboard = null;
_this._gestures = null;
_this._resizeObserver = null;
_this._disconnTimer = null;
_this._resizeTimeout = null;
_this._mouseMoveTimer = null;
_this._decoders = {};
_this._FBU = {
rects: 0,
x: 0,
y: 0,
width: 0,
height: 0,
encoding: null
};
_this._mousePos = {};
_this._mouseButtonMask = 0;
_this._mouseLastMoveTime = 0;
_this._viewportDragging = false;
_this._viewportDragPos = {};
_this._viewportHasMoved = false;
_this._accumulatedWheelDeltaX = 0;
_this._accumulatedWheelDeltaY = 0;
_this._gestureLastTapTime = null;
_this._gestureFirstDoubleTapEv = null;
_this._gestureLastMagnitudeX = 0;
_this._gestureLastMagnitudeY = 0;
_this._eventHandlers = {
focusCanvas: _this._focusCanvas.bind(_assertThisInitialized(_this)),
handleResize: _this._handleResize.bind(_assertThisInitialized(_this)),
handleMouse: _this._handleMouse.bind(_assertThisInitialized(_this)),
handleWheel: _this._handleWheel.bind(_assertThisInitialized(_this)),
handleGesture: _this._handleGesture.bind(_assertThisInitialized(_this))
};
Log.Debug(">> RFB.constructor");
_this._screen = document.createElement("div");
_this._screen.style.display = "flex";
_this._screen.style.width = "100%";
_this._screen.style.height = "100%";
_this._screen.style.overflow = "auto";
_this._screen.style.background = DEFAULT_BACKGROUND;
_this._canvas = document.createElement("canvas");
_this._canvas.style.margin = "auto";
_this._canvas.style.outline = "none";
_this._canvas.width = 0;
_this._canvas.height = 0;
_this._canvas.tabIndex = -1;
_this._screen.appendChild(_this._canvas);
_this._cursor = new _cursor["default"]();
_this._cursorImage = RFB3.cursors.none;
_this._decoders[_encodings.encodings.encodingRaw] = new _raw["default"]();
_this._decoders[_encodings.encodings.encodingCopyRect] = new _copyrect["default"]();
_this._decoders[_encodings.encodings.encodingRRE] = new _rre["default"]();
_this._decoders[_encodings.encodings.encodingHextile] = new _hextile["default"]();
_this._decoders[_encodings.encodings.encodingTight] = new _tight["default"]();
_this._decoders[_encodings.encodings.encodingTightPNG] = new _tightpng["default"]();
try {
_this._display = new _display["default"](_this._canvas);
} catch (exc) {
Log.Error("Display exception: " + exc);
throw exc;
}
_this._display.onflush = _this._onFlush.bind(_assertThisInitialized(_this));
_this._keyboard = new _keyboard["default"](_this._canvas);
_this._keyboard.onkeyevent = _this._handleKeyEvent.bind(_assertThisInitialized(_this));
_this._gestures = new _gesturehandler["default"]();
_this._sock = new _websock["default"]();
_this._sock.on("open", _this._socketOpen.bind(_assertThisInitialized(_this)));
_this._sock.on("close", _this._socketClose.bind(_assertThisInitialized(_this)));
_this._sock.on("message", _this._handleMessage.bind(_assertThisInitialized(_this)));
_this._sock.on("error", _this._socketError.bind(_assertThisInitialized(_this)));
_this._resizeObserver = new ResizeObserver(_this._eventHandlers.handleResize);
_this._updateConnectionState("connecting");
Log.Debug("<< RFB.constructor");
_this.dragViewport = false;
_this.focusOnClick = true;
_this._viewOnly = false;
_this._clipViewport = false;
_this._scaleViewport = false;
_this._resizeSession = false;
_this._showDotCursor = false;
if (options.showDotCursor !== void 0) {
Log.Warn("Specifying showDotCursor as a RFB constructor argument is deprecated");
_this._showDotCursor = options.showDotCursor;
}
_this._qualityLevel = 6;
_this._compressionLevel = 2;
return _this;
}
_createClass(RFB3, [{
key: "viewOnly",
get: function get() {
return this._viewOnly;
},
set: function set(viewOnly) {
this._viewOnly = viewOnly;
if (this._rfbConnectionState === "connecting" || this._rfbConnectionState === "connected") {
if (viewOnly) {
this._keyboard.ungrab();
} else {
this._keyboard.grab();
}
}
}
}, {
key: "capabilities",
get: function get() {
return this._capabilities;
}
}, {
key: "touchButton",
get: function get() {
return 0;
},
set: function set(button) {
Log.Warn("Using old API!");
}
}, {
key: "clipViewport",
get: function get() {
return this._clipViewport;
},
set: function set(viewport) {
this._clipViewport = viewport;
this._updateClip();
}
}, {
key: "scaleViewport",
get: function get() {
return this._scaleViewport;
},
set: function set(scale) {
this._scaleViewport = scale;
if (scale && this._clipViewport) {
this._updateClip();
}
this._updateScale();
if (!scale && this._clipViewport) {
this._updateClip();
}
}
}, {
key: "resizeSession",
get: function get() {
return this._resizeSession;
},
set: function set(resize) {
this._resizeSession = resize;
if (resize) {
this._requestRemoteResize();
}
}
}, {
key: "showDotCursor",
get: function get() {
return this._showDotCursor;
},
set: function set(show) {
this._showDotCursor = show;
this._refreshCursor();
}
}, {
key: "background",
get: function get() {
return this._screen.style.background;
},
set: function set(cssValue) {
this._screen.style.background = cssValue;
}
}, {
key: "qualityLevel",
get: function get() {
return this._qualityLevel;
},
set: function set(qualityLevel) {
if (!Number.isInteger(qualityLevel) || qualityLevel < 0 || qualityLevel > 9) {
Log.Error("qualityLevel must be an integer between 0 and 9");
return;
}
if (this._qualityLevel === qualityLevel) {
return;
}
this._qualityLevel = qualityLevel;
if (this._rfbConnectionState === "connected") {
this._sendEncodings();
}
}
}, {
key: "compressionLevel",
get: function get() {
return this._compressionLevel;
},
set: function set(compressionLevel) {
if (!Number.isInteger(compressionLevel) || compressionLevel < 0 || compressionLevel > 9) {
Log.Error("compressionLevel must be an integer between 0 and 9");
return;
}
if (this._compressionLevel === compressionLevel) {
return;
}
this._compressionLevel = compressionLevel;
if (this._rfbConnectionState === "connected") {
this._sendEncodings();
}
}
}, {
key: "disconnect",
value: function disconnect() {
this._updateConnectionState("disconnecting");
this._sock.off("error");
this._sock.off("message");
this._sock.off("open");
}
}, {
key: "sendCredentials",
value: function sendCredentials(creds) {
this._rfbCredentials = creds;
setTimeout(this._initMsg.bind(this), 0);
}
}, {
key: "sendCtrlAltDel",
value: function sendCtrlAltDel() {
if (this._rfbConnectionState !== "connected" || this._viewOnly) {
return;
}
Log.Info("Sending Ctrl-Alt-Del");
this.sendKey(_keysym["default"].XK_Control_L, "ControlLeft", true);
this.sendKey(_keysym["default"].XK_Alt_L, "AltLeft", true);
this.sendKey(_keysym["default"].XK_Delete, "Delete", true);
this.sendKey(_keysym["default"].XK_Delete, "Delete", false);
this.sendKey(_keysym["default"].XK_Alt_L, "AltLeft", false);
this.sendKey(_keysym["default"].XK_Control_L, "ControlLeft", false);
}
}, {
key: "machineShutdown",
value: function machineShutdown() {
this._xvpOp(1, 2);
}
}, {
key: "machineReboot",
value: function machineReboot() {
this._xvpOp(1, 3);
}
}, {
key: "machineReset",
value: function machineReset() {
this._xvpOp(1, 4);
}
}, {
key: "sendKey",
value: function sendKey(keysym2, code, down) {
if (this._rfbConnectionState !== "connected" || this._viewOnly) {
return;
}
if (down === void 0) {
this.sendKey(keysym2, code, true);
this.sendKey(keysym2, code, false);
return;
}
var scancode = _xtscancodes["default"][code];
if (this._qemuExtKeyEventSupported && scancode) {
keysym2 = keysym2 || 0;
Log.Info("Sending key (" + (down ? "down" : "up") + "): keysym " + keysym2 + ", scancode " + scancode);
RFB3.messages.QEMUExtendedKeyEvent(this._sock, keysym2, down, scancode);
} else {
if (!keysym2) {
return;
}
Log.Info("Sending keysym (" + (down ? "down" : "up") + "): " + keysym2);
RFB3.messages.keyEvent(this._sock, keysym2, down ? 1 : 0);
}
}
}, {
key: "focus",
value: function focus() {
this._canvas.focus();
}
}, {
key: "blur",
value: function blur() {
this._canvas.blur();
}
}, {
key: "clipboardPasteFrom",
value: function clipboardPasteFrom(text) {
if (this._rfbConnectionState !== "connected" || this._viewOnly) {
return;
}
if (this._clipboardServerCapabilitiesFormats[extendedClipboardFormatText] && this._clipboardServerCapabilitiesActions[extendedClipboardActionNotify]) {
this._clipboardText = text;
RFB3.messages.extendedClipboardNotify(this._sock, [extendedClipboardFormatText]);
} else {
var data = new Uint8Array(text.length);
for (var i = 0; i < text.length; i++) {
data[i] = text.charCodeAt(i);
}
RFB3.messages.clientCutText(this._sock, data);
}
}
}, {
key: "_connect",
value: function _connect() {
Log.Debug(">> RFB.connect");
if (this._url) {
Log.Info("connecting to ".concat(this._url));
this._sock.open(this._url, this._wsProtocols);
} else {
Log.Info("attaching ".concat(this._rawChannel, " to Websock"));
this._sock.attach(this._rawChannel);
if (this._sock.readyState === "closed") {
throw Error("Cannot use already closed WebSocket/RTCDataChannel");
}
if (this._sock.readyState === "open") {
this._socketOpen();
}
}
this._target.appendChild(this._screen);
this._gestures.attach(this._canvas);
this._cursor.attach(this._canvas);
this._refreshCursor();
this._resizeObserver.observe(this._screen);
this._canvas.addEventListener("mousedown", this._eventHandlers.focusCanvas);
this._canvas.addEventListener("touchstart", this._eventHandlers.focusCanvas);
this._canvas.addEventListener("mousedown", this._eventHandlers.handleMouse);
this._canvas.addEventListener("mouseup", this._eventHandlers.handleMouse);
this._canvas.addEventListener("mousemove", this._eventHandlers.handleMouse);
this._canvas.addEventListener("click", this._eventHandlers.handleMouse);
this._canvas.addEventListener("contextmenu", this._eventHandlers.handleMouse);
this._canvas.addEventListener("wheel", this._eventHandlers.handleWheel);
this._canvas.addEventListener("gesturestart", this._eventHandlers.handleGesture);
this._canvas.addEventListener("gesturemove", this._eventHandlers.handleGesture);
this._canvas.addEventListener("gestureend", this._eventHandlers.handleGesture);
Log.Debug("<< RFB.connect");
}
}, {
key: "_disconnect",
value: function _disconnect() {
Log.Debug(">> RFB.disconnect");
this._cursor.detach();
this._canvas.removeEventListener("gesturestart", this._eventHandlers.handleGesture);
this._canvas.removeEventListener("gesturemove", this._eventHandlers.handleGesture);
this._canvas.removeEventListener("gestureend", this._eventHandlers.handleGesture);
this._canvas.removeEventListener("wheel", this._eventHandlers.handleWheel);
this._canvas.removeEventListener("mousedown", this._eventHandlers.handleMouse);
this._canvas.removeEventListener("mouseup", this._eventHandlers.handleMouse);
this._canvas.removeEventListener("mousemove", this._eventHandlers.handleMouse);
this._canvas.removeEventListener("click", this._eventHandlers.handleMouse);
this._canvas.removeEventListener("contextmenu", this._eventHandlers.handleMouse);
this._canvas.removeEventListener("mousedown", this._eventHandlers.focusCanvas);
this._canvas.removeEventListener("touchstart", this._eventHandlers.focusCanvas);
this._resizeObserver.disconnect();
this._keyboard.ungrab();
this._gestures.detach();
this._sock.close();
try {
this._target.removeChild(this._screen);
} catch (e) {
if (e.name === "NotFoundError")
;
else {
throw e;
}
}
clearTimeout(this._resizeTimeout);
clearTimeout(this._mouseMoveTimer);
Log.Debug("<< RFB.disconnect");
}
}, {
key: "_socketOpen",
value: function _socketOpen() {
if (this._rfbConnectionState === "connecting" && this._rfbInitState === "") {
this._rfbInitState = "ProtocolVersion";
Log.Debug("Starting VNC handshake");
} else {
this._fail("Unexpected server connection while " + this._rfbConnectionState);
}
}
}, {
key: "_socketClose",
value: function _socketClose(e) {
Log.Debug("WebSocket on-close event");
var msg = "";
if (e.code) {
msg = "(code: " + e.code;
if (e.reason) {
msg += ", reason: " + e.reason;
}
msg += ")";
}
switch (this._rfbConnectionState) {
case "connecting":
this._fail("Connection closed " + msg);
break;
case "connected":
this._updateConnectionState("disconnecting");
this._updateConnectionState("disconnected");
break;
case "disconnecting":
this._updateConnectionState("disconnected");
break;
case "disconnected":
this._fail("Unexpected server disconnect when already disconnected " + msg);
break;
default:
this._fail("Unexpected server disconnect before connecting " + msg);
break;
}
this._sock.off("close");
this._rawChannel = null;
}
}, {
key: "_socketError",
value: function _socketError(e) {
Log.Warn("WebSocket on-error event");
}
}, {
key: "_focusCanvas",
value: function _focusCanvas(event) {
if (!this.focusOnClick) {
return;
}
this.focus();
}
}, {
key: "_setDesktopName",
value: function _setDesktopName(name) {
this._fbName = name;
this.dispatchEvent(new CustomEvent("desktopname", {
detail: {
name: this._fbName
}
}));
}
}, {
key: "_handleResize",
value: function _handleResize() {
var _this2 = this;
window.requestAnimationFrame(function() {
_this2._updateClip();
_this2._updateScale();
});
if (this._resizeSession) {
clearTimeout(this._resizeTimeout);
this._resizeTimeout = setTimeout(this._requestRemoteResize.bind(this), 500);
}
}
}, {
key: "_updateClip",
value: function _updateClip() {
var curClip = this._display.clipViewport;
var newClip = this._clipViewport;
if (this._scaleViewport) {
newClip = false;
}
if (curClip !== newClip) {
this._display.clipViewport = newClip;
}
if (newClip) {
var size = this._screenSize();
this._display.viewportChangeSize(size.w, size.h);
this._fixScrollbars();
}
}
}, {
key: "_updateScale",
value: function _updateScale() {
if (!this._scaleViewport) {
this._display.scale = 1;
} else {
var size = this._screenSize();
this._display.autoscale(size.w, size.h);
}
this._fixScrollbars();
}
}, {
key: "_requestRemoteResize",
value: function _requestRemoteResize() {
clearTimeout(this._resizeTimeout);
this._resizeTimeout = null;
if (!this._resizeSession || this._viewOnly || !this._supportsSetDesktopSize) {
return;
}
var size = this._screenSize();
RFB3.messages.setDesktopSize(this._sock, Math.floor(size.w), Math.floor(size.h), this._screenID, this._screenFlags);
Log.Debug("Requested new desktop size: " + size.w + "x" + size.h);
}
}, {
key: "_screenSize",
value: function _screenSize() {
var r = this._screen.getBoundingClientRect();
return {
w: r.width,
h: r.height
};
}
}, {
key: "_fixScrollbars",
value: function _fixScrollbars() {
var orig = this._screen.style.overflow;
this._screen.style.overflow = "hidden";
this._screen.getBoundingClientRect();
this._screen.style.overflow = orig;
}
}, {
key: "_updateConnectionState",
value: function _updateConnectionState(state) {
var _this3 = this;
var oldstate = this._rfbConnectionState;
if (state === oldstate) {
Log.Debug("Already in state '" + state + "', ignoring");
return;
}
if (oldstate === "disconnected") {
Log.Error("Tried changing state of a disconnected RFB object");
return;
}
switch (state) {
case "connected":
if (oldstate !== "connecting") {
Log.Error("Bad transition to connected state, previous connection state: " + oldstate);
return;
}
break;
case "disconnected":
if (oldstate !== "disconnecting") {
Log.Error("Bad transition to disconnected state, previous connection state: " + oldstate);
return;
}
break;
case "connecting":
if (oldstate !== "") {
Log.Error("Bad transition to connecting state, previous connection state: " + oldstate);
return;
}
break;
case "disconnecting":
if (oldstate !== "connected" && oldstate !== "connecting") {
Log.Error("Bad transition to disconnecting state, previous connection state: " + oldstate);
return;
}
break;
default:
Log.Error("Unknown connection state: " + state);
return;
}
this._rfbConnectionState = state;
Log.Debug("New state '" + state + "', was '" + oldstate + "'.");
if (this._disconnTimer && state !== "disconnecting") {
Log.Debug("Clearing disconnect timer");
clearTimeout(this._disconnTimer);
this._disconnTimer = null;
this._sock.off("close");
}
switch (state) {
case "connecting":
this._connect();
break;
case "connected":
this.dispatchEvent(new CustomEvent("connect", {
detail: {}
}));
break;
case "disconnecting":
this._disconnect();
this._disconnTimer = setTimeout(function() {
Log.Error("Disconnection timed out.");
_this3._updateConnectionState("disconnected");
}, DISCONNECT_TIMEOUT * 1e3);
break;
case "disconnected":
this.dispatchEvent(new CustomEvent("disconnect", {
detail: {
clean: this._rfbCleanDisconnect
}
}));
break;
}
}
}, {
key: "_fail",
value: function _fail(details) {
switch (this._rfbConnectionState) {
case "disconnecting":
Log.Error("Failed when disconnecting: " + details);
break;
case "connected":
Log.Error("Failed while connected: " + details);
break;
case "connecting":
Log.Error("Failed when connecting: " + details);
break;
default:
Log.Error("RFB failure: " + details);
break;
}
this._rfbCleanDisconnect = false;
this._updateConnectionState("disconnecting");
this._updateConnectionState("disconnected");
return false;
}
}, {
key: "_setCapability",
value: function _setCapability(cap, val) {
this._capabilities[cap] = val;
this.dispatchEvent(new CustomEvent("capabilities", {
detail: {
capabilities: this._capabilities
}
}));
}
}, {
key: "_handleMessage",
value: function _handleMessage() {
if (this._sock.rQlen === 0) {
Log.Warn("handleMessage called on an empty receive queue");
return;
}
switch (this._rfbConnectionState) {
case "disconnected":
Log.Error("Got data while disconnected");
break;
case "connected":
while (true) {
if (this._flushing) {
break;
}
if (!this._normalMsg()) {
break;
}
if (this._sock.rQlen === 0) {
break;
}
}
break;
default:
this._initMsg();
break;
}
}
}, {
key: "_handleKeyEvent",
value: function _handleKeyEvent(keysym2, code, down) {
this.sendKey(keysym2, code, down);
}
}, {
key: "_handleMouse",
value: function _handleMouse(ev) {
if (ev.type === "click") {
if (ev.target !== this._canvas) {
return;
}
}
ev.stopPropagation();
ev.preventDefault();
if (ev.type === "click" || ev.type === "contextmenu") {
return;
}
var pos = (0, _element.clientToElement)(ev.clientX, ev.clientY, this._canvas);
switch (ev.type) {
case "mousedown":
(0, _events.setCapture)(this._canvas);
this._handleMouseButton(pos.x, pos.y, true, 1 << ev.button);
break;
case "mouseup":
this._handleMouseButton(pos.x, pos.y, false, 1 << ev.button);
break;
case "mousemove":
this._handleMouseMove(pos.x, pos.y);
break;
}
}
}, {
key: "_handleMouseButton",
value: function _handleMouseButton(x, y, down, bmask) {
if (this.dragViewport) {
if (down && !this._viewportDragging) {
this._viewportDragging = true;
this._viewportDragPos = {
"x": x,
"y": y
};
this._viewportHasMoved = false;
return;
} else {
this._viewportDragging = false;
if (this._viewportHasMoved) {
return;
}
this._sendMouse(x, y, bmask);
}
}
if (this._mouseMoveTimer !== null) {
clearTimeout(this._mouseMoveTimer);
this._mouseMoveTimer = null;
this._sendMouse(x, y, this._mouseButtonMask);
}
if (down) {
this._mouseButtonMask |= bmask;
} else {
this._mouseButtonMask &= ~bmask;
}
this._sendMouse(x, y, this._mouseButtonMask);
}
}, {
key: "_handleMouseMove",
value: function _handleMouseMove(x, y) {
var _this4 = this;
if (this._viewportDragging) {
var deltaX = this._viewportDragPos.x - x;
var deltaY = this._viewportDragPos.y - y;
if (this._viewportHasMoved || Math.abs(deltaX) > _browser.dragThreshold || Math.abs(deltaY) > _browser.dragThreshold) {
this._viewportHasMoved = true;
this._viewportDragPos = {
"x": x,
"y": y
};
this._display.viewportChangePos(deltaX, deltaY);
}
return;
}
this._mousePos = {
"x": x,
"y": y
};
if (this._mouseMoveTimer == null) {
var timeSinceLastMove = Date.now() - this._mouseLastMoveTime;
if (timeSinceLastMove > MOUSE_MOVE_DELAY) {
this._sendMouse(x, y, this._mouseButtonMask);
this._mouseLastMoveTime = Date.now();
} else {
this._mouseMoveTimer = setTimeout(function() {
_this4._handleDelayedMouseMove();
}, MOUSE_MOVE_DELAY - timeSinceLastMove);
}
}
}
}, {
key: "_handleDelayedMouseMove",
value: function _handleDelayedMouseMove() {
this._mouseMoveTimer = null;
this._sendMouse(this._mousePos.x, this._mousePos.y, this._mouseButtonMask);
this._mouseLastMoveTime = Date.now();
}
}, {
key: "_sendMouse",
value: function _sendMouse(x, y, mask) {
if (this._rfbConnectionState !== "connected") {
return;
}
if (this._viewOnly) {
return;
}
RFB3.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), mask);
}
}, {
key: "_handleWheel",
value: function _handleWheel(ev) {
if (this._rfbConnectionState !== "connected") {
return;
}
if (this._viewOnly) {
return;
}
ev.stopPropagation();
ev.preventDefault();
var pos = (0, _element.clientToElement)(ev.clientX, ev.clientY, this._canvas);
var dX = ev.deltaX;
var dY = ev.deltaY;
if (ev.deltaMode !== 0) {
dX *= WHEEL_LINE_HEIGHT;
dY *= WHEEL_LINE_HEIGHT;
}
this._accumulatedWheelDeltaX += dX;
this._accumulatedWheelDeltaY += dY;
if (Math.abs(this._accumulatedWheelDeltaX) >= WHEEL_STEP) {
if (this._accumulatedWheelDeltaX < 0) {
this._handleMouseButton(pos.x, pos.y, true, 1 << 5);
this._handleMouseButton(pos.x, pos.y, false, 1 << 5);
} else if (this._accumulatedWheelDeltaX > 0) {
this._handleMouseButton(pos.x, pos.y, true, 1 << 6);
this._handleMouseButton(pos.x, pos.y, false, 1 << 6);
}
this._accumulatedWheelDeltaX = 0;
}
if (Math.abs(this._accumulatedWheelDeltaY) >= WHEEL_STEP) {
if (this._accumulatedWheelDeltaY < 0) {
this._handleMouseButton(pos.x, pos.y, true, 1 << 3);
this._handleMouseButton(pos.x, pos.y, false, 1 << 3);
} else if (this._accumulatedWheelDeltaY > 0) {
this._handleMouseButton(pos.x, pos.y, true, 1 << 4);
this._handleMouseButton(pos.x, pos.y, false, 1 << 4);
}
this._accumulatedWheelDeltaY = 0;
}
}
}, {
key: "_fakeMouseMove",
value: function _fakeMouseMove(ev, elementX, elementY) {
this._handleMouseMove(elementX, elementY);
this._cursor.move(ev.detail.clientX, ev.detail.clientY);
}
}, {
key: "_handleTapEvent",
value: function _handleTapEvent(ev, bmask) {
var pos = (0, _element.clientToElement)(ev.detail.clientX, ev.detail.clientY, this._canvas);
if (this._gestureLastTapTime !== null && Date.now() - this._gestureLastTapTime < DOUBLE_TAP_TIMEOUT && this._gestureFirstDoubleTapEv.detail.type === ev.detail.type) {
var dx = this._gestureFirstDoubleTapEv.detail.clientX - ev.detail.clientX;
var dy = this._gestureFirstDoubleTapEv.detail.clientY - ev.detail.clientY;
var distance = Math.hypot(dx, dy);
if (distance < DOUBLE_TAP_THRESHOLD) {
pos = (0, _element.clientToElement)(this._gestureFirstDoubleTapEv.detail.clientX, this._gestureFirstDoubleTapEv.detail.clientY, this._canvas);
} else {
this._gestureFirstDoubleTapEv = ev;
}
} else {
this._gestureFirstDoubleTapEv = ev;
}
this._gestureLastTapTime = Date.now();
this._fakeMouseMove(this._gestureFirstDoubleTapEv, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, true, bmask);
this._handleMouseButton(pos.x, pos.y, false, bmask);
}
}, {
key: "_handleGesture",
value: function _handleGesture(ev) {
var magnitude;
var pos = (0, _element.clientToElement)(ev.detail.clientX, ev.detail.clientY, this._canvas);
switch (ev.type) {
case "gesturestart":
switch (ev.detail.type) {
case "onetap":
this._handleTapEvent(ev, 1);
break;
case "twotap":
this._handleTapEvent(ev, 4);
break;
case "threetap":
this._handleTapEvent(ev, 2);
break;
case "drag":
this._fakeMouseMove(ev, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, true, 1);
break;
case "longpress":
this._fakeMouseMove(ev, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, true, 4);
break;
case "twodrag":
this._gestureLastMagnitudeX = ev.detail.magnitudeX;
this._gestureLastMagnitudeY = ev.detail.magnitudeY;
this._fakeMouseMove(ev, pos.x, pos.y);
break;
case "pinch":
this._gestureLastMagnitudeX = Math.hypot(ev.detail.magnitudeX, ev.detail.magnitudeY);
this._fakeMouseMove(ev, pos.x, pos.y);
break;
}
break;
case "gesturemove":
switch (ev.detail.type) {
case "onetap":
case "twotap":
case "threetap":
break;
case "drag":
case "longpress":
this._fakeMouseMove(ev, pos.x, pos.y);
break;
case "twodrag":
this._fakeMouseMove(ev, pos.x, pos.y);
while (ev.detail.magnitudeY - this._gestureLastMagnitudeY > GESTURE_SCRLSENS) {
this._handleMouseButton(pos.x, pos.y, true, 8);
this._handleMouseButton(pos.x, pos.y, false, 8);
this._gestureLastMagnitudeY += GESTURE_SCRLSENS;
}
while (ev.detail.magnitudeY - this._gestureLastMagnitudeY < -GESTURE_SCRLSENS) {
this._handleMouseButton(pos.x, pos.y, true, 16);
this._handleMouseButton(pos.x, pos.y, false, 16);
this._gestureLastMagnitudeY -= GESTURE_SCRLSENS;
}
while (ev.detail.magnitudeX - this._gestureLastMagnitudeX > GESTURE_SCRLSENS) {
this._handleMouseButton(pos.x, pos.y, true, 32);
this._handleMouseButton(pos.x, pos.y, false, 32);
this._gestureLastMagnitudeX += GESTURE_SCRLSENS;
}
while (ev.detail.magnitudeX - this._gestureLastMagnitudeX < -GESTURE_SCRLSENS) {
this._handleMouseButton(pos.x, pos.y, true, 64);
this._handleMouseButton(pos.x, pos.y, false, 64);
this._gestureLastMagnitudeX -= GESTURE_SCRLSENS;
}
break;
case "pinch":
this._fakeMouseMove(ev, pos.x, pos.y);
magnitude = Math.hypot(ev.detail.magnitudeX, ev.detail.magnitudeY);
if (Math.abs(magnitude - this._gestureLastMagnitudeX) > GESTURE_ZOOMSENS) {
this._handleKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
while (magnitude - this._gestureLastMagnitudeX > GESTURE_ZOOMSENS) {
this._handleMouseButton(pos.x, pos.y, true, 8);
this._handleMouseButton(pos.x, pos.y, false, 8);
this._gestureLastMagnitudeX += GESTURE_ZOOMSENS;
}
while (magnitude - this._gestureLastMagnitudeX < -GESTURE_ZOOMSENS) {
this._handleMouseButton(pos.x, pos.y, true, 16);
this._handleMouseButton(pos.x, pos.y, false, 16);
this._gestureLastMagnitudeX -= GESTURE_ZOOMSENS;
}
}
this._handleKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", false);
break;
}
break;
case "gestureend":
switch (ev.detail.type) {
case "onetap":
case "twotap":
case "threetap":
case "pinch":
case "twodrag":
break;
case "drag":
this._fakeMouseMove(ev, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, false, 1);
break;
case "longpress":
this._fakeMouseMove(ev, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, false, 4);
break;
}
break;
}
}
}, {
key: "_negotiateProtocolVersion",
value: function _negotiateProtocolVersion() {
if (this._sock.rQwait("version", 12)) {
return false;
}
var sversion = this._sock.rQshiftStr(12).substr(4, 7);
Log.Info("Server ProtocolVersion: " + sversion);
var isRepeater = 0;
switch (sversion) {
case "000.000":
isRepeater = 1;
break;
case "003.003":
case "003.006":
case "003.889":
this._rfbVersion = 3.3;
break;
case "003.007":
this._rfbVersion = 3.7;
break;
case "003.008":
case "004.000":
case "004.001":
case "005.000":
this._rfbVersion = 3.8;
break;
default:
return this._fail("Invalid server version " + sversion);
}
if (isRepeater) {
var repeaterID = "ID:" + this._repeaterID;
while (repeaterID.length < 250) {
repeaterID += "\0";
}
this._sock.sendString(repeaterID);
return true;
}
if (this._rfbVersion > this._rfbMaxVersion) {
this._rfbVersion = this._rfbMaxVersion;
}
var cversion = "00" + parseInt(this._rfbVersion, 10) + ".00" + this._rfbVersion * 10 % 10;
this._sock.sendString("RFB " + cversion + "\n");
Log.Debug("Sent ProtocolVersion: " + cversion);
this._rfbInitState = "Security";
}
}, {
key: "_negotiateSecurity",
value: function _negotiateSecurity() {
if (this._rfbVersion >= 3.7) {
var numTypes = this._sock.rQshift8();
if (this._sock.rQwait("security type", numTypes, 1)) {
return false;
}
if (numTypes === 0) {
this._rfbInitState = "SecurityReason";
this._securityContext = "no security types";
this._securityStatus = 1;
return this._initMsg();
}
var types = this._sock.rQshiftBytes(numTypes);
Log.Debug("Server security types: " + types);
if (types.includes(1)) {
this._rfbAuthScheme = 1;
} else if (types.includes(22)) {
this._rfbAuthScheme = 22;
} else if (types.includes(16)) {
this._rfbAuthScheme = 16;
} else if (types.includes(2)) {
this._rfbAuthScheme = 2;
} else if (types.includes(19)) {
this._rfbAuthScheme = 19;
} else {
return this._fail("Unsupported security types (types: " + types + ")");
}
this._sock.send([this._rfbAuthScheme]);
} else {
if (this._sock.rQwait("security scheme", 4)) {
return false;
}
this._rfbAuthScheme = this._sock.rQshift32();
if (this._rfbAuthScheme == 0) {
this._rfbInitState = "SecurityReason";
this._securityContext = "authentication scheme";
this._securityStatus = 1;
return this._initMsg();
}
}
this._rfbInitState = "Authentication";
Log.Debug("Authenticating using scheme: " + this._rfbAuthScheme);
return this._initMsg();
}
}, {
key: "_handleSecurityReason",
value: function _handleSecurityReason() {
if (this._sock.rQwait("reason length", 4)) {
return false;
}
var strlen = this._sock.rQshift32();
var reason = "";
if (strlen > 0) {
if (this._sock.rQwait("reason", strlen, 4)) {
return false;
}
reason = this._sock.rQshiftStr(strlen);
}
if (reason !== "") {
this.dispatchEvent(new CustomEvent("securityfailure", {
detail: {
status: this._securityStatus,
reason
}
}));
return this._fail("Security negotiation failed on " + this._securityContext + " (reason: " + reason + ")");
} else {
this.dispatchEvent(new CustomEvent("securityfailure", {
detail: {
status: this._securityStatus
}
}));
return this._fail("Security negotiation failed on " + this._securityContext);
}
}
}, {
key: "_negotiateXvpAuth",
value: function _negotiateXvpAuth() {
if (this._rfbCredentials.username === void 0 || this._rfbCr