Merge a607c19f45 into 609a3fac74
This commit is contained in:
commit
7112d1b70f
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module",
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended"
|
||||||
|
}
|
||||||
|
|
@ -9,14 +9,14 @@
|
||||||
// Fallback for all uncought errors
|
// Fallback for all uncought errors
|
||||||
function handleError (event, err) {
|
function handleError (event, err) {
|
||||||
try {
|
try {
|
||||||
var msg = document.getElementById('noVNC_fallback_errormsg');
|
const msg = document.getElementById('noVNC_fallback_errormsg');
|
||||||
|
|
||||||
// Only show the initial error
|
// Only show the initial error
|
||||||
if (msg.hasChildNodes()) {
|
if (msg.hasChildNodes()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var div = document.createElement("div");
|
let div = document.createElement("div");
|
||||||
div.classList.add('noVNC_message');
|
div.classList.add('noVNC_message');
|
||||||
div.appendChild(document.createTextNode(event.message));
|
div.appendChild(document.createTextNode(event.message));
|
||||||
msg.appendChild(div);
|
msg.appendChild(div);
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
if (event.filename) {
|
if (event.filename) {
|
||||||
div = document.createElement("div");
|
div = document.createElement("div");
|
||||||
div.className = 'noVNC_location';
|
div.className = 'noVNC_location';
|
||||||
var text = event.filename;
|
let text = event.filename;
|
||||||
if (event.lineno !== undefined) {
|
if (event.lineno !== undefined) {
|
||||||
text += ":" + event.lineno;
|
text += ":" + event.lineno;
|
||||||
if (event.colno !== undefined) {
|
if (event.colno !== undefined) {
|
||||||
|
|
@ -51,6 +51,6 @@
|
||||||
// from being printed to the browser console.
|
// from being printed to the browser console.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
window.addEventListener('error', function (evt) { handleError(evt, evt.error); });
|
window.addEventListener('error', evt => handleError(evt, evt.error));
|
||||||
window.addEventListener('unhandledrejection', function (evt) { handleError(evt.reason, evt.reason); });
|
window.addEventListener('unhandledrejection', evt => handleError(evt.reason, evt.reason));
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,17 @@
|
||||||
* Localization Utilities
|
* Localization Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function Localizer() {
|
export class Localizer{
|
||||||
// Currently configured language
|
constructor() {
|
||||||
this.language = 'en';
|
// Currently configured language
|
||||||
|
this.language = 'en';
|
||||||
|
|
||||||
// Current dictionary of translations
|
// Current dictionary of translations
|
||||||
this.dictionary = undefined;
|
this.dictionary = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
Localizer.prototype = {
|
|
||||||
// Configure suitable language based on user preferences
|
// Configure suitable language based on user preferences
|
||||||
setup: function (supportedLanguages) {
|
setup(supportedLanguages) {
|
||||||
var userLanguages;
|
|
||||||
|
|
||||||
this.language = 'en'; // Default: US English
|
this.language = 'en'; // Default: US English
|
||||||
|
|
||||||
|
|
@ -29,17 +28,16 @@ Localizer.prototype = {
|
||||||
* Navigator.languages only available in Chrome (32+) and FireFox (32+)
|
* Navigator.languages only available in Chrome (32+) and FireFox (32+)
|
||||||
* Fall back to navigator.language for other browsers
|
* Fall back to navigator.language for other browsers
|
||||||
*/
|
*/
|
||||||
if (typeof window.navigator.languages == 'object') {
|
|
||||||
userLanguages = window.navigator.languages;
|
|
||||||
} else {
|
|
||||||
userLanguages = [navigator.language || navigator.userLanguage];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0;i < userLanguages.length;i++) {
|
const userLanguages = (typeof window.navigator.languages == 'object')
|
||||||
var userLang = userLanguages[i];
|
? window.navigator.languages
|
||||||
userLang = userLang.toLowerCase();
|
: [navigator.language || navigator.userLanguage];
|
||||||
userLang = userLang.replace("_", "-");
|
|
||||||
userLang = userLang.split("-");
|
for (let i = 0;i < userLanguages.length;i++) {
|
||||||
|
const userLang = userLanguages[i]
|
||||||
|
.toLowerCase()
|
||||||
|
.replace("_", "-")
|
||||||
|
.split("-");
|
||||||
|
|
||||||
// Built-in default?
|
// Built-in default?
|
||||||
if ((userLang[0] === 'en') &&
|
if ((userLang[0] === 'en') &&
|
||||||
|
|
@ -48,11 +46,11 @@ Localizer.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// First pass: perfect match
|
// First pass: perfect match
|
||||||
for (var j = 0;j < supportedLanguages.length;j++) {
|
for (let j = 0;j < supportedLanguages.length;j++) {
|
||||||
var supLang = supportedLanguages[j];
|
const supLang = supportedLanguages[j]
|
||||||
supLang = supLang.toLowerCase();
|
.toLowerCase()
|
||||||
supLang = supLang.replace("_", "-");
|
.replace("_", "-")
|
||||||
supLang = supLang.split("-");
|
.split("-");
|
||||||
|
|
||||||
if (userLang[0] !== supLang[0])
|
if (userLang[0] !== supLang[0])
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -64,11 +62,11 @@ Localizer.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass: fallback
|
// Second pass: fallback
|
||||||
for (var j = 0;j < supportedLanguages.length;j++) {
|
for (let j = 0; j < supportedLanguages.length; j++) {
|
||||||
supLang = supportedLanguages[j];
|
const supLang = supportedLanguages[j]
|
||||||
supLang = supLang.toLowerCase();
|
.toLowerCase()
|
||||||
supLang = supLang.replace("_", "-");
|
.replace("_", "-")
|
||||||
supLang = supLang.split("-");
|
.split("-");
|
||||||
|
|
||||||
if (userLang[0] !== supLang[0])
|
if (userLang[0] !== supLang[0])
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -79,36 +77,31 @@ Localizer.prototype = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Retrieve localised text
|
// Retrieve localised text
|
||||||
get: function (id) {
|
get(id) {
|
||||||
if (typeof this.dictionary !== 'undefined' && this.dictionary[id]) {
|
if (typeof this.dictionary !== 'undefined' && this.dictionary[id]) {
|
||||||
return this.dictionary[id];
|
return this.dictionary[id];
|
||||||
} else {
|
} else {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Traverses the DOM and translates relevant fields
|
// Traverses the DOM and translates relevant fields
|
||||||
// See https://html.spec.whatwg.org/multipage/dom.html#attr-translate
|
// See https://html.spec.whatwg.org/multipage/dom.html#attr-translate
|
||||||
translateDOM: function () {
|
translateDOM() {
|
||||||
var self = this;
|
|
||||||
function process(elem, enabled) {
|
function process(elem, enabled) {
|
||||||
function isAnyOf(searchElement, items) {
|
function isAnyOf(searchElement, items) {
|
||||||
return items.indexOf(searchElement) !== -1;
|
return items.indexOf(searchElement) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateAttribute(elem, attr) {
|
function translateAttribute(elem, attr) {
|
||||||
var str = elem.getAttribute(attr);
|
elem.setAttribute(attr, this.get(elem.getAttribute(attr)));
|
||||||
str = self.get(str);
|
|
||||||
elem.setAttribute(attr, str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function translateTextNode(node) {
|
function translateTextNode(node) {
|
||||||
var str = node.data.trim();
|
node.data = this.get(node.data.trim());
|
||||||
str = self.get(str);
|
|
||||||
node.data = str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elem.hasAttribute("translate")) {
|
if (elem.hasAttribute("translate")) {
|
||||||
|
|
@ -152,19 +145,18 @@ Localizer.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0;i < elem.childNodes.length;i++) {
|
elem.childNodes.forEach((node) => {
|
||||||
var node = elem.childNodes[i];
|
|
||||||
if (node.nodeType === node.ELEMENT_NODE) {
|
if (node.nodeType === node.ELEMENT_NODE) {
|
||||||
process(node, enabled);
|
process(node, enabled);
|
||||||
} else if (node.nodeType === node.TEXT_NODE && enabled) {
|
} else if (node.nodeType === node.TEXT_NODE && enabled) {
|
||||||
translateTextNode(node);
|
translateTextNode(node);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
process(document.body, true);
|
process(document.body, true);
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export var l10n = new Localizer();
|
export let l10n = new Localizer();
|
||||||
export default l10n.get.bind(l10n);
|
export default l10n.get.bind(l10n);
|
||||||
|
|
|
||||||
103
app/webutil.js
103
app/webutil.js
|
|
@ -7,26 +7,21 @@
|
||||||
* See README.md for usage and integration instructions.
|
* See README.md for usage and integration instructions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint bitwise: false, white: false, browser: true, devel: true */
|
|
||||||
/*global Util, window, document */
|
|
||||||
|
|
||||||
import { init_logging as main_init_logging } from '../core/util/logging.js';
|
import { init_logging as main_init_logging } from '../core/util/logging.js';
|
||||||
|
|
||||||
// init log level reading the logging HTTP param
|
// init log level reading the logging HTTP param
|
||||||
export function init_logging (level) {
|
export function init_logging (level) {
|
||||||
"use strict";
|
|
||||||
if (typeof level !== "undefined") {
|
if (typeof level !== "undefined") {
|
||||||
main_init_logging(level);
|
main_init_logging(level);
|
||||||
} else {
|
} else {
|
||||||
var param = document.location.href.match(/logging=([A-Za-z0-9\._\-]*)/);
|
const param = document.location.href.match(/logging=([A-Za-z0-9._-]*)/);
|
||||||
main_init_logging(param || undefined);
|
main_init_logging(param || undefined);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Read a query string variable
|
// Read a query string variable
|
||||||
export function getQueryVar (name, defVal) {
|
export function getQueryVar (name, defVal) {
|
||||||
"use strict";
|
const re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
|
||||||
var re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
|
|
||||||
match = document.location.href.match(re);
|
match = document.location.href.match(re);
|
||||||
if (typeof defVal === 'undefined') { defVal = null; }
|
if (typeof defVal === 'undefined') { defVal = null; }
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|
@ -34,12 +29,11 @@ export function getQueryVar (name, defVal) {
|
||||||
} else {
|
} else {
|
||||||
return defVal;
|
return defVal;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Read a hash fragment variable
|
// Read a hash fragment variable
|
||||||
export function getHashVar (name, defVal) {
|
export function getHashVar (name, defVal) {
|
||||||
"use strict";
|
const re = new RegExp('.*[&#]' + name + '=([^&]*)'),
|
||||||
var re = new RegExp('.*[&#]' + name + '=([^&]*)'),
|
|
||||||
match = document.location.hash.match(re);
|
match = document.location.hash.match(re);
|
||||||
if (typeof defVal === 'undefined') { defVal = null; }
|
if (typeof defVal === 'undefined') { defVal = null; }
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|
@ -47,18 +41,17 @@ export function getHashVar (name, defVal) {
|
||||||
} else {
|
} else {
|
||||||
return defVal;
|
return defVal;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Read a variable from the fragment or the query string
|
// Read a variable from the fragment or the query string
|
||||||
// Fragment takes precedence
|
// Fragment takes precedence
|
||||||
export function getConfigVar (name, defVal) {
|
export function getConfigVar (name, defVal) {
|
||||||
"use strict";
|
let val = getHashVar(name);
|
||||||
var val = getHashVar(name);
|
|
||||||
if (val === null) {
|
if (val === null) {
|
||||||
val = getQueryVar(name, defVal);
|
val = getQueryVar(name, defVal);
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
|
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
|
||||||
|
|
@ -66,8 +59,7 @@ export function getConfigVar (name, defVal) {
|
||||||
|
|
||||||
// No days means only for this browser session
|
// No days means only for this browser session
|
||||||
export function createCookie (name, value, days) {
|
export function createCookie (name, value, days) {
|
||||||
"use strict";
|
let date, expires;
|
||||||
var date, expires;
|
|
||||||
if (days) {
|
if (days) {
|
||||||
date = new Date();
|
date = new Date();
|
||||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||||
|
|
@ -76,46 +68,41 @@ export function createCookie (name, value, days) {
|
||||||
expires = "";
|
expires = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
var secure;
|
const secure = (document.location.protocol === "https:")
|
||||||
if (document.location.protocol === "https:") {
|
? "; secure"
|
||||||
secure = "; secure";
|
: "";
|
||||||
} else {
|
|
||||||
secure = "";
|
|
||||||
}
|
|
||||||
document.cookie = name + "=" + value + expires + "; path=/" + secure;
|
document.cookie = name + "=" + value + expires + "; path=/" + secure;
|
||||||
};
|
}
|
||||||
|
|
||||||
export function readCookie (name, defaultValue) {
|
export function readCookie (name, defaultValue) {
|
||||||
"use strict";
|
const nameEQ = name + "=",
|
||||||
var nameEQ = name + "=",
|
|
||||||
ca = document.cookie.split(';');
|
ca = document.cookie.split(';');
|
||||||
|
|
||||||
for (var i = 0; i < ca.length; i += 1) {
|
for (let i = 0; i < ca.length; i += 1) {
|
||||||
var c = ca[i];
|
let c = ca[i];
|
||||||
while (c.charAt(0) === ' ') { c = c.substring(1, c.length); }
|
while (c.charAt(0) === ' ') { c = c.substring(1, c.length); }
|
||||||
if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); }
|
if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); }
|
||||||
}
|
}
|
||||||
|
|
||||||
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
|
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
|
||||||
};
|
}
|
||||||
|
|
||||||
export function eraseCookie (name) {
|
export function eraseCookie (name) {
|
||||||
"use strict";
|
|
||||||
createCookie(name, "", -1);
|
createCookie(name, "", -1);
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setting handling.
|
* Setting handling.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var settings = {};
|
let settings = {};
|
||||||
|
|
||||||
export function initSettings (callback /*, ...callbackArgs */) {
|
export function initSettings (callback /*, ...callbackArgs */) {
|
||||||
"use strict";
|
const callbackArgs = Array.prototype.slice.call(arguments, 1);
|
||||||
var callbackArgs = Array.prototype.slice.call(arguments, 1);
|
|
||||||
if (window.chrome && window.chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
window.chrome.storage.sync.get(function (cfg) {
|
window.chrome.storage.sync.get((cfg) => {
|
||||||
settings = cfg;
|
settings = cfg;
|
||||||
console.log(settings);
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback.apply(this, callbackArgs);
|
callback.apply(this, callbackArgs);
|
||||||
}
|
}
|
||||||
|
|
@ -126,11 +113,10 @@ export function initSettings (callback /*, ...callbackArgs */) {
|
||||||
callback.apply(this, callbackArgs);
|
callback.apply(this, callbackArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// No days means only for this browser session
|
// No days means only for this browser session
|
||||||
export function writeSetting (name, value) {
|
export function writeSetting (name, value) {
|
||||||
"use strict";
|
|
||||||
if (window.chrome && window.chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
//console.log("writeSetting:", name, value);
|
//console.log("writeSetting:", name, value);
|
||||||
if (settings[name] !== value) {
|
if (settings[name] !== value) {
|
||||||
|
|
@ -140,11 +126,10 @@ export function writeSetting (name, value) {
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem(name, value);
|
localStorage.setItem(name, value);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function readSetting (name, defaultValue) {
|
export function readSetting (name, defaultValue) {
|
||||||
"use strict";
|
let value;
|
||||||
var value;
|
|
||||||
if (window.chrome && window.chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
value = settings[name];
|
value = settings[name];
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -158,33 +143,29 @@ export function readSetting (name, defaultValue) {
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function eraseSetting (name) {
|
export function eraseSetting (name) {
|
||||||
"use strict";
|
|
||||||
if (window.chrome && window.chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
window.chrome.storage.sync.remove(name);
|
window.chrome.storage.sync.remove(name);
|
||||||
delete settings[name];
|
delete settings[name];
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(name);
|
localStorage.removeItem(name);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function injectParamIfMissing (path, param, value) {
|
export function injectParamIfMissing (path, param, value) {
|
||||||
// force pretend that we're dealing with a relative path
|
// force pretend that we're dealing with a relative path
|
||||||
// (assume that we wanted an extra if we pass one in)
|
// (assume that we wanted an extra if we pass one in)
|
||||||
path = "/" + path;
|
path = "/" + path;
|
||||||
|
|
||||||
var elem = document.createElement('a');
|
const elem = document.createElement('a');
|
||||||
elem.href = path;
|
elem.href = path;
|
||||||
|
|
||||||
var param_eq = encodeURIComponent(param) + "=";
|
const param_eq = encodeURIComponent(param) + "=";
|
||||||
var query;
|
const query = elem.search
|
||||||
if (elem.search) {
|
? elem.search.slice(1).split('&')
|
||||||
query = elem.search.slice(1).split('&');
|
: [];
|
||||||
} else {
|
|
||||||
query = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!query.some(function (v) { return v.startsWith(param_eq); })) {
|
if (!query.some(function (v) { return v.startsWith(param_eq); })) {
|
||||||
query.push(param_eq + encodeURIComponent(value));
|
query.push(param_eq + encodeURIComponent(value));
|
||||||
|
|
@ -195,10 +176,10 @@ export function injectParamIfMissing (path, param, value) {
|
||||||
// in the elem.pathname string. Handle that case gracefully.
|
// in the elem.pathname string. Handle that case gracefully.
|
||||||
if (elem.pathname.charAt(0) == "/") {
|
if (elem.pathname.charAt(0) == "/") {
|
||||||
return elem.pathname.slice(1) + elem.search + elem.hash;
|
return elem.pathname.slice(1) + elem.search + elem.hash;
|
||||||
} else {
|
|
||||||
return elem.pathname + elem.search + elem.hash;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
return elem.pathname + elem.search + elem.hash;
|
||||||
|
}
|
||||||
|
|
||||||
// sadly, we can't use the Fetch API until we decide to drop
|
// sadly, we can't use the Fetch API until we decide to drop
|
||||||
// IE11 support or polyfill promises and fetch in IE11.
|
// IE11 support or polyfill promises and fetch in IE11.
|
||||||
|
|
@ -206,28 +187,26 @@ export function injectParamIfMissing (path, param, value) {
|
||||||
// will receive either an event or an error on failure.
|
// will receive either an event or an error on failure.
|
||||||
export function fetchJSON(path, resolve, reject) {
|
export function fetchJSON(path, resolve, reject) {
|
||||||
// NB: IE11 doesn't support JSON as a responseType
|
// NB: IE11 doesn't support JSON as a responseType
|
||||||
var req = new XMLHttpRequest();
|
const req = new XMLHttpRequest();
|
||||||
req.open('GET', path);
|
req.open('GET', path);
|
||||||
|
|
||||||
req.onload = function () {
|
req.onload = () => {
|
||||||
if (req.status === 200) {
|
if (req.status === 200) {
|
||||||
try {
|
try {
|
||||||
var resObj = JSON.parse(req.responseText);
|
resolve(JSON.parse(req.responseText));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
resolve(resObj);
|
|
||||||
} else {
|
} else {
|
||||||
reject(new Error("XHR got non-200 status while trying to load '" + path + "': " + req.status));
|
reject(new Error("XHR got non-200 status while trying to load '" + path + "': " + req.status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
req.onerror = function (evt) {
|
req.onerror = (evt) => {
|
||||||
reject(new Error("XHR encountered an error while trying to load '" + path + "': " + evt.message));
|
reject(new Error("XHR encountered an error while trying to load '" + path + "': " + evt.message));
|
||||||
};
|
};
|
||||||
|
|
||||||
req.ontimeout = function (evt) {
|
req.ontimeout = () => {
|
||||||
reject(new Error("XHR timed out while trying to load '" + path + "'"));
|
reject(new Error("XHR timed out while trying to load '" + path + "'"));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,50 +4,44 @@
|
||||||
|
|
||||||
// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
|
// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
|
||||||
|
|
||||||
/*jslint white: false */
|
import * as Log from './util/logging.js';
|
||||||
/*global console */
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/* Convert data (an array of integers) to a Base64 string. */
|
/* Convert data (an array of integers) to a Base64 string. */
|
||||||
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
|
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
|
||||||
base64Pad : '=',
|
base64Pad : '=',
|
||||||
|
|
||||||
encode: function (data) {
|
encode(data) {
|
||||||
"use strict";
|
let result = '';
|
||||||
var result = '';
|
const length = data.length;
|
||||||
var toBase64Table = this.toBase64Table;
|
const lengthpad = (length % 3);
|
||||||
var length = data.length;
|
|
||||||
var lengthpad = (length % 3);
|
|
||||||
// Convert every three bytes to 4 ascii characters.
|
// Convert every three bytes to 4 ascii characters.
|
||||||
|
|
||||||
for (var i = 0; i < (length - 2); i += 3) {
|
for (let i = 0; i < (length - 2); i += 3) {
|
||||||
result += toBase64Table[data[i] >> 2];
|
result += this.toBase64Table[data[i] >> 2];
|
||||||
result += toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)];
|
result += this.toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)];
|
||||||
result += toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)];
|
result += this.toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)];
|
||||||
result += toBase64Table[data[i + 2] & 0x3f];
|
result += this.toBase64Table[data[i + 2] & 0x3f];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the remaining 1 or 2 bytes, pad out to 4 characters.
|
// Convert the remaining 1 or 2 bytes, pad out to 4 characters.
|
||||||
var j = 0;
|
let j = length - lengthpad;
|
||||||
if (lengthpad === 2) {
|
if (lengthpad === 2) {
|
||||||
j = length - lengthpad;
|
result += this.toBase64Table[data[j] >> 2];
|
||||||
result += toBase64Table[data[j] >> 2];
|
result += this.toBase64Table[((data[j] & 0x03) << 4) + (data[j + 1] >> 4)];
|
||||||
result += toBase64Table[((data[j] & 0x03) << 4) + (data[j + 1] >> 4)];
|
result += this.toBase64Table[(data[j + 1] & 0x0f) << 2];
|
||||||
result += toBase64Table[(data[j + 1] & 0x0f) << 2];
|
result += this.toBase64Table[64];
|
||||||
result += toBase64Table[64];
|
|
||||||
} else if (lengthpad === 1) {
|
} else if (lengthpad === 1) {
|
||||||
j = length - lengthpad;
|
result += this.toBase64Table[data[j] >> 2];
|
||||||
result += toBase64Table[data[j] >> 2];
|
result += this.toBase64Table[(data[j] & 0x03) << 4];
|
||||||
result += toBase64Table[(data[j] & 0x03) << 4];
|
result += this.toBase64Table[64];
|
||||||
result += toBase64Table[64];
|
result += this.toBase64Table[64];
|
||||||
result += toBase64Table[64];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Convert Base64 data to a string */
|
/* Convert Base64 data to a string */
|
||||||
/* jshint -W013 */
|
|
||||||
toBinaryTable : [
|
toBinaryTable : [
|
||||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||||
|
|
@ -58,31 +52,25 @@ export default {
|
||||||
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
|
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
|
||||||
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
|
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
|
||||||
],
|
],
|
||||||
/* jshint +W013 */
|
|
||||||
|
|
||||||
decode: function (data, offset) {
|
decode(data, offset) {
|
||||||
"use strict";
|
|
||||||
offset = typeof(offset) !== 'undefined' ? offset : 0;
|
offset = typeof(offset) !== 'undefined' ? offset : 0;
|
||||||
var toBinaryTable = this.toBinaryTable;
|
let leftbits = 0; // number of bits decoded, but yet to be appended
|
||||||
var base64Pad = this.base64Pad;
|
let leftdata = 0; // bits decoded, but yet to be appended
|
||||||
var result, result_length;
|
let data_length = data.indexOf('=') - offset;
|
||||||
var leftbits = 0; // number of bits decoded, but yet to be appended
|
|
||||||
var leftdata = 0; // bits decoded, but yet to be appended
|
|
||||||
var data_length = data.indexOf('=') - offset;
|
|
||||||
|
|
||||||
if (data_length < 0) { data_length = data.length - offset; }
|
if (data_length < 0) { data_length = data.length - offset; }
|
||||||
|
|
||||||
/* Every four characters is 3 resulting numbers */
|
/* Every four characters is 3 resulting numbers */
|
||||||
result_length = (data_length >> 2) * 3 + Math.floor((data_length % 4) / 1.5);
|
const result_length = (data_length >> 2) * 3 + Math.floor((data_length % 4) / 1.5);
|
||||||
result = new Array(result_length);
|
const result = new Array(result_length);
|
||||||
|
|
||||||
// Convert one by one.
|
// Convert one by one.
|
||||||
for (var idx = 0, i = offset; i < data.length; i++) {
|
for (let idx = 0, i = offset; i < data.length; i++) {
|
||||||
var c = toBinaryTable[data.charCodeAt(i) & 0x7f];
|
const c = this.toBinaryTable[data.charCodeAt(i) & 0x7f];
|
||||||
var padding = (data.charAt(i) === base64Pad);
|
|
||||||
// Skip illegal characters and whitespace
|
// Skip illegal characters and whitespace
|
||||||
if (c === -1) {
|
if (c === -1) {
|
||||||
console.error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
|
Log.Error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +82,7 @@ export default {
|
||||||
if (leftbits >= 8) {
|
if (leftbits >= 8) {
|
||||||
leftbits -= 8;
|
leftbits -= 8;
|
||||||
// Append if not padding.
|
// Append if not padding.
|
||||||
if (!padding) {
|
if (data.charAt(i) !== this.base64Pad) {
|
||||||
result[idx++] = (leftdata >> leftbits) & 0xff;
|
result[idx++] = (leftdata >> leftbits) & 0xff;
|
||||||
}
|
}
|
||||||
leftdata &= (1 << leftbits) - 1;
|
leftdata &= (1 << leftbits) - 1;
|
||||||
|
|
@ -103,7 +91,7 @@ export default {
|
||||||
|
|
||||||
// If there are any bits left, the base64 string was corrupted
|
// If there are any bits left, the base64 string was corrupted
|
||||||
if (leftbits) {
|
if (leftbits) {
|
||||||
err = new Error('Corrupted base64 string');
|
const err = new Error('Corrupted base64 string');
|
||||||
err.name = 'Base64-Error';
|
err.name = 'Base64-Error';
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
68
core/des.js
68
core/des.js
|
|
@ -75,89 +75,79 @@
|
||||||
* fine Java utilities: http://www.acme.com/java/
|
* fine Java utilities: http://www.acme.com/java/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jslint white: false */
|
|
||||||
|
|
||||||
export default function DES(passwd) {
|
export default function DES(passwd) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// Tables, permutations, S-boxes, etc.
|
// Tables, permutations, S-boxes, etc.
|
||||||
// jshint -W013
|
const PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
|
||||||
var PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
|
|
||||||
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
|
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
|
||||||
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
|
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ];
|
||||||
totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28],
|
const totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28];
|
||||||
z = 0x0, a,b,c,d,e,f, SP1,SP2,SP3,SP4,SP5,SP6,SP7,SP8,
|
const keys = [];
|
||||||
keys = [];
|
const z = 0x0;
|
||||||
|
let a,b,c,d,e,f;
|
||||||
|
|
||||||
// jshint -W015
|
|
||||||
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
|
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
|
||||||
SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
|
const SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
|
||||||
z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
|
z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
|
||||||
a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
|
a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
|
||||||
c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
|
c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
|
||||||
a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
|
a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
|
||||||
SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
|
const SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
|
||||||
a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
|
a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
|
||||||
z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
|
z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
|
||||||
z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
|
z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
|
||||||
a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
|
a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
|
||||||
SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
|
const SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
|
||||||
b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
|
b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
|
||||||
c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
|
c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
|
||||||
b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
|
b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
|
||||||
a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
|
a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
|
||||||
SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
|
const SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
|
||||||
z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
|
z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
|
||||||
b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
|
b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
|
||||||
c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
|
c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
|
||||||
a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
|
a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
|
||||||
SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
|
const SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
|
||||||
a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
|
a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
|
||||||
z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
|
z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
|
||||||
c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
|
c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
|
||||||
a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
|
a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
|
||||||
SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
|
const SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
|
||||||
z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
|
z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
|
||||||
b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
|
b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
|
||||||
a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
|
a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
|
||||||
a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
|
a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
|
||||||
SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
|
const SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
|
||||||
b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
|
b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
|
||||||
b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
|
b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
|
||||||
z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
|
z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
|
||||||
a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
|
a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
|
||||||
SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
|
const SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
|
||||||
c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
|
c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
|
||||||
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
|
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
|
||||||
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
|
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
|
||||||
// jshint +W013,+W015
|
|
||||||
|
|
||||||
// Set the key.
|
// Set the key.
|
||||||
function setKeys(keyBlock) {
|
function setKeys(keyBlock) {
|
||||||
var i, j, l, m, n, o, pc1m = [], pcr = [], kn = [],
|
const pc1m = [], pcr = [], kn = [];
|
||||||
raw0, raw1, rawi, KnLi;
|
let l, m, n;
|
||||||
|
|
||||||
for (j = 0, l = 56; j < 56; ++j, l -= 8) {
|
for (let j = 0, l = 56; j < 56; ++j, l -= 8) {
|
||||||
l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
|
l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
|
||||||
m = l & 0x7;
|
m = l & 0x7;
|
||||||
pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
|
pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 16; ++i) {
|
for (let i = 0; i < 16; ++i) {
|
||||||
m = i << 1;
|
m = i << 1;
|
||||||
n = m + 1;
|
n = m + 1;
|
||||||
kn[m] = kn[n] = 0;
|
kn[m] = kn[n] = 0;
|
||||||
for (o = 28; o < 59; o += 28) {
|
for (let o = 28; o < 59; o += 28) {
|
||||||
for (j = o - 28; j < o; ++j) {
|
for (let j = o - 28; j < o; ++j) {
|
||||||
l = j + totrot[i];
|
l = j + totrot[i];
|
||||||
if (l < o) {
|
pcr[j] = (l < o) ? pc1m[l] : pc1m[l - 28];
|
||||||
pcr[j] = pc1m[l];
|
|
||||||
} else {
|
|
||||||
pcr[j] = pc1m[l - 28];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (j = 0; j < 24; ++j) {
|
for (let j = 0; j < 24; ++j) {
|
||||||
if (pcr[PC2[j]] !== 0) {
|
if (pcr[PC2[j]] !== 0) {
|
||||||
kn[m] |= 1 << (23 - j);
|
kn[m] |= 1 << (23 - j);
|
||||||
}
|
}
|
||||||
|
|
@ -168,9 +158,9 @@ export default function DES(passwd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// cookey
|
// cookey
|
||||||
for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
|
for (let i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
|
||||||
raw0 = kn[rawi++];
|
const raw0 = kn[rawi++];
|
||||||
raw1 = kn[rawi++];
|
const raw1 = kn[rawi++];
|
||||||
keys[KnLi] = (raw0 & 0x00fc0000) << 6;
|
keys[KnLi] = (raw0 & 0x00fc0000) << 6;
|
||||||
keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
||||||
keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
||||||
|
|
@ -186,7 +176,8 @@ export default function DES(passwd) {
|
||||||
|
|
||||||
// Encrypt 8 bytes of text
|
// Encrypt 8 bytes of text
|
||||||
function enc8(text) {
|
function enc8(text) {
|
||||||
var i = 0, b = text.slice(), fval, keysi = 0,
|
const b = text.slice();
|
||||||
|
let i = 0, fval, keysi = 0,
|
||||||
l, r, x; // left, right, accumulator
|
l, r, x; // left, right, accumulator
|
||||||
|
|
||||||
// Squash 8 bytes to 2 ints
|
// Squash 8 bytes to 2 ints
|
||||||
|
|
@ -271,6 +262,5 @@ export default function DES(passwd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
setKeys(passwd); // Setup keys
|
setKeys(passwd); // Setup keys
|
||||||
return {'encrypt': encrypt}; // Public interface
|
return { encrypt }; // Public interface
|
||||||
|
}
|
||||||
}; // function DES
|
|
||||||
|
|
|
||||||
619
core/display.js
619
core/display.js
|
|
@ -7,73 +7,10 @@
|
||||||
* See README.md for usage and integration instructions.
|
* See README.md for usage and integration instructions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint browser: true, white: false */
|
|
||||||
/*global Util, Base64, changeCursor */
|
|
||||||
|
|
||||||
import * as Log from './util/logging.js';
|
import * as Log from './util/logging.js';
|
||||||
import Base64 from "./base64.js";
|
import Base64 from "./base64.js";
|
||||||
|
|
||||||
export default function Display(target) {
|
let SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
|
||||||
this._drawCtx = null;
|
|
||||||
this._c_forceCanvas = false;
|
|
||||||
|
|
||||||
this._renderQ = []; // queue drawing actions for in-oder rendering
|
|
||||||
this._flushing = false;
|
|
||||||
|
|
||||||
// the full frame buffer (logical canvas) size
|
|
||||||
this._fb_width = 0;
|
|
||||||
this._fb_height = 0;
|
|
||||||
|
|
||||||
this._prevDrawStyle = "";
|
|
||||||
this._tile = null;
|
|
||||||
this._tile16x16 = null;
|
|
||||||
this._tile_x = 0;
|
|
||||||
this._tile_y = 0;
|
|
||||||
|
|
||||||
Log.Debug(">> Display.constructor");
|
|
||||||
|
|
||||||
// The visible canvas
|
|
||||||
this._target = target;
|
|
||||||
|
|
||||||
if (!this._target) {
|
|
||||||
throw new Error("Target must be set");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof this._target === 'string') {
|
|
||||||
throw new Error('target must be a DOM element');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this._target.getContext) {
|
|
||||||
throw new Error("no getContext method");
|
|
||||||
}
|
|
||||||
|
|
||||||
this._targetCtx = this._target.getContext('2d');
|
|
||||||
|
|
||||||
// the visible canvas viewport (i.e. what actually gets seen)
|
|
||||||
this._viewportLoc = { 'x': 0, 'y': 0, 'w': this._target.width, 'h': this._target.height };
|
|
||||||
|
|
||||||
// The hidden canvas, where we do the actual rendering
|
|
||||||
this._backbuffer = document.createElement('canvas');
|
|
||||||
this._drawCtx = this._backbuffer.getContext('2d');
|
|
||||||
|
|
||||||
this._damageBounds = { left:0, top:0,
|
|
||||||
right: this._backbuffer.width,
|
|
||||||
bottom: this._backbuffer.height };
|
|
||||||
|
|
||||||
Log.Debug("User Agent: " + navigator.userAgent);
|
|
||||||
|
|
||||||
this.clear();
|
|
||||||
|
|
||||||
// Check canvas features
|
|
||||||
if (!('createImageData' in this._drawCtx)) {
|
|
||||||
throw new Error("Canvas does not support createImageData");
|
|
||||||
}
|
|
||||||
|
|
||||||
this._tile16x16 = this._drawCtx.createImageData(16, 16);
|
|
||||||
Log.Debug("<< Display.constructor");
|
|
||||||
};
|
|
||||||
|
|
||||||
var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
|
|
||||||
try {
|
try {
|
||||||
new ImageData(new Uint8ClampedArray(4), 1, 1);
|
new ImageData(new Uint8ClampedArray(4), 1, 1);
|
||||||
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true;
|
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true;
|
||||||
|
|
@ -81,42 +18,106 @@ try {
|
||||||
// ignore failure
|
// ignore failure
|
||||||
}
|
}
|
||||||
|
|
||||||
Display.prototype = {
|
export default class Display {
|
||||||
|
constructor(target) {
|
||||||
|
this._drawCtx = null;
|
||||||
|
this._c_forceCanvas = false;
|
||||||
|
|
||||||
|
this._renderQ = []; // queue drawing actions for in-oder rendering
|
||||||
|
this._flushing = false;
|
||||||
|
|
||||||
|
// the full frame buffer (logical canvas) size
|
||||||
|
this._fb_width = 0;
|
||||||
|
this._fb_height = 0;
|
||||||
|
|
||||||
|
this._prevDrawStyle = "";
|
||||||
|
this._tile = null;
|
||||||
|
this._tile16x16 = null;
|
||||||
|
this._tile_x = 0;
|
||||||
|
this._tile_y = 0;
|
||||||
|
|
||||||
|
Log.Debug(">> Display.constructor");
|
||||||
|
|
||||||
|
// The visible canvas
|
||||||
|
this._target = target;
|
||||||
|
|
||||||
|
if (!this._target) {
|
||||||
|
throw new Error("Target must be set");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof this._target === 'string') {
|
||||||
|
throw new Error('target must be a DOM element');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._target.getContext) {
|
||||||
|
throw new Error("no getContext method");
|
||||||
|
}
|
||||||
|
|
||||||
|
this._targetCtx = this._target.getContext('2d');
|
||||||
|
|
||||||
|
// the visible canvas viewport (i.e. what actually gets seen)
|
||||||
|
this._viewportLoc = { 'x': 0, 'y': 0, 'w': this._target.width, 'h': this._target.height };
|
||||||
|
|
||||||
|
// The hidden canvas, where we do the actual rendering
|
||||||
|
this._backbuffer = document.createElement('canvas');
|
||||||
|
this._drawCtx = this._backbuffer.getContext('2d');
|
||||||
|
|
||||||
|
this._damageBounds = { left:0, top:0,
|
||||||
|
right: this._backbuffer.width,
|
||||||
|
bottom: this._backbuffer.height };
|
||||||
|
|
||||||
|
Log.Debug("User Agent: " + navigator.userAgent);
|
||||||
|
|
||||||
|
this.clear();
|
||||||
|
|
||||||
|
// Check canvas features
|
||||||
|
if (!('createImageData' in this._drawCtx)) {
|
||||||
|
throw new Error("Canvas does not support createImageData");
|
||||||
|
}
|
||||||
|
|
||||||
|
this._tile16x16 = this._drawCtx.createImageData(16, 16);
|
||||||
|
|
||||||
|
|
||||||
|
// ===== PROPERTIES =====
|
||||||
|
|
||||||
|
this._scale = 1.0;
|
||||||
|
this._clipViewport = false;
|
||||||
|
this.logo = null;
|
||||||
|
|
||||||
|
Log.Debug("<< Display.constructor");
|
||||||
|
}
|
||||||
|
|
||||||
// ===== PROPERTIES =====
|
// ===== PROPERTIES =====
|
||||||
|
|
||||||
_scale: 1.0,
|
get scale() { return this._scale; }
|
||||||
get scale() { return this._scale; },
|
|
||||||
set scale(scale) {
|
set scale(scale) {
|
||||||
this._rescale(scale);
|
this._rescale(scale);
|
||||||
},
|
}
|
||||||
|
|
||||||
_clipViewport: false,
|
get clipViewport() { return this._clipViewport; }
|
||||||
get clipViewport() { return this._clipViewport; },
|
|
||||||
set clipViewport(viewport) {
|
set clipViewport(viewport) {
|
||||||
this._clipViewport = viewport;
|
this._clipViewport = viewport;
|
||||||
// May need to readjust the viewport dimensions
|
// May need to readjust the viewport dimensions
|
||||||
var vp = this._viewportLoc;
|
const vp = this._viewportLoc;
|
||||||
this.viewportChangeSize(vp.w, vp.h);
|
this.viewportChangeSize(vp.w, vp.h);
|
||||||
this.viewportChangePos(0, 0);
|
this.viewportChangePos(0, 0);
|
||||||
},
|
}
|
||||||
|
|
||||||
get width() {
|
get width() {
|
||||||
return this._fb_width;
|
return this._fb_width;
|
||||||
},
|
}
|
||||||
get height() {
|
get height() {
|
||||||
return this._fb_height;
|
return this._fb_height;
|
||||||
},
|
}
|
||||||
|
|
||||||
logo: null,
|
|
||||||
|
|
||||||
// ===== EVENT HANDLERS =====
|
// ===== EVENT HANDLERS =====
|
||||||
|
|
||||||
onflush: function () {}, // A flush request has finished
|
onflush() {} // A flush request has finished
|
||||||
|
|
||||||
// ===== PUBLIC METHODS =====
|
// ===== PUBLIC METHODS =====
|
||||||
|
|
||||||
viewportChangePos: function (deltaX, deltaY) {
|
viewportChangePos(deltaX, deltaY) {
|
||||||
var vp = this._viewportLoc;
|
const vp = this._viewportLoc;
|
||||||
deltaX = Math.floor(deltaX);
|
deltaX = Math.floor(deltaX);
|
||||||
deltaY = Math.floor(deltaY);
|
deltaY = Math.floor(deltaY);
|
||||||
|
|
||||||
|
|
@ -125,8 +126,8 @@ Display.prototype = {
|
||||||
deltaY = -vp.h;
|
deltaY = -vp.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
var vx2 = vp.x + vp.w - 1;
|
const vx2 = vp.x + vp.w - 1;
|
||||||
var vy2 = vp.y + vp.h - 1;
|
const vy2 = vp.y + vp.h - 1;
|
||||||
|
|
||||||
// Position change
|
// Position change
|
||||||
|
|
||||||
|
|
@ -155,10 +156,9 @@ Display.prototype = {
|
||||||
this._damage(vp.x, vp.y, vp.w, vp.h);
|
this._damage(vp.x, vp.y, vp.w, vp.h);
|
||||||
|
|
||||||
this.flip();
|
this.flip();
|
||||||
},
|
}
|
||||||
|
|
||||||
viewportChangeSize: function(width, height) {
|
|
||||||
|
|
||||||
|
viewportChangeSize(width, height) {
|
||||||
if (!this._clipViewport ||
|
if (!this._clipViewport ||
|
||||||
typeof(width) === "undefined" ||
|
typeof(width) === "undefined" ||
|
||||||
typeof(height) === "undefined") {
|
typeof(height) === "undefined") {
|
||||||
|
|
@ -175,12 +175,12 @@ Display.prototype = {
|
||||||
height = this._fb_height;
|
height = this._fb_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
var vp = this._viewportLoc;
|
const vp = this._viewportLoc;
|
||||||
if (vp.w !== width || vp.h !== height) {
|
if (vp.w !== width || vp.h !== height) {
|
||||||
vp.w = width;
|
vp.w = width;
|
||||||
vp.h = height;
|
vp.h = height;
|
||||||
|
|
||||||
var canvas = this._target;
|
const canvas = this._target;
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
canvas.height = height;
|
canvas.height = height;
|
||||||
|
|
||||||
|
|
@ -193,27 +193,27 @@ Display.prototype = {
|
||||||
// Update the visible size of the target canvas
|
// Update the visible size of the target canvas
|
||||||
this._rescale(this._scale);
|
this._rescale(this._scale);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
absX: function (x) {
|
absX(x) {
|
||||||
return x / this._scale + this._viewportLoc.x;
|
return x / this._scale + this._viewportLoc.x;
|
||||||
},
|
}
|
||||||
|
|
||||||
absY: function (y) {
|
absY(y) {
|
||||||
return y / this._scale + this._viewportLoc.y;
|
return y / this._scale + this._viewportLoc.y;
|
||||||
},
|
}
|
||||||
|
|
||||||
resize: function (width, height) {
|
resize(width, height) {
|
||||||
this._prevDrawStyle = "";
|
this._prevDrawStyle = "";
|
||||||
|
|
||||||
this._fb_width = width;
|
this._fb_width = width;
|
||||||
this._fb_height = height;
|
this._fb_height = height;
|
||||||
|
|
||||||
var canvas = this._backbuffer;
|
const canvas = this._backbuffer;
|
||||||
if (canvas.width !== width || canvas.height !== height) {
|
if (canvas.width !== width || canvas.height !== height) {
|
||||||
|
|
||||||
// We have to save the canvas data since changing the size will clear it
|
// We have to save the canvas data since changing the size will clear it
|
||||||
var saveImg = null;
|
let saveImg = null;
|
||||||
if (canvas.width > 0 && canvas.height > 0) {
|
if (canvas.width > 0 && canvas.height > 0) {
|
||||||
saveImg = this._drawCtx.getImageData(0, 0, canvas.width, canvas.height);
|
saveImg = this._drawCtx.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
}
|
}
|
||||||
|
|
@ -232,13 +232,13 @@ Display.prototype = {
|
||||||
|
|
||||||
// Readjust the viewport as it may be incorrectly sized
|
// Readjust the viewport as it may be incorrectly sized
|
||||||
// and positioned
|
// and positioned
|
||||||
var vp = this._viewportLoc;
|
const vp = this._viewportLoc;
|
||||||
this.viewportChangeSize(vp.w, vp.h);
|
this.viewportChangeSize(vp.w, vp.h);
|
||||||
this.viewportChangePos(0, 0);
|
this.viewportChangePos(0, 0);
|
||||||
},
|
}
|
||||||
|
|
||||||
// Track what parts of the visible canvas that need updating
|
// Track what parts of the visible canvas that need updating
|
||||||
_damage: function(x, y, w, h) {
|
_damage(x, y, w, h) {
|
||||||
if (x < this._damageBounds.left) {
|
if (x < this._damageBounds.left) {
|
||||||
this._damageBounds.left = x;
|
this._damageBounds.left = x;
|
||||||
}
|
}
|
||||||
|
|
@ -251,59 +251,58 @@ Display.prototype = {
|
||||||
if ((y + h) > this._damageBounds.bottom) {
|
if ((y + h) > this._damageBounds.bottom) {
|
||||||
this._damageBounds.bottom = y + h;
|
this._damageBounds.bottom = y + h;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Update the visible canvas with the contents of the
|
// Update the visible canvas with the contents of the
|
||||||
// rendering canvas
|
// rendering canvas
|
||||||
flip: function(from_queue) {
|
flip(from_queue) {
|
||||||
if (this._renderQ.length !== 0 && !from_queue) {
|
if (this._renderQ.length !== 0 && !from_queue) {
|
||||||
this._renderQ_push({
|
this._renderQ_push({
|
||||||
'type': 'flip'
|
'type': 'flip'
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
var x, y, vx, vy, w, h;
|
|
||||||
|
|
||||||
x = this._damageBounds.left;
|
|
||||||
y = this._damageBounds.top;
|
|
||||||
w = this._damageBounds.right - x;
|
|
||||||
h = this._damageBounds.bottom - y;
|
|
||||||
|
|
||||||
vx = x - this._viewportLoc.x;
|
|
||||||
vy = y - this._viewportLoc.y;
|
|
||||||
|
|
||||||
if (vx < 0) {
|
|
||||||
w += vx;
|
|
||||||
x -= vx;
|
|
||||||
vx = 0;
|
|
||||||
}
|
|
||||||
if (vy < 0) {
|
|
||||||
h += vy;
|
|
||||||
y -= vy;
|
|
||||||
vy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((vx + w) > this._viewportLoc.w) {
|
|
||||||
w = this._viewportLoc.w - vx;
|
|
||||||
}
|
|
||||||
if ((vy + h) > this._viewportLoc.h) {
|
|
||||||
h = this._viewportLoc.h - vy;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((w > 0) && (h > 0)) {
|
|
||||||
// FIXME: We may need to disable image smoothing here
|
|
||||||
// as well (see copyImage()), but we haven't
|
|
||||||
// noticed any problem yet.
|
|
||||||
this._targetCtx.drawImage(this._backbuffer,
|
|
||||||
x, y, w, h,
|
|
||||||
vx, vy, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._damageBounds.left = this._damageBounds.top = 65535;
|
|
||||||
this._damageBounds.right = this._damageBounds.bottom = 0;
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
clear: function () {
|
let x = this._damageBounds.left;
|
||||||
|
let y = this._damageBounds.top;
|
||||||
|
let w = this._damageBounds.right - x;
|
||||||
|
let h = this._damageBounds.bottom - y;
|
||||||
|
|
||||||
|
let vx = x - this._viewportLoc.x;
|
||||||
|
let vy = y - this._viewportLoc.y;
|
||||||
|
|
||||||
|
if (vx < 0) {
|
||||||
|
w += vx;
|
||||||
|
x -= vx;
|
||||||
|
vx = 0;
|
||||||
|
}
|
||||||
|
if (vy < 0) {
|
||||||
|
h += vy;
|
||||||
|
y -= vy;
|
||||||
|
vy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((vx + w) > this._viewportLoc.w) {
|
||||||
|
w = this._viewportLoc.w - vx;
|
||||||
|
}
|
||||||
|
if ((vy + h) > this._viewportLoc.h) {
|
||||||
|
h = this._viewportLoc.h - vy;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((w > 0) && (h > 0)) {
|
||||||
|
// FIXME: We may need to disable image smoothing here
|
||||||
|
// as well (see copyImage()), but we haven't
|
||||||
|
// noticed any problem yet.
|
||||||
|
this._targetCtx.drawImage(this._backbuffer,
|
||||||
|
x, y, w, h,
|
||||||
|
vx, vy, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._damageBounds.left = this._damageBounds.top = 65535;
|
||||||
|
this._damageBounds.right = this._damageBounds.bottom = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
if (this._logo) {
|
if (this._logo) {
|
||||||
this.resize(this._logo.width, this._logo.height);
|
this.resize(this._logo.width, this._logo.height);
|
||||||
this.imageRect(0, 0, this._logo.type, this._logo.data);
|
this.imageRect(0, 0, this._logo.type, this._logo.data);
|
||||||
|
|
@ -312,21 +311,21 @@ Display.prototype = {
|
||||||
this._drawCtx.clearRect(0, 0, this._fb_width, this._fb_height);
|
this._drawCtx.clearRect(0, 0, this._fb_width, this._fb_height);
|
||||||
}
|
}
|
||||||
this.flip();
|
this.flip();
|
||||||
},
|
}
|
||||||
|
|
||||||
pending: function() {
|
pending() {
|
||||||
return this._renderQ.length > 0;
|
return this._renderQ.length > 0;
|
||||||
},
|
}
|
||||||
|
|
||||||
flush: function() {
|
flush() {
|
||||||
if (this._renderQ.length === 0) {
|
if (this._renderQ.length === 0) {
|
||||||
this.onflush();
|
this.onflush();
|
||||||
} else {
|
} else {
|
||||||
this._flushing = true;
|
this._flushing = true;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
fillRect: function (x, y, width, height, color, from_queue) {
|
fillRect(x, y, width, height, color, from_queue) {
|
||||||
if (this._renderQ.length !== 0 && !from_queue) {
|
if (this._renderQ.length !== 0 && !from_queue) {
|
||||||
this._renderQ_push({
|
this._renderQ_push({
|
||||||
'type': 'fill',
|
'type': 'fill',
|
||||||
|
|
@ -341,9 +340,9 @@ Display.prototype = {
|
||||||
this._drawCtx.fillRect(x, y, width, height);
|
this._drawCtx.fillRect(x, y, width, height);
|
||||||
this._damage(x, y, width, height);
|
this._damage(x, y, width, height);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
copyImage: function (old_x, old_y, new_x, new_y, w, h, from_queue) {
|
copyImage(old_x, old_y, new_x, new_y, w, h, from_queue) {
|
||||||
if (this._renderQ.length !== 0 && !from_queue) {
|
if (this._renderQ.length !== 0 && !from_queue) {
|
||||||
this._renderQ_push({
|
this._renderQ_push({
|
||||||
'type': 'copy',
|
'type': 'copy',
|
||||||
|
|
@ -372,10 +371,10 @@ Display.prototype = {
|
||||||
new_x, new_y, w, h);
|
new_x, new_y, w, h);
|
||||||
this._damage(new_x, new_y, w, h);
|
this._damage(new_x, new_y, w, h);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
imageRect: function(x, y, mime, arr) {
|
imageRect(x, y, mime, arr) {
|
||||||
var img = new Image();
|
const img = new Image();
|
||||||
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
|
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
|
||||||
this._renderQ_push({
|
this._renderQ_push({
|
||||||
'type': 'img',
|
'type': 'img',
|
||||||
|
|
@ -383,10 +382,10 @@ Display.prototype = {
|
||||||
'x': x,
|
'x': x,
|
||||||
'y': y
|
'y': y
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
// start updating a tile
|
// start updating a tile
|
||||||
startTile: function (x, y, width, height, color) {
|
startTile(x, y, width, height, color) {
|
||||||
this._tile_x = x;
|
this._tile_x = x;
|
||||||
this._tile_y = y;
|
this._tile_y = y;
|
||||||
if (width === 16 && height === 16) {
|
if (width === 16 && height === 16) {
|
||||||
|
|
@ -395,171 +394,172 @@ Display.prototype = {
|
||||||
this._tile = this._drawCtx.createImageData(width, height);
|
this._tile = this._drawCtx.createImageData(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
var red = color[2];
|
const red = color[2];
|
||||||
var green = color[1];
|
const green = color[1];
|
||||||
var blue = color[0];
|
const blue = color[0];
|
||||||
|
|
||||||
var data = this._tile.data;
|
const data = this._tile.data;
|
||||||
for (var i = 0; i < width * height * 4; i += 4) {
|
for (let i = 0; i < width * height * 4; i += 4) {
|
||||||
data[i] = red;
|
data[i] = red;
|
||||||
data[i + 1] = green;
|
data[i + 1] = green;
|
||||||
data[i + 2] = blue;
|
data[i + 2] = blue;
|
||||||
data[i + 3] = 255;
|
data[i + 3] = 255;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// update sub-rectangle of the current tile
|
// update sub-rectangle of the current tile
|
||||||
subTile: function (x, y, w, h, color) {
|
subTile(x, y, w, h, color) {
|
||||||
var red = color[2];
|
const red = color[2];
|
||||||
var green = color[1];
|
const green = color[1];
|
||||||
var blue = color[0];
|
const blue = color[0];
|
||||||
var xend = x + w;
|
const xend = x + w;
|
||||||
var yend = y + h;
|
const yend = y + h;
|
||||||
|
|
||||||
var data = this._tile.data;
|
const data = this._tile.data;
|
||||||
var width = this._tile.width;
|
const width = this._tile.width;
|
||||||
for (var j = y; j < yend; j++) {
|
for (let j = y; j < yend; j++) {
|
||||||
for (var i = x; i < xend; i++) {
|
for (let i = x; i < xend; i++) {
|
||||||
var p = (i + (j * width)) * 4;
|
const p = (i + (j * width)) * 4;
|
||||||
data[p] = red;
|
data[p] = red;
|
||||||
data[p + 1] = green;
|
data[p + 1] = green;
|
||||||
data[p + 2] = blue;
|
data[p + 2] = blue;
|
||||||
data[p + 3] = 255;
|
data[p + 3] = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// draw the current tile to the screen
|
// draw the current tile to the screen
|
||||||
finishTile: function () {
|
finishTile() {
|
||||||
this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y);
|
this._drawCtx.putImageData(this._tile, this._tile_x, this._tile_y);
|
||||||
this._damage(this._tile_x, this._tile_y,
|
this._damage(this._tile_x, this._tile_y,
|
||||||
this._tile.width, this._tile.height);
|
this._tile.width, this._tile.height);
|
||||||
},
|
}
|
||||||
|
|
||||||
blitImage: function (x, y, width, height, arr, offset, from_queue) {
|
blitImage(x, y, width, height, arr, offset, from_queue) {
|
||||||
if (this._renderQ.length !== 0 && !from_queue) {
|
if (this._renderQ.length === 0 || from_queue) {
|
||||||
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
||||||
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
||||||
// this probably isn't getting called *nearly* as much
|
|
||||||
var new_arr = new Uint8Array(width * height * 4);
|
|
||||||
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
|
||||||
this._renderQ_push({
|
|
||||||
'type': 'blit',
|
|
||||||
'data': new_arr,
|
|
||||||
'x': x,
|
|
||||||
'y': y,
|
|
||||||
'width': width,
|
|
||||||
'height': height,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this._bgrxImageData(x, y, width, height, arr, offset);
|
this._bgrxImageData(x, y, width, height, arr, offset);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
blitRgbImage: function (x, y , width, height, arr, offset, from_queue) {
|
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
||||||
if (this._renderQ.length !== 0 && !from_queue) {
|
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
||||||
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
// this probably isn't getting called *nearly* as much
|
||||||
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
const new_arr = new Uint8Array(width * height * 4);
|
||||||
// this probably isn't getting called *nearly* as much
|
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
||||||
var new_arr = new Uint8Array(width * height * 3);
|
this._renderQ_push({
|
||||||
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
'type': 'blit',
|
||||||
this._renderQ_push({
|
'data': new_arr,
|
||||||
'type': 'blitRgb',
|
'x': x,
|
||||||
'data': new_arr,
|
'y': y,
|
||||||
'x': x,
|
'width': width,
|
||||||
'y': y,
|
'height': height,
|
||||||
'width': width,
|
});
|
||||||
'height': height,
|
}
|
||||||
});
|
|
||||||
} else {
|
blitRgbImage(x, y , width, height, arr, offset, from_queue) {
|
||||||
|
if (this._renderQ.length === 0 || from_queue) {
|
||||||
this._rgbImageData(x, y, width, height, arr, offset);
|
this._rgbImageData(x, y, width, height, arr, offset);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
blitRgbxImage: function (x, y, width, height, arr, offset, from_queue) {
|
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
||||||
if (this._renderQ.length !== 0 && !from_queue) {
|
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
||||||
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
// this probably isn't getting called *nearly* as much
|
||||||
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
const new_arr = new Uint8Array(width * height * 3);
|
||||||
// this probably isn't getting called *nearly* as much
|
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
||||||
var new_arr = new Uint8Array(width * height * 4);
|
this._renderQ_push({
|
||||||
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
'type': 'blitRgb',
|
||||||
this._renderQ_push({
|
'data': new_arr,
|
||||||
'type': 'blitRgbx',
|
'x': x,
|
||||||
'data': new_arr,
|
'y': y,
|
||||||
'x': x,
|
'width': width,
|
||||||
'y': y,
|
'height': height,
|
||||||
'width': width,
|
});
|
||||||
'height': height,
|
}
|
||||||
});
|
|
||||||
} else {
|
blitRgbxImage(x, y, width, height, arr, offset, from_queue) {
|
||||||
|
if (this._renderQ.length === 0 || from_queue) {
|
||||||
this._rgbxImageData(x, y, width, height, arr, offset);
|
this._rgbxImageData(x, y, width, height, arr, offset);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
drawImage: function (img, x, y) {
|
|
||||||
|
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
||||||
|
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
||||||
|
// this probably isn't getting called *nearly* as much
|
||||||
|
const new_arr = new Uint8Array(width * height * 4);
|
||||||
|
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
|
||||||
|
this._renderQ_push({
|
||||||
|
'type': 'blitRgbx',
|
||||||
|
'data': new_arr,
|
||||||
|
'x': x,
|
||||||
|
'y': y,
|
||||||
|
'width': width,
|
||||||
|
'height': height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
drawImage(img, x, y) {
|
||||||
this._drawCtx.drawImage(img, x, y);
|
this._drawCtx.drawImage(img, x, y);
|
||||||
this._damage(x, y, img.width, img.height);
|
this._damage(x, y, img.width, img.height);
|
||||||
},
|
}
|
||||||
|
|
||||||
changeCursor: function (pixels, mask, hotx, hoty, w, h) {
|
changeCursor(pixels, mask, hotx, hoty, w, h) {
|
||||||
Display.changeCursor(this._target, pixels, mask, hotx, hoty, w, h);
|
Display.changeCursor(this._target, pixels, mask, hotx, hoty, w, h);
|
||||||
},
|
}
|
||||||
|
|
||||||
defaultCursor: function () {
|
defaultCursor() {
|
||||||
this._target.style.cursor = "default";
|
this._target.style.cursor = "default";
|
||||||
},
|
}
|
||||||
|
|
||||||
disableLocalCursor: function () {
|
disableLocalCursor() {
|
||||||
this._target.style.cursor = "none";
|
this._target.style.cursor = "none";
|
||||||
},
|
}
|
||||||
|
|
||||||
autoscale: function (containerWidth, containerHeight) {
|
autoscale(containerWidth, containerHeight) {
|
||||||
var vp = this._viewportLoc;
|
const vp = this._viewportLoc;
|
||||||
var targetAspectRatio = containerWidth / containerHeight;
|
const targetAspectRatio = containerWidth / containerHeight;
|
||||||
var fbAspectRatio = vp.w / vp.h;
|
const fbAspectRatio = vp.w / vp.h;
|
||||||
|
|
||||||
var scaleRatio;
|
const scaleRatio = (fbAspectRatio >= targetAspectRatio)
|
||||||
if (fbAspectRatio >= targetAspectRatio) {
|
? containerWidth / vp.w
|
||||||
scaleRatio = containerWidth / vp.w;
|
: containerHeight / vp.h;
|
||||||
} else {
|
|
||||||
scaleRatio = containerHeight / vp.h;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._rescale(scaleRatio);
|
this._rescale(scaleRatio);
|
||||||
},
|
}
|
||||||
|
|
||||||
// ===== PRIVATE METHODS =====
|
// ===== PRIVATE METHODS =====
|
||||||
|
|
||||||
_rescale: function (factor) {
|
_rescale(factor) {
|
||||||
this._scale = factor;
|
this._scale = factor;
|
||||||
var vp = this._viewportLoc;
|
const vp = this._viewportLoc;
|
||||||
|
|
||||||
// NB(directxman12): If you set the width directly, or set the
|
// NB(directxman12): If you set the width directly, or set the
|
||||||
// style width to a number, the canvas is cleared.
|
// style width to a number, the canvas is cleared.
|
||||||
// However, if you set the style width to a string
|
// However, if you set the style width to a string
|
||||||
// ('NNNpx'), the canvas is scaled without clearing.
|
// ('NNNpx'), the canvas is scaled without clearing.
|
||||||
var width = Math.round(factor * vp.w) + 'px';
|
const width = Math.round(factor * vp.w) + 'px';
|
||||||
var height = Math.round(factor * vp.h) + 'px';
|
const height = Math.round(factor * vp.h) + 'px';
|
||||||
|
|
||||||
if ((this._target.style.width !== width) ||
|
if ((this._target.style.width !== width) ||
|
||||||
(this._target.style.height !== height)) {
|
(this._target.style.height !== height)) {
|
||||||
this._target.style.width = width;
|
this._target.style.width = width;
|
||||||
this._target.style.height = height;
|
this._target.style.height = height;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_setFillColor: function (color) {
|
_setFillColor(color) {
|
||||||
var newStyle = 'rgb(' + color[2] + ',' + color[1] + ',' + color[0] + ')';
|
const newStyle = 'rgb(' + color[2] + ',' + color[1] + ',' + color[0] + ')';
|
||||||
if (newStyle !== this._prevDrawStyle) {
|
if (newStyle !== this._prevDrawStyle) {
|
||||||
this._drawCtx.fillStyle = newStyle;
|
this._drawCtx.fillStyle = newStyle;
|
||||||
this._prevDrawStyle = newStyle;
|
this._prevDrawStyle = newStyle;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_rgbImageData: function (x, y, width, height, arr, offset) {
|
_rgbImageData(x, y, width, height, arr, offset) {
|
||||||
var img = this._drawCtx.createImageData(width, height);
|
const img = this._drawCtx.createImageData(width, height);
|
||||||
var data = img.data;
|
const data = img.data;
|
||||||
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 3) {
|
for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 3) {
|
||||||
data[i] = arr[j];
|
data[i] = arr[j];
|
||||||
data[i + 1] = arr[j + 1];
|
data[i + 1] = arr[j + 1];
|
||||||
data[i + 2] = arr[j + 2];
|
data[i + 2] = arr[j + 2];
|
||||||
|
|
@ -567,12 +567,12 @@ Display.prototype = {
|
||||||
}
|
}
|
||||||
this._drawCtx.putImageData(img, x, y);
|
this._drawCtx.putImageData(img, x, y);
|
||||||
this._damage(x, y, img.width, img.height);
|
this._damage(x, y, img.width, img.height);
|
||||||
},
|
}
|
||||||
|
|
||||||
_bgrxImageData: function (x, y, width, height, arr, offset) {
|
_bgrxImageData(x, y, width, height, arr, offset) {
|
||||||
var img = this._drawCtx.createImageData(width, height);
|
const img = this._drawCtx.createImageData(width, height);
|
||||||
var data = img.data;
|
const data = img.data;
|
||||||
for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
|
for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 4) {
|
||||||
data[i] = arr[j + 2];
|
data[i] = arr[j + 2];
|
||||||
data[i + 1] = arr[j + 1];
|
data[i + 1] = arr[j + 1];
|
||||||
data[i + 2] = arr[j];
|
data[i + 2] = arr[j];
|
||||||
|
|
@ -580,11 +580,11 @@ Display.prototype = {
|
||||||
}
|
}
|
||||||
this._drawCtx.putImageData(img, x, y);
|
this._drawCtx.putImageData(img, x, y);
|
||||||
this._damage(x, y, img.width, img.height);
|
this._damage(x, y, img.width, img.height);
|
||||||
},
|
}
|
||||||
|
|
||||||
_rgbxImageData: function (x, y, width, height, arr, offset) {
|
_rgbxImageData(x, y, width, height, arr) {
|
||||||
// NB(directxman12): arr must be an Type Array view
|
// NB(directxman12): arr must be an Type Array view
|
||||||
var img;
|
let img;
|
||||||
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
|
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
|
||||||
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
|
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -593,28 +593,28 @@ Display.prototype = {
|
||||||
}
|
}
|
||||||
this._drawCtx.putImageData(img, x, y);
|
this._drawCtx.putImageData(img, x, y);
|
||||||
this._damage(x, y, img.width, img.height);
|
this._damage(x, y, img.width, img.height);
|
||||||
},
|
}
|
||||||
|
|
||||||
_renderQ_push: function (action) {
|
_renderQ_push(action) {
|
||||||
this._renderQ.push(action);
|
this._renderQ.push(action);
|
||||||
if (this._renderQ.length === 1) {
|
if (this._renderQ.length === 1) {
|
||||||
// If this can be rendered immediately it will be, otherwise
|
// If this can be rendered immediately it will be, otherwise
|
||||||
// the scanner will wait for the relevant event
|
// the scanner will wait for the relevant event
|
||||||
this._scan_renderQ();
|
this._scan_renderQ();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_resume_renderQ: function() {
|
_resume_renderQ() {
|
||||||
// "this" is the object that is ready, not the
|
// "this" is the object that is ready, not the
|
||||||
// display object
|
// display object
|
||||||
this.removeEventListener('load', this._noVNC_display._resume_renderQ);
|
this.removeEventListener('load', this._noVNC_display._resume_renderQ);
|
||||||
this._noVNC_display._scan_renderQ();
|
this._noVNC_display._scan_renderQ();
|
||||||
},
|
}
|
||||||
|
|
||||||
_scan_renderQ: function () {
|
_scan_renderQ() {
|
||||||
var ready = true;
|
let ready = true;
|
||||||
while (ready && this._renderQ.length > 0) {
|
while (ready && this._renderQ.length > 0) {
|
||||||
var a = this._renderQ[0];
|
const a = this._renderQ[0];
|
||||||
switch (a.type) {
|
switch (a.type) {
|
||||||
case 'flip':
|
case 'flip':
|
||||||
this.flip(true);
|
this.flip(true);
|
||||||
|
|
@ -656,46 +656,45 @@ Display.prototype = {
|
||||||
this._flushing = false;
|
this._flushing = false;
|
||||||
this.onflush();
|
this.onflush();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Class Methods
|
|
||||||
Display.changeCursor = function (target, pixels, mask, hotx, hoty, w, h) {
|
|
||||||
if ((w === 0) || (h === 0)) {
|
|
||||||
target.style.cursor = 'none';
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var cur = []
|
static changeCursor(target, pixels, mask, hotx, hoty, w, h) {
|
||||||
var y, x;
|
if ((w === 0) || (h === 0)) {
|
||||||
for (y = 0; y < h; y++) {
|
target.style.cursor = 'none';
|
||||||
for (x = 0; x < w; x++) {
|
return;
|
||||||
var idx = y * Math.ceil(w / 8) + Math.floor(x / 8);
|
|
||||||
var alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
|
|
||||||
idx = ((w * y) + x) * 4;
|
|
||||||
cur.push(pixels[idx + 2]); // red
|
|
||||||
cur.push(pixels[idx + 1]); // green
|
|
||||||
cur.push(pixels[idx]); // blue
|
|
||||||
cur.push(alpha); // alpha
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cur = [];
|
||||||
|
for (let y = 0; y < h; y++) {
|
||||||
|
for (let x = 0; x < w; x++) {
|
||||||
|
let idx = y * Math.ceil(w / 8) + Math.floor(x / 8);
|
||||||
|
const alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
|
||||||
|
idx = ((w * y) + x) * 4;
|
||||||
|
cur.push(pixels[idx + 2]); // red
|
||||||
|
cur.push(pixels[idx + 1]); // green
|
||||||
|
cur.push(pixels[idx]); // blue
|
||||||
|
cur.push(alpha); // alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
canvas.width = w;
|
||||||
|
canvas.height = h;
|
||||||
|
|
||||||
|
let img;
|
||||||
|
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
|
||||||
|
img = new ImageData(new Uint8ClampedArray(cur), w, h);
|
||||||
|
} else {
|
||||||
|
img = ctx.createImageData(w, h);
|
||||||
|
img.data.set(new Uint8ClampedArray(cur));
|
||||||
|
}
|
||||||
|
ctx.clearRect(0, 0, w, h);
|
||||||
|
ctx.putImageData(img, 0, 0);
|
||||||
|
|
||||||
|
const url = canvas.toDataURL();
|
||||||
|
target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var canvas = document.createElement('canvas');
|
|
||||||
var ctx = canvas.getContext('2d');
|
|
||||||
|
|
||||||
canvas.width = w;
|
|
||||||
canvas.height = h;
|
|
||||||
|
|
||||||
var img;
|
|
||||||
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
|
|
||||||
img = new ImageData(new Uint8ClampedArray(cur), w, h);
|
|
||||||
} else {
|
|
||||||
img = ctx.createImageData(w, h);
|
|
||||||
img.data.set(new Uint8ClampedArray(cur));
|
|
||||||
}
|
|
||||||
ctx.clearRect(0, 0, w, h);
|
|
||||||
ctx.putImageData(img, 0, 0);
|
|
||||||
|
|
||||||
var url = canvas.toDataURL();
|
|
||||||
target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default';
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
* See README.md for usage and integration instructions.
|
* See README.md for usage and integration instructions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export var encodings = {
|
export let encodings = {
|
||||||
encodingRaw: 0,
|
encodingRaw: 0,
|
||||||
encodingCopyRect: 1,
|
encodingCopyRect: 1,
|
||||||
encodingRRE: 2,
|
encodingRRE: 2,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,17 @@
|
||||||
import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
|
import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
|
||||||
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
||||||
|
|
||||||
Inflate.prototype = {
|
export default class Inflate {
|
||||||
inflate: function (data, flush, expected) {
|
constructor() {
|
||||||
|
this.strm = new ZStream();
|
||||||
|
this.chunkSize = 1024 * 10 * 10;
|
||||||
|
this.strm.output = new Uint8Array(this.chunkSize);
|
||||||
|
this.windowBits = 5;
|
||||||
|
|
||||||
|
inflateInit(this.strm, this.windowBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
inflate(data, flush, expected) {
|
||||||
this.strm.input = data;
|
this.strm.input = data;
|
||||||
this.strm.avail_in = this.strm.input.length;
|
this.strm.avail_in = this.strm.input.length;
|
||||||
this.strm.next_in = 0;
|
this.strm.next_in = 0;
|
||||||
|
|
@ -21,18 +30,9 @@ Inflate.prototype = {
|
||||||
inflate(this.strm, flush);
|
inflate(this.strm, flush);
|
||||||
|
|
||||||
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
|
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
|
||||||
},
|
}
|
||||||
|
|
||||||
reset: function () {
|
reset() {
|
||||||
inflateReset(this.strm);
|
inflateReset(this.strm);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default function Inflate() {
|
|
||||||
this.strm = new ZStream();
|
|
||||||
this.chunkSize = 1024 * 10 * 10;
|
|
||||||
this.strm.output = new Uint8Array(this.chunkSize);
|
|
||||||
this.windowBits = 5;
|
|
||||||
|
|
||||||
inflateInit(this.strm, this.windowBits);
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import KeyTable from "./keysym.js";
|
||||||
* See https://www.w3.org/TR/uievents-key/ for possible values.
|
* See https://www.w3.org/TR/uievents-key/ for possible values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var DOMKeyTable = {};
|
const DOMKeyTable = {};
|
||||||
|
|
||||||
function addStandard(key, standard)
|
function addStandard(key, standard)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,61 +5,40 @@
|
||||||
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint browser: true, white: false */
|
|
||||||
/*global window, Util */
|
|
||||||
|
|
||||||
import * as Log from '../util/logging.js';
|
import * as Log from '../util/logging.js';
|
||||||
import { stopEvent } from '../util/events.js';
|
import { stopEvent } from '../util/events.js';
|
||||||
import * as KeyboardUtil from "./util.js";
|
import * as KeyboardUtil from "./util.js";
|
||||||
import KeyTable from "./keysym.js";
|
import KeyTable from "./keysym.js";
|
||||||
|
import * as browserUtils from "../util/browsers.js";
|
||||||
|
|
||||||
//
|
//
|
||||||
// Keyboard event handler
|
// Keyboard event handler
|
||||||
//
|
//
|
||||||
|
|
||||||
export default function Keyboard(target) {
|
export default class Keyboard {
|
||||||
this._target = target || null;
|
constructor(target) {
|
||||||
|
this._target = target || null;
|
||||||
|
|
||||||
this._keyDownList = {}; // List of depressed keys
|
this._keyDownList = {}; // List of depressed keys
|
||||||
// (even if they are happy)
|
// (even if they are happy)
|
||||||
this._pendingKey = null; // Key waiting for keypress
|
this._pendingKey = null; // Key waiting for keypress
|
||||||
|
|
||||||
// keep these here so we can refer to them later
|
// keep these here so we can refer to them later
|
||||||
this._eventHandlers = {
|
this._eventHandlers = {
|
||||||
'keyup': this._handleKeyUp.bind(this),
|
'keyup': this._handleKeyUp.bind(this),
|
||||||
'keydown': this._handleKeyDown.bind(this),
|
'keydown': this._handleKeyDown.bind(this),
|
||||||
'keypress': this._handleKeyPress.bind(this),
|
'keypress': this._handleKeyPress.bind(this),
|
||||||
'blur': this._allKeysUp.bind(this)
|
'blur': this._allKeysUp.bind(this)
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function isMac() {
|
|
||||||
return navigator && !!(/mac/i).exec(navigator.platform);
|
|
||||||
}
|
|
||||||
function isWindows() {
|
|
||||||
return navigator && !!(/win/i).exec(navigator.platform);
|
|
||||||
}
|
|
||||||
function isIOS() {
|
|
||||||
return navigator &&
|
|
||||||
(!!(/ipad/i).exec(navigator.platform) ||
|
|
||||||
!!(/iphone/i).exec(navigator.platform) ||
|
|
||||||
!!(/ipod/i).exec(navigator.platform));
|
|
||||||
}
|
|
||||||
function isIE() {
|
|
||||||
return navigator && !!(/trident/i).exec(navigator.userAgent);
|
|
||||||
}
|
|
||||||
function isEdge() {
|
|
||||||
return navigator && !!(/edge/i).exec(navigator.userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Keyboard.prototype = {
|
|
||||||
// ===== EVENT HANDLERS =====
|
// ===== EVENT HANDLERS =====
|
||||||
|
|
||||||
onkeyevent: function () {}, // Handler for key press/release
|
onkeyevent() {} // Handler for key press/release
|
||||||
|
|
||||||
// ===== PRIVATE METHODS =====
|
// ===== PRIVATE METHODS =====
|
||||||
|
|
||||||
_sendKeyEvent: function (keysym, code, down) {
|
_sendKeyEvent(keysym, code, down) {
|
||||||
Log.Debug("onkeyevent " + (down ? "down" : "up") +
|
Log.Debug("onkeyevent " + (down ? "down" : "up") +
|
||||||
", keysym: " + keysym, ", code: " + code);
|
", keysym: " + keysym, ", code: " + code);
|
||||||
|
|
||||||
|
|
@ -67,8 +46,8 @@ Keyboard.prototype = {
|
||||||
// AltGraph, which tends to confuse the hell out of
|
// AltGraph, which tends to confuse the hell out of
|
||||||
// remote systems. Fake a release of these keys until
|
// remote systems. Fake a release of these keys until
|
||||||
// there is a way to detect AltGraph properly.
|
// there is a way to detect AltGraph properly.
|
||||||
var fakeAltGraph = false;
|
let fakeAltGraph = false;
|
||||||
if (down && isWindows()) {
|
if (down && browserUtils.isWindows()) {
|
||||||
if ((code !== 'ControlLeft') &&
|
if ((code !== 'ControlLeft') &&
|
||||||
(code !== 'AltRight') &&
|
(code !== 'AltRight') &&
|
||||||
('ControlLeft' in this._keyDownList) &&
|
('ControlLeft' in this._keyDownList) &&
|
||||||
|
|
@ -89,10 +68,10 @@ Keyboard.prototype = {
|
||||||
this.onkeyevent(this._keyDownList['AltRight'],
|
this.onkeyevent(this._keyDownList['AltRight'],
|
||||||
'AltRight', true);
|
'AltRight', true);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_getKeyCode: function (e) {
|
_getKeyCode(e) {
|
||||||
var code = KeyboardUtil.getKeycode(e);
|
const code = KeyboardUtil.getKeycode(e);
|
||||||
if (code !== 'Unidentified') {
|
if (code !== 'Unidentified') {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -115,26 +94,26 @@ Keyboard.prototype = {
|
||||||
return e.keyIdentifier;
|
return e.keyIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
var codepoint = parseInt(e.keyIdentifier.substr(2), 16);
|
const codepoint = parseInt(e.keyIdentifier.substr(2), 16);
|
||||||
var char = String.fromCharCode(codepoint);
|
|
||||||
// Some implementations fail to uppercase the symbols
|
// Some implementations fail to uppercase the symbols
|
||||||
char = char.toUpperCase();
|
const char = String.fromCharCode(codepoint).toUpperCase();
|
||||||
|
|
||||||
return 'Platform' + char.charCodeAt();
|
return 'Platform' + char.charCodeAt();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'Unidentified';
|
return 'Unidentified';
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleKeyDown: function (e) {
|
_handleKeyDown(e) {
|
||||||
var code = this._getKeyCode(e);
|
let code = this._getKeyCode(e);
|
||||||
var keysym = KeyboardUtil.getKeysym(e);
|
let keysym = KeyboardUtil.getKeysym(e);
|
||||||
|
|
||||||
// We cannot handle keys we cannot track, but we also need
|
// We cannot handle keys we cannot track, but we also need
|
||||||
// to deal with virtual keyboards which omit key info
|
// to deal with virtual keyboards which omit key info
|
||||||
// (iOS omits tracking info on keyup events, which forces us to
|
// (iOS omits tracking info on keyup events, which forces us to
|
||||||
// special treat that platform here)
|
// special treat that platform here)
|
||||||
if ((code === 'Unidentified') || isIOS()) {
|
if ((code === 'Unidentified') || browserUtils.isIOS()) {
|
||||||
if (keysym) {
|
if (keysym) {
|
||||||
// If it's a virtual keyboard then it should be
|
// If it's a virtual keyboard then it should be
|
||||||
// sufficient to just send press and release right
|
// sufficient to just send press and release right
|
||||||
|
|
@ -151,7 +130,7 @@ Keyboard.prototype = {
|
||||||
// keys around a bit to make things more sane for the remote
|
// keys around a bit to make things more sane for the remote
|
||||||
// server. This method is used by RealVNC and TigerVNC (and
|
// server. This method is used by RealVNC and TigerVNC (and
|
||||||
// possibly others).
|
// possibly others).
|
||||||
if (isMac()) {
|
if (browserUtils.isMac()) {
|
||||||
switch (keysym) {
|
switch (keysym) {
|
||||||
case KeyTable.XK_Super_L:
|
case KeyTable.XK_Super_L:
|
||||||
keysym = KeyTable.XK_Alt_L;
|
keysym = KeyTable.XK_Alt_L;
|
||||||
|
|
@ -178,7 +157,7 @@ Keyboard.prototype = {
|
||||||
// state change events. That gets extra confusing for CapsLock
|
// state change events. That gets extra confusing for CapsLock
|
||||||
// which toggles on each press, but not on release. So pretend
|
// which toggles on each press, but not on release. So pretend
|
||||||
// it was a quick press and release of the button.
|
// it was a quick press and release of the button.
|
||||||
if (isMac() && (code === 'CapsLock')) {
|
if (browserUtils.isMac() && (code === 'CapsLock')) {
|
||||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
||||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
|
|
@ -189,7 +168,8 @@ Keyboard.prototype = {
|
||||||
// a keypress event as well
|
// a keypress event as well
|
||||||
// (IE and Edge has a broken KeyboardEvent.key, so we can't
|
// (IE and Edge has a broken KeyboardEvent.key, so we can't
|
||||||
// just check for the presence of that field)
|
// just check for the presence of that field)
|
||||||
if (!keysym && (!e.key || isIE() || isEdge())) {
|
if (!keysym
|
||||||
|
&& (!e.key || browserUtils.isIE() || browserUtils.isEdge())) {
|
||||||
this._pendingKey = code;
|
this._pendingKey = code;
|
||||||
// However we might not get a keypress event if the key
|
// However we might not get a keypress event if the key
|
||||||
// is non-printable, which needs some special fallback
|
// is non-printable, which needs some special fallback
|
||||||
|
|
@ -204,10 +184,10 @@ Keyboard.prototype = {
|
||||||
this._keyDownList[code] = keysym;
|
this._keyDownList[code] = keysym;
|
||||||
|
|
||||||
this._sendKeyEvent(keysym, code, true);
|
this._sendKeyEvent(keysym, code, true);
|
||||||
},
|
}
|
||||||
|
|
||||||
// Legacy event for browsers without code/key
|
// Legacy event for browsers without code/key
|
||||||
_handleKeyPress: function (e) {
|
_handleKeyPress(e) {
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
|
|
||||||
// Are we expecting a keypress?
|
// Are we expecting a keypress?
|
||||||
|
|
@ -215,8 +195,8 @@ Keyboard.prototype = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var code = this._getKeyCode(e);
|
let code = this._getKeyCode(e);
|
||||||
var keysym = KeyboardUtil.getKeysym(e);
|
const keysym = KeyboardUtil.getKeysym(e);
|
||||||
|
|
||||||
// The key we were waiting for?
|
// The key we were waiting for?
|
||||||
if ((code !== 'Unidentified') && (code != this._pendingKey)) {
|
if ((code !== 'Unidentified') && (code != this._pendingKey)) {
|
||||||
|
|
@ -227,23 +207,24 @@ Keyboard.prototype = {
|
||||||
this._pendingKey = null;
|
this._pendingKey = null;
|
||||||
|
|
||||||
if (!keysym) {
|
if (!keysym) {
|
||||||
console.log('keypress with no keysym:', e);
|
Log.Debug('keypress with no keysym:', e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._keyDownList[code] = keysym;
|
this._keyDownList[code] = keysym;
|
||||||
|
|
||||||
this._sendKeyEvent(keysym, code, true);
|
this._sendKeyEvent(keysym, code, true);
|
||||||
},
|
}
|
||||||
_handleKeyPressTimeout: function (e) {
|
|
||||||
|
_handleKeyPressTimeout(e) {
|
||||||
// Did someone manage to sort out the key already?
|
// Did someone manage to sort out the key already?
|
||||||
if (this._pendingKey === null) {
|
if (this._pendingKey === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var code, keysym;
|
let keysym;
|
||||||
|
|
||||||
code = this._pendingKey;
|
const code = this._pendingKey;
|
||||||
this._pendingKey = null;
|
this._pendingKey = null;
|
||||||
|
|
||||||
// We have no way of knowing the proper keysym with the
|
// We have no way of knowing the proper keysym with the
|
||||||
|
|
@ -254,12 +235,11 @@ Keyboard.prototype = {
|
||||||
keysym = e.keyCode;
|
keysym = e.keyCode;
|
||||||
} else if ((e.keyCode >= 0x41) && (e.keyCode <= 0x5a)) {
|
} else if ((e.keyCode >= 0x41) && (e.keyCode <= 0x5a)) {
|
||||||
// Character (A-Z)
|
// Character (A-Z)
|
||||||
var char = String.fromCharCode(e.keyCode);
|
let char = String.fromCharCode(e.keyCode);
|
||||||
// A feeble attempt at the correct case
|
// A feeble attempt at the correct case
|
||||||
if (e.shiftKey)
|
char = e.shiftKey
|
||||||
char = char.toUpperCase();
|
? char.toUpperCase()
|
||||||
else
|
: char.toLowerCase();
|
||||||
char = char.toLowerCase();
|
|
||||||
keysym = char.charCodeAt();
|
keysym = char.charCodeAt();
|
||||||
} else {
|
} else {
|
||||||
// Unknown, give up
|
// Unknown, give up
|
||||||
|
|
@ -269,15 +249,15 @@ Keyboard.prototype = {
|
||||||
this._keyDownList[code] = keysym;
|
this._keyDownList[code] = keysym;
|
||||||
|
|
||||||
this._sendKeyEvent(keysym, code, true);
|
this._sendKeyEvent(keysym, code, true);
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleKeyUp: function (e) {
|
_handleKeyUp(e) {
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
|
|
||||||
var code = this._getKeyCode(e);
|
const code = this._getKeyCode(e);
|
||||||
|
|
||||||
// See comment in _handleKeyDown()
|
// See comment in _handleKeyDown()
|
||||||
if (isMac() && (code === 'CapsLock')) {
|
if (browserUtils.isMac() && (code === 'CapsLock')) {
|
||||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
||||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -291,22 +271,22 @@ Keyboard.prototype = {
|
||||||
this._sendKeyEvent(this._keyDownList[code], code, false);
|
this._sendKeyEvent(this._keyDownList[code], code, false);
|
||||||
|
|
||||||
delete this._keyDownList[code];
|
delete this._keyDownList[code];
|
||||||
},
|
}
|
||||||
|
|
||||||
_allKeysUp: function () {
|
_allKeysUp() {
|
||||||
Log.Debug(">> Keyboard.allKeysUp");
|
Log.Debug(">> Keyboard.allKeysUp");
|
||||||
for (var code in this._keyDownList) {
|
for (let code in this._keyDownList) {
|
||||||
this._sendKeyEvent(this._keyDownList[code], code, false);
|
this._sendKeyEvent(this._keyDownList[code], code, false);
|
||||||
};
|
}
|
||||||
this._keyDownList = {};
|
this._keyDownList = {};
|
||||||
Log.Debug("<< Keyboard.allKeysUp");
|
Log.Debug("<< Keyboard.allKeysUp");
|
||||||
},
|
}
|
||||||
|
|
||||||
// ===== PUBLIC METHODS =====
|
// ===== PUBLIC METHODS =====
|
||||||
|
|
||||||
grab: function () {
|
grab() {
|
||||||
//Log.Debug(">> Keyboard.grab");
|
//Log.Debug(">> Keyboard.grab");
|
||||||
var c = this._target;
|
const c = this._target;
|
||||||
|
|
||||||
c.addEventListener('keydown', this._eventHandlers.keydown);
|
c.addEventListener('keydown', this._eventHandlers.keydown);
|
||||||
c.addEventListener('keyup', this._eventHandlers.keyup);
|
c.addEventListener('keyup', this._eventHandlers.keyup);
|
||||||
|
|
@ -316,11 +296,11 @@ Keyboard.prototype = {
|
||||||
window.addEventListener('blur', this._eventHandlers.blur);
|
window.addEventListener('blur', this._eventHandlers.blur);
|
||||||
|
|
||||||
//Log.Debug("<< Keyboard.grab");
|
//Log.Debug("<< Keyboard.grab");
|
||||||
},
|
}
|
||||||
|
|
||||||
ungrab: function () {
|
ungrab () {
|
||||||
//Log.Debug(">> Keyboard.ungrab");
|
//Log.Debug(">> Keyboard.ungrab");
|
||||||
var c = this._target;
|
const c = this._target;
|
||||||
|
|
||||||
c.removeEventListener('keydown', this._eventHandlers.keydown);
|
c.removeEventListener('keydown', this._eventHandlers.keydown);
|
||||||
c.removeEventListener('keyup', this._eventHandlers.keyup);
|
c.removeEventListener('keyup', this._eventHandlers.keyup);
|
||||||
|
|
@ -331,5 +311,5 @@ Keyboard.prototype = {
|
||||||
this._allKeysUp();
|
this._allKeysUp();
|
||||||
|
|
||||||
//Log.Debug(">> Keyboard.ungrab");
|
//Log.Debug(">> Keyboard.ungrab");
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
/* Functions at the bottom */
|
/* Functions at the bottom */
|
||||||
|
|
||||||
var codepoints = {
|
const codepoints = {
|
||||||
0x0100: 0x03c0, // XK_Amacron
|
0x0100: 0x03c0, // XK_Amacron
|
||||||
0x0101: 0x03e0, // XK_amacron
|
0x0101: 0x03e0, // XK_amacron
|
||||||
0x0102: 0x01c3, // XK_Abreve
|
0x0102: 0x01c3, // XK_Abreve
|
||||||
|
|
@ -670,14 +670,14 @@ var codepoints = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
lookup : function(u) {
|
lookup(u) {
|
||||||
// Latin-1 is one-to-one mapping
|
// Latin-1 is one-to-one mapping
|
||||||
if ((u >= 0x20) && (u <= 0xff)) {
|
if ((u >= 0x20) && (u <= 0xff)) {
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup table (fairly random)
|
// Lookup table (fairly random)
|
||||||
var keysym = codepoints[u];
|
const keysym = codepoints[u];
|
||||||
if (keysym !== undefined) {
|
if (keysym !== undefined) {
|
||||||
return keysym;
|
return keysym;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,59 +5,57 @@
|
||||||
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint browser: true, white: false */
|
|
||||||
/*global window, Util */
|
|
||||||
|
|
||||||
import * as Log from '../util/logging.js';
|
import * as Log from '../util/logging.js';
|
||||||
import { isTouchDevice } from '../util/browsers.js';
|
import { isTouchDevice } from '../util/browsers.js';
|
||||||
import { setCapture, stopEvent, getPointerEvent } from '../util/events.js';
|
import { setCapture, stopEvent, getPointerEvent } from '../util/events.js';
|
||||||
|
|
||||||
var WHEEL_STEP = 10; // Delta threshold for a mouse wheel step
|
const WHEEL_STEP = 10; // Delta threshold for a mouse wheel step
|
||||||
var WHEEL_STEP_TIMEOUT = 50; // ms
|
const WHEEL_STEP_TIMEOUT = 50; // ms
|
||||||
var WHEEL_LINE_HEIGHT = 19;
|
const WHEEL_LINE_HEIGHT = 19;
|
||||||
|
|
||||||
export default function Mouse(target) {
|
export default class Mouse {
|
||||||
this._target = target || document;
|
constructor(target) {
|
||||||
|
this._target = target || document;
|
||||||
|
|
||||||
this._doubleClickTimer = null;
|
this._doubleClickTimer = null;
|
||||||
this._lastTouchPos = null;
|
this._lastTouchPos = null;
|
||||||
|
|
||||||
this._pos = null;
|
this._pos = null;
|
||||||
this._wheelStepXTimer = null;
|
this._wheelStepXTimer = null;
|
||||||
this._wheelStepYTimer = null;
|
this._wheelStepYTimer = null;
|
||||||
this._accumulatedWheelDeltaX = 0;
|
this._accumulatedWheelDeltaX = 0;
|
||||||
this._accumulatedWheelDeltaY = 0;
|
this._accumulatedWheelDeltaY = 0;
|
||||||
|
|
||||||
this._eventHandlers = {
|
this._eventHandlers = {
|
||||||
'mousedown': this._handleMouseDown.bind(this),
|
'mousedown': this._handleMouseDown.bind(this),
|
||||||
'mouseup': this._handleMouseUp.bind(this),
|
'mouseup': this._handleMouseUp.bind(this),
|
||||||
'mousemove': this._handleMouseMove.bind(this),
|
'mousemove': this._handleMouseMove.bind(this),
|
||||||
'mousewheel': this._handleMouseWheel.bind(this),
|
'mousewheel': this._handleMouseWheel.bind(this),
|
||||||
'mousedisable': this._handleMouseDisable.bind(this)
|
'mousedisable': this._handleMouseDisable.bind(this)
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
Mouse.prototype = {
|
|
||||||
// ===== PROPERTIES =====
|
// ===== PROPERTIES =====
|
||||||
|
|
||||||
touchButton: 1, // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
|
this.touchButton = 1; // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ===== EVENT HANDLERS =====
|
// ===== EVENT HANDLERS =====
|
||||||
|
|
||||||
onmousebutton: function () {}, // Handler for mouse button click/release
|
onmousebutton() {} // Handler for mouse button click/release
|
||||||
onmousemove: function () {}, // Handler for mouse movement
|
onmousemove() {} // Handler for mouse movement
|
||||||
|
|
||||||
// ===== PRIVATE METHODS =====
|
// ===== PRIVATE METHODS =====
|
||||||
|
|
||||||
_resetDoubleClickTimer: function () {
|
_resetDoubleClickTimer() {
|
||||||
this._doubleClickTimer = null;
|
this._doubleClickTimer = null;
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleMouseButton: function (e, down) {
|
_handleMouseButton(e, down) {
|
||||||
this._updateMousePosition(e);
|
this._updateMousePosition(e);
|
||||||
var pos = this._pos;
|
let pos = this._pos;
|
||||||
|
|
||||||
var bmask;
|
let bmask;
|
||||||
if (e.touches || e.changedTouches) {
|
if (e.touches || e.changedTouches) {
|
||||||
// Touch device
|
// Touch device
|
||||||
|
|
||||||
|
|
@ -73,13 +71,13 @@ Mouse.prototype = {
|
||||||
// force the position of the latter touch to the position of
|
// force the position of the latter touch to the position of
|
||||||
// the first.
|
// the first.
|
||||||
|
|
||||||
var xs = this._lastTouchPos.x - pos.x;
|
const xs = this._lastTouchPos.x - pos.x;
|
||||||
var ys = this._lastTouchPos.y - pos.y;
|
const ys = this._lastTouchPos.y - pos.y;
|
||||||
var d = Math.sqrt((xs * xs) + (ys * ys));
|
const d = Math.sqrt((xs * xs) + (ys * ys));
|
||||||
|
|
||||||
// The goal is to trigger on a certain physical width, the
|
// The goal is to trigger on a certain physical width, the
|
||||||
// devicePixelRatio brings us a bit closer but is not optimal.
|
// devicePixelRatio brings us a bit closer but is not optimal.
|
||||||
var threshold = 20 * (window.devicePixelRatio || 1);
|
const threshold = 20 * (window.devicePixelRatio || 1);
|
||||||
if (d < threshold) {
|
if (d < threshold) {
|
||||||
pos = this._lastTouchPos;
|
pos = this._lastTouchPos;
|
||||||
}
|
}
|
||||||
|
|
@ -103,25 +101,25 @@ Mouse.prototype = {
|
||||||
this.onmousebutton(pos.x, pos.y, down, bmask);
|
this.onmousebutton(pos.x, pos.y, down, bmask);
|
||||||
|
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleMouseDown: function (e) {
|
_handleMouseDown(e) {
|
||||||
// Touch events have implicit capture
|
// Touch events have implicit capture
|
||||||
if (e.type === "mousedown") {
|
if (e.type === "mousedown") {
|
||||||
setCapture(this._target);
|
setCapture(this._target);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._handleMouseButton(e, 1);
|
this._handleMouseButton(e, 1);
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleMouseUp: function (e) {
|
_handleMouseUp(e) {
|
||||||
this._handleMouseButton(e, 0);
|
this._handleMouseButton(e, 0);
|
||||||
},
|
}
|
||||||
|
|
||||||
// Mouse wheel events are sent in steps over VNC. This means that the VNC
|
// Mouse wheel events are sent in steps over VNC. This means that the VNC
|
||||||
// protocol can't handle a wheel event with specific distance or speed.
|
// protocol can't handle a wheel event with specific distance or speed.
|
||||||
// Therefor, if we get a lot of small mouse wheel events we combine them.
|
// Therefor, if we get a lot of small mouse wheel events we combine them.
|
||||||
_generateWheelStepX: function () {
|
_generateWheelStepX() {
|
||||||
|
|
||||||
if (this._accumulatedWheelDeltaX < 0) {
|
if (this._accumulatedWheelDeltaX < 0) {
|
||||||
this.onmousebutton(this._pos.x, this._pos.y, 1, 1 << 5);
|
this.onmousebutton(this._pos.x, this._pos.y, 1, 1 << 5);
|
||||||
|
|
@ -132,9 +130,9 @@ Mouse.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._accumulatedWheelDeltaX = 0;
|
this._accumulatedWheelDeltaX = 0;
|
||||||
},
|
}
|
||||||
|
|
||||||
_generateWheelStepY: function () {
|
_generateWheelStepY() {
|
||||||
|
|
||||||
if (this._accumulatedWheelDeltaY < 0) {
|
if (this._accumulatedWheelDeltaY < 0) {
|
||||||
this.onmousebutton(this._pos.x, this._pos.y, 1, 1 << 3);
|
this.onmousebutton(this._pos.x, this._pos.y, 1, 1 << 3);
|
||||||
|
|
@ -145,22 +143,22 @@ Mouse.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._accumulatedWheelDeltaY = 0;
|
this._accumulatedWheelDeltaY = 0;
|
||||||
},
|
}
|
||||||
|
|
||||||
_resetWheelStepTimers: function () {
|
_resetWheelStepTimers() {
|
||||||
window.clearTimeout(this._wheelStepXTimer);
|
window.clearTimeout(this._wheelStepXTimer);
|
||||||
window.clearTimeout(this._wheelStepYTimer);
|
window.clearTimeout(this._wheelStepYTimer);
|
||||||
this._wheelStepXTimer = null;
|
this._wheelStepXTimer = null;
|
||||||
this._wheelStepYTimer = null;
|
this._wheelStepYTimer = null;
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleMouseWheel: function (e) {
|
_handleMouseWheel(e) {
|
||||||
this._resetWheelStepTimers();
|
this._resetWheelStepTimers();
|
||||||
|
|
||||||
this._updateMousePosition(e);
|
this._updateMousePosition(e);
|
||||||
|
|
||||||
var dX = e.deltaX;
|
let dX = e.deltaX;
|
||||||
var dY = e.deltaY;
|
let dY = e.deltaY;
|
||||||
|
|
||||||
// Pixel units unless it's non-zero.
|
// Pixel units unless it's non-zero.
|
||||||
// Note that if deltamode is line or page won't matter since we aren't
|
// Note that if deltamode is line or page won't matter since we aren't
|
||||||
|
|
@ -186,6 +184,7 @@ Mouse.prototype = {
|
||||||
window.setTimeout(this._generateWheelStepX.bind(this),
|
window.setTimeout(this._generateWheelStepX.bind(this),
|
||||||
WHEEL_STEP_TIMEOUT);
|
WHEEL_STEP_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.abs(this._accumulatedWheelDeltaY) > WHEEL_STEP) {
|
if (Math.abs(this._accumulatedWheelDeltaY) > WHEEL_STEP) {
|
||||||
this._generateWheelStepY();
|
this._generateWheelStepY();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -195,15 +194,15 @@ Mouse.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleMouseMove: function (e) {
|
_handleMouseMove(e) {
|
||||||
this._updateMousePosition(e);
|
this._updateMousePosition(e);
|
||||||
this.onmousemove(this._pos.x, this._pos.y);
|
this.onmousemove(this._pos.x, this._pos.y);
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleMouseDisable: function (e) {
|
_handleMouseDisable(e) {
|
||||||
/*
|
/*
|
||||||
* Stop propagation if inside canvas area
|
* Stop propagation if inside canvas area
|
||||||
* Note: This is only needed for the 'click' event as it fails
|
* Note: This is only needed for the 'click' event as it fails
|
||||||
|
|
@ -213,13 +212,13 @@ Mouse.prototype = {
|
||||||
if (e.target == this._target) {
|
if (e.target == this._target) {
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Update coordinates relative to target
|
// Update coordinates relative to target
|
||||||
_updateMousePosition: function(e) {
|
_updateMousePosition(e) {
|
||||||
e = getPointerEvent(e);
|
e = getPointerEvent(e);
|
||||||
var bounds = this._target.getBoundingClientRect();
|
const bounds = this._target.getBoundingClientRect();
|
||||||
var x, y;
|
let x, y;
|
||||||
// Clip to target bounds
|
// Clip to target bounds
|
||||||
if (e.clientX < bounds.left) {
|
if (e.clientX < bounds.left) {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
|
@ -235,19 +234,20 @@ Mouse.prototype = {
|
||||||
} else {
|
} else {
|
||||||
y = e.clientY - bounds.top;
|
y = e.clientY - bounds.top;
|
||||||
}
|
}
|
||||||
this._pos = {x:x, y:y};
|
this._pos = { x, y };
|
||||||
},
|
}
|
||||||
|
|
||||||
// ===== PUBLIC METHODS =====
|
// ===== PUBLIC METHODS =====
|
||||||
|
|
||||||
grab: function () {
|
grab() {
|
||||||
var c = this._target;
|
const c = this._target;
|
||||||
|
|
||||||
if (isTouchDevice) {
|
if (isTouchDevice) {
|
||||||
c.addEventListener('touchstart', this._eventHandlers.mousedown);
|
c.addEventListener('touchstart', this._eventHandlers.mousedown);
|
||||||
c.addEventListener('touchend', this._eventHandlers.mouseup);
|
c.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
c.addEventListener('touchmove', this._eventHandlers.mousemove);
|
c.addEventListener('touchmove', this._eventHandlers.mousemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
c.addEventListener('mousedown', this._eventHandlers.mousedown);
|
c.addEventListener('mousedown', this._eventHandlers.mousedown);
|
||||||
c.addEventListener('mouseup', this._eventHandlers.mouseup);
|
c.addEventListener('mouseup', this._eventHandlers.mouseup);
|
||||||
c.addEventListener('mousemove', this._eventHandlers.mousemove);
|
c.addEventListener('mousemove', this._eventHandlers.mousemove);
|
||||||
|
|
@ -259,10 +259,10 @@ Mouse.prototype = {
|
||||||
/* preventDefault() on mousedown doesn't stop this event for some
|
/* preventDefault() on mousedown doesn't stop this event for some
|
||||||
reason so we have to explicitly block it */
|
reason so we have to explicitly block it */
|
||||||
c.addEventListener('contextmenu', this._eventHandlers.mousedisable);
|
c.addEventListener('contextmenu', this._eventHandlers.mousedisable);
|
||||||
},
|
}
|
||||||
|
|
||||||
ungrab: function () {
|
ungrab() {
|
||||||
var c = this._target;
|
const c = this._target;
|
||||||
|
|
||||||
this._resetWheelStepTimers();
|
this._resetWheelStepTimers();
|
||||||
|
|
||||||
|
|
@ -271,6 +271,7 @@ Mouse.prototype = {
|
||||||
c.removeEventListener('touchend', this._eventHandlers.mouseup);
|
c.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
c.removeEventListener('touchmove', this._eventHandlers.mousemove);
|
c.removeEventListener('touchmove', this._eventHandlers.mousemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
c.removeEventListener('mousedown', this._eventHandlers.mousedown);
|
c.removeEventListener('mousedown', this._eventHandlers.mousedown);
|
||||||
c.removeEventListener('mouseup', this._eventHandlers.mouseup);
|
c.removeEventListener('mouseup', this._eventHandlers.mouseup);
|
||||||
c.removeEventListener('mousemove', this._eventHandlers.mousemove);
|
c.removeEventListener('mousemove', this._eventHandlers.mousemove);
|
||||||
|
|
@ -280,4 +281,4 @@ Mouse.prototype = {
|
||||||
|
|
||||||
c.removeEventListener('contextmenu', this._eventHandlers.mousedisable);
|
c.removeEventListener('contextmenu', this._eventHandlers.mousedisable);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,8 @@
|
||||||
import KeyTable from "./keysym.js";
|
|
||||||
import keysyms from "./keysymdef.js";
|
import keysyms from "./keysymdef.js";
|
||||||
import vkeys from "./vkeys.js";
|
import vkeys from "./vkeys.js";
|
||||||
import fixedkeys from "./fixedkeys.js";
|
import fixedkeys from "./fixedkeys.js";
|
||||||
import DOMKeyTable from "./domkeytable.js";
|
import DOMKeyTable from "./domkeytable.js";
|
||||||
|
import * as browserUtils from "../util/browsers.js";
|
||||||
function isMac() {
|
|
||||||
return navigator && !!(/mac/i).exec(navigator.platform);
|
|
||||||
}
|
|
||||||
function isIE() {
|
|
||||||
return navigator && !!(/trident/i).exec(navigator.userAgent);
|
|
||||||
}
|
|
||||||
function isEdge() {
|
|
||||||
return navigator && !!(/edge/i).exec(navigator.userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get 'KeyboardEvent.code', handling legacy browsers
|
// Get 'KeyboardEvent.code', handling legacy browsers
|
||||||
export function getKeycode(evt){
|
export function getKeycode(evt){
|
||||||
|
|
@ -34,10 +24,10 @@ export function getKeycode(evt){
|
||||||
// in the 'keyCode' field for non-printable characters. However
|
// in the 'keyCode' field for non-printable characters. However
|
||||||
// Webkit sets it to the same as charCode in 'keypress' events.
|
// Webkit sets it to the same as charCode in 'keypress' events.
|
||||||
if ((evt.type !== 'keypress') && (evt.keyCode in vkeys)) {
|
if ((evt.type !== 'keypress') && (evt.keyCode in vkeys)) {
|
||||||
var code = vkeys[evt.keyCode];
|
let code = vkeys[evt.keyCode];
|
||||||
|
|
||||||
// macOS has messed up this code for some reason
|
// macOS has messed up this code for some reason
|
||||||
if (isMac() && (code === 'ContextMenu')) {
|
if (browserUtils.isMac() && (code === 'ContextMenu')) {
|
||||||
code = 'MetaRight';
|
code = 'MetaRight';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,13 +104,14 @@ export function getKey(evt) {
|
||||||
|
|
||||||
// IE and Edge have broken handling of AltGraph so we cannot
|
// IE and Edge have broken handling of AltGraph so we cannot
|
||||||
// trust them for printable characters
|
// trust them for printable characters
|
||||||
if ((evt.key.length !== 1) || (!isIE() && !isEdge())) {
|
if ((evt.key.length !== 1)
|
||||||
|
|| (!browserUtils.isIE() && !browserUtils.isEdge())) {
|
||||||
return evt.key;
|
return evt.key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to deduce it based on the physical key
|
// Try to deduce it based on the physical key
|
||||||
var code = getKeycode(evt);
|
let code = getKeycode(evt);
|
||||||
if (code in fixedkeys) {
|
if (code in fixedkeys) {
|
||||||
return fixedkeys[code];
|
return fixedkeys[code];
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +127,7 @@ export function getKey(evt) {
|
||||||
|
|
||||||
// Get the most reliable keysym value we can get from a key event
|
// Get the most reliable keysym value we can get from a key event
|
||||||
export function getKeysym(evt){
|
export function getKeysym(evt){
|
||||||
var key = getKey(evt);
|
const key = getKey(evt);
|
||||||
|
|
||||||
if (key === 'Unidentified') {
|
if (key === 'Unidentified') {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -144,7 +135,7 @@ export function getKeysym(evt){
|
||||||
|
|
||||||
// First look up special keys
|
// First look up special keys
|
||||||
if (key in DOMKeyTable) {
|
if (key in DOMKeyTable) {
|
||||||
var location = evt.location;
|
let location = evt.location;
|
||||||
|
|
||||||
// Safari screws up location for the right cmd key
|
// Safari screws up location for the right cmd key
|
||||||
if ((key === 'Meta') && (location === 0)) {
|
if ((key === 'Meta') && (location === 0)) {
|
||||||
|
|
@ -159,15 +150,12 @@ export function getKeysym(evt){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we need to look at the Unicode symbol instead
|
// Now we need to look at the Unicode symbol instead
|
||||||
|
|
||||||
var codepoint;
|
|
||||||
|
|
||||||
// Special key? (FIXME: Should have been caught earlier)
|
// Special key? (FIXME: Should have been caught earlier)
|
||||||
if (key.length !== 1) {
|
if (key.length !== 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
codepoint = key.charCodeAt();
|
const codepoint = key.charCodeAt();
|
||||||
if (codepoint) {
|
if (codepoint) {
|
||||||
return keysyms.lookup(codepoint);
|
return keysyms.lookup(codepoint);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,167 +5,167 @@
|
||||||
* keymap-gen --lang=js code-map keymaps.csv html atset1
|
* keymap-gen --lang=js code-map keymaps.csv html atset1
|
||||||
*/
|
*/
|
||||||
export default {
|
export default {
|
||||||
"Again": 0xe005, /* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */
|
"Again": 0xe005, /* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */
|
||||||
"AltLeft": 0x38, /* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */
|
"AltLeft": 0x38, /* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */
|
||||||
"AltRight": 0xe038, /* html:AltRight (AltRight) -> linux:100 (KEY_RIGHTALT) -> atset1:57400 */
|
"AltRight": 0xe038, /* html:AltRight (AltRight) -> linux:100 (KEY_RIGHTALT) -> atset1:57400 */
|
||||||
"ArrowDown": 0xe050, /* html:ArrowDown (ArrowDown) -> linux:108 (KEY_DOWN) -> atset1:57424 */
|
"ArrowDown": 0xe050, /* html:ArrowDown (ArrowDown) -> linux:108 (KEY_DOWN) -> atset1:57424 */
|
||||||
"ArrowLeft": 0xe04b, /* html:ArrowLeft (ArrowLeft) -> linux:105 (KEY_LEFT) -> atset1:57419 */
|
"ArrowLeft": 0xe04b, /* html:ArrowLeft (ArrowLeft) -> linux:105 (KEY_LEFT) -> atset1:57419 */
|
||||||
"ArrowRight": 0xe04d, /* html:ArrowRight (ArrowRight) -> linux:106 (KEY_RIGHT) -> atset1:57421 */
|
"ArrowRight": 0xe04d, /* html:ArrowRight (ArrowRight) -> linux:106 (KEY_RIGHT) -> atset1:57421 */
|
||||||
"ArrowUp": 0xe048, /* html:ArrowUp (ArrowUp) -> linux:103 (KEY_UP) -> atset1:57416 */
|
"ArrowUp": 0xe048, /* html:ArrowUp (ArrowUp) -> linux:103 (KEY_UP) -> atset1:57416 */
|
||||||
"AudioVolumeDown": 0xe02e, /* html:AudioVolumeDown (AudioVolumeDown) -> linux:114 (KEY_VOLUMEDOWN) -> atset1:57390 */
|
"AudioVolumeDown": 0xe02e, /* html:AudioVolumeDown (AudioVolumeDown) -> linux:114 (KEY_VOLUMEDOWN) -> atset1:57390 */
|
||||||
"AudioVolumeMute": 0xe020, /* html:AudioVolumeMute (AudioVolumeMute) -> linux:113 (KEY_MUTE) -> atset1:57376 */
|
"AudioVolumeMute": 0xe020, /* html:AudioVolumeMute (AudioVolumeMute) -> linux:113 (KEY_MUTE) -> atset1:57376 */
|
||||||
"AudioVolumeUp": 0xe030, /* html:AudioVolumeUp (AudioVolumeUp) -> linux:115 (KEY_VOLUMEUP) -> atset1:57392 */
|
"AudioVolumeUp": 0xe030, /* html:AudioVolumeUp (AudioVolumeUp) -> linux:115 (KEY_VOLUMEUP) -> atset1:57392 */
|
||||||
"Backquote": 0x29, /* html:Backquote (Backquote) -> linux:41 (KEY_GRAVE) -> atset1:41 */
|
"Backquote": 0x29, /* html:Backquote (Backquote) -> linux:41 (KEY_GRAVE) -> atset1:41 */
|
||||||
"Backslash": 0x2b, /* html:Backslash (Backslash) -> linux:43 (KEY_BACKSLASH) -> atset1:43 */
|
"Backslash": 0x2b, /* html:Backslash (Backslash) -> linux:43 (KEY_BACKSLASH) -> atset1:43 */
|
||||||
"Backspace": 0xe, /* html:Backspace (Backspace) -> linux:14 (KEY_BACKSPACE) -> atset1:14 */
|
"Backspace": 0xe, /* html:Backspace (Backspace) -> linux:14 (KEY_BACKSPACE) -> atset1:14 */
|
||||||
"BracketLeft": 0x1a, /* html:BracketLeft (BracketLeft) -> linux:26 (KEY_LEFTBRACE) -> atset1:26 */
|
"BracketLeft": 0x1a, /* html:BracketLeft (BracketLeft) -> linux:26 (KEY_LEFTBRACE) -> atset1:26 */
|
||||||
"BracketRight": 0x1b, /* html:BracketRight (BracketRight) -> linux:27 (KEY_RIGHTBRACE) -> atset1:27 */
|
"BracketRight": 0x1b, /* html:BracketRight (BracketRight) -> linux:27 (KEY_RIGHTBRACE) -> atset1:27 */
|
||||||
"BrowserBack": 0xe06a, /* html:BrowserBack (BrowserBack) -> linux:158 (KEY_BACK) -> atset1:57450 */
|
"BrowserBack": 0xe06a, /* html:BrowserBack (BrowserBack) -> linux:158 (KEY_BACK) -> atset1:57450 */
|
||||||
"BrowserFavorites": 0xe066, /* html:BrowserFavorites (BrowserFavorites) -> linux:156 (KEY_BOOKMARKS) -> atset1:57446 */
|
"BrowserFavorites": 0xe066, /* html:BrowserFavorites (BrowserFavorites) -> linux:156 (KEY_BOOKMARKS) -> atset1:57446 */
|
||||||
"BrowserForward": 0xe069, /* html:BrowserForward (BrowserForward) -> linux:159 (KEY_FORWARD) -> atset1:57449 */
|
"BrowserForward": 0xe069, /* html:BrowserForward (BrowserForward) -> linux:159 (KEY_FORWARD) -> atset1:57449 */
|
||||||
"BrowserHome": 0xe032, /* html:BrowserHome (BrowserHome) -> linux:172 (KEY_HOMEPAGE) -> atset1:57394 */
|
"BrowserHome": 0xe032, /* html:BrowserHome (BrowserHome) -> linux:172 (KEY_HOMEPAGE) -> atset1:57394 */
|
||||||
"BrowserRefresh": 0xe067, /* html:BrowserRefresh (BrowserRefresh) -> linux:173 (KEY_REFRESH) -> atset1:57447 */
|
"BrowserRefresh": 0xe067, /* html:BrowserRefresh (BrowserRefresh) -> linux:173 (KEY_REFRESH) -> atset1:57447 */
|
||||||
"BrowserSearch": 0xe065, /* html:BrowserSearch (BrowserSearch) -> linux:217 (KEY_SEARCH) -> atset1:57445 */
|
"BrowserSearch": 0xe065, /* html:BrowserSearch (BrowserSearch) -> linux:217 (KEY_SEARCH) -> atset1:57445 */
|
||||||
"BrowserStop": 0xe068, /* html:BrowserStop (BrowserStop) -> linux:128 (KEY_STOP) -> atset1:57448 */
|
"BrowserStop": 0xe068, /* html:BrowserStop (BrowserStop) -> linux:128 (KEY_STOP) -> atset1:57448 */
|
||||||
"CapsLock": 0x3a, /* html:CapsLock (CapsLock) -> linux:58 (KEY_CAPSLOCK) -> atset1:58 */
|
"CapsLock": 0x3a, /* html:CapsLock (CapsLock) -> linux:58 (KEY_CAPSLOCK) -> atset1:58 */
|
||||||
"Comma": 0x33, /* html:Comma (Comma) -> linux:51 (KEY_COMMA) -> atset1:51 */
|
"Comma": 0x33, /* html:Comma (Comma) -> linux:51 (KEY_COMMA) -> atset1:51 */
|
||||||
"ContextMenu": 0xe05d, /* html:ContextMenu (ContextMenu) -> linux:127 (KEY_COMPOSE) -> atset1:57437 */
|
"ContextMenu": 0xe05d, /* html:ContextMenu (ContextMenu) -> linux:127 (KEY_COMPOSE) -> atset1:57437 */
|
||||||
"ControlLeft": 0x1d, /* html:ControlLeft (ControlLeft) -> linux:29 (KEY_LEFTCTRL) -> atset1:29 */
|
"ControlLeft": 0x1d, /* html:ControlLeft (ControlLeft) -> linux:29 (KEY_LEFTCTRL) -> atset1:29 */
|
||||||
"ControlRight": 0xe01d, /* html:ControlRight (ControlRight) -> linux:97 (KEY_RIGHTCTRL) -> atset1:57373 */
|
"ControlRight": 0xe01d, /* html:ControlRight (ControlRight) -> linux:97 (KEY_RIGHTCTRL) -> atset1:57373 */
|
||||||
"Convert": 0x79, /* html:Convert (Convert) -> linux:92 (KEY_HENKAN) -> atset1:121 */
|
"Convert": 0x79, /* html:Convert (Convert) -> linux:92 (KEY_HENKAN) -> atset1:121 */
|
||||||
"Copy": 0xe078, /* html:Copy (Copy) -> linux:133 (KEY_COPY) -> atset1:57464 */
|
"Copy": 0xe078, /* html:Copy (Copy) -> linux:133 (KEY_COPY) -> atset1:57464 */
|
||||||
"Cut": 0xe03c, /* html:Cut (Cut) -> linux:137 (KEY_CUT) -> atset1:57404 */
|
"Cut": 0xe03c, /* html:Cut (Cut) -> linux:137 (KEY_CUT) -> atset1:57404 */
|
||||||
"Delete": 0xe053, /* html:Delete (Delete) -> linux:111 (KEY_DELETE) -> atset1:57427 */
|
"Delete": 0xe053, /* html:Delete (Delete) -> linux:111 (KEY_DELETE) -> atset1:57427 */
|
||||||
"Digit0": 0xb, /* html:Digit0 (Digit0) -> linux:11 (KEY_0) -> atset1:11 */
|
"Digit0": 0xb, /* html:Digit0 (Digit0) -> linux:11 (KEY_0) -> atset1:11 */
|
||||||
"Digit1": 0x2, /* html:Digit1 (Digit1) -> linux:2 (KEY_1) -> atset1:2 */
|
"Digit1": 0x2, /* html:Digit1 (Digit1) -> linux:2 (KEY_1) -> atset1:2 */
|
||||||
"Digit2": 0x3, /* html:Digit2 (Digit2) -> linux:3 (KEY_2) -> atset1:3 */
|
"Digit2": 0x3, /* html:Digit2 (Digit2) -> linux:3 (KEY_2) -> atset1:3 */
|
||||||
"Digit3": 0x4, /* html:Digit3 (Digit3) -> linux:4 (KEY_3) -> atset1:4 */
|
"Digit3": 0x4, /* html:Digit3 (Digit3) -> linux:4 (KEY_3) -> atset1:4 */
|
||||||
"Digit4": 0x5, /* html:Digit4 (Digit4) -> linux:5 (KEY_4) -> atset1:5 */
|
"Digit4": 0x5, /* html:Digit4 (Digit4) -> linux:5 (KEY_4) -> atset1:5 */
|
||||||
"Digit5": 0x6, /* html:Digit5 (Digit5) -> linux:6 (KEY_5) -> atset1:6 */
|
"Digit5": 0x6, /* html:Digit5 (Digit5) -> linux:6 (KEY_5) -> atset1:6 */
|
||||||
"Digit6": 0x7, /* html:Digit6 (Digit6) -> linux:7 (KEY_6) -> atset1:7 */
|
"Digit6": 0x7, /* html:Digit6 (Digit6) -> linux:7 (KEY_6) -> atset1:7 */
|
||||||
"Digit7": 0x8, /* html:Digit7 (Digit7) -> linux:8 (KEY_7) -> atset1:8 */
|
"Digit7": 0x8, /* html:Digit7 (Digit7) -> linux:8 (KEY_7) -> atset1:8 */
|
||||||
"Digit8": 0x9, /* html:Digit8 (Digit8) -> linux:9 (KEY_8) -> atset1:9 */
|
"Digit8": 0x9, /* html:Digit8 (Digit8) -> linux:9 (KEY_8) -> atset1:9 */
|
||||||
"Digit9": 0xa, /* html:Digit9 (Digit9) -> linux:10 (KEY_9) -> atset1:10 */
|
"Digit9": 0xa, /* html:Digit9 (Digit9) -> linux:10 (KEY_9) -> atset1:10 */
|
||||||
"Eject": 0xe07d, /* html:Eject (Eject) -> linux:162 (KEY_EJECTCLOSECD) -> atset1:57469 */
|
"Eject": 0xe07d, /* html:Eject (Eject) -> linux:162 (KEY_EJECTCLOSECD) -> atset1:57469 */
|
||||||
"End": 0xe04f, /* html:End (End) -> linux:107 (KEY_END) -> atset1:57423 */
|
"End": 0xe04f, /* html:End (End) -> linux:107 (KEY_END) -> atset1:57423 */
|
||||||
"Enter": 0x1c, /* html:Enter (Enter) -> linux:28 (KEY_ENTER) -> atset1:28 */
|
"Enter": 0x1c, /* html:Enter (Enter) -> linux:28 (KEY_ENTER) -> atset1:28 */
|
||||||
"Equal": 0xd, /* html:Equal (Equal) -> linux:13 (KEY_EQUAL) -> atset1:13 */
|
"Equal": 0xd, /* html:Equal (Equal) -> linux:13 (KEY_EQUAL) -> atset1:13 */
|
||||||
"Escape": 0x1, /* html:Escape (Escape) -> linux:1 (KEY_ESC) -> atset1:1 */
|
"Escape": 0x1, /* html:Escape (Escape) -> linux:1 (KEY_ESC) -> atset1:1 */
|
||||||
"F1": 0x3b, /* html:F1 (F1) -> linux:59 (KEY_F1) -> atset1:59 */
|
"F1": 0x3b, /* html:F1 (F1) -> linux:59 (KEY_F1) -> atset1:59 */
|
||||||
"F10": 0x44, /* html:F10 (F10) -> linux:68 (KEY_F10) -> atset1:68 */
|
"F10": 0x44, /* html:F10 (F10) -> linux:68 (KEY_F10) -> atset1:68 */
|
||||||
"F11": 0x57, /* html:F11 (F11) -> linux:87 (KEY_F11) -> atset1:87 */
|
"F11": 0x57, /* html:F11 (F11) -> linux:87 (KEY_F11) -> atset1:87 */
|
||||||
"F12": 0x58, /* html:F12 (F12) -> linux:88 (KEY_F12) -> atset1:88 */
|
"F12": 0x58, /* html:F12 (F12) -> linux:88 (KEY_F12) -> atset1:88 */
|
||||||
"F13": 0x5d, /* html:F13 (F13) -> linux:183 (KEY_F13) -> atset1:93 */
|
"F13": 0x5d, /* html:F13 (F13) -> linux:183 (KEY_F13) -> atset1:93 */
|
||||||
"F14": 0x5e, /* html:F14 (F14) -> linux:184 (KEY_F14) -> atset1:94 */
|
"F14": 0x5e, /* html:F14 (F14) -> linux:184 (KEY_F14) -> atset1:94 */
|
||||||
"F15": 0x5f, /* html:F15 (F15) -> linux:185 (KEY_F15) -> atset1:95 */
|
"F15": 0x5f, /* html:F15 (F15) -> linux:185 (KEY_F15) -> atset1:95 */
|
||||||
"F16": 0x55, /* html:F16 (F16) -> linux:186 (KEY_F16) -> atset1:85 */
|
"F16": 0x55, /* html:F16 (F16) -> linux:186 (KEY_F16) -> atset1:85 */
|
||||||
"F17": 0xe003, /* html:F17 (F17) -> linux:187 (KEY_F17) -> atset1:57347 */
|
"F17": 0xe003, /* html:F17 (F17) -> linux:187 (KEY_F17) -> atset1:57347 */
|
||||||
"F18": 0xe077, /* html:F18 (F18) -> linux:188 (KEY_F18) -> atset1:57463 */
|
"F18": 0xe077, /* html:F18 (F18) -> linux:188 (KEY_F18) -> atset1:57463 */
|
||||||
"F19": 0xe004, /* html:F19 (F19) -> linux:189 (KEY_F19) -> atset1:57348 */
|
"F19": 0xe004, /* html:F19 (F19) -> linux:189 (KEY_F19) -> atset1:57348 */
|
||||||
"F2": 0x3c, /* html:F2 (F2) -> linux:60 (KEY_F2) -> atset1:60 */
|
"F2": 0x3c, /* html:F2 (F2) -> linux:60 (KEY_F2) -> atset1:60 */
|
||||||
"F20": 0x5a, /* html:F20 (F20) -> linux:190 (KEY_F20) -> atset1:90 */
|
"F20": 0x5a, /* html:F20 (F20) -> linux:190 (KEY_F20) -> atset1:90 */
|
||||||
"F21": 0x74, /* html:F21 (F21) -> linux:191 (KEY_F21) -> atset1:116 */
|
"F21": 0x74, /* html:F21 (F21) -> linux:191 (KEY_F21) -> atset1:116 */
|
||||||
"F22": 0xe079, /* html:F22 (F22) -> linux:192 (KEY_F22) -> atset1:57465 */
|
"F22": 0xe079, /* html:F22 (F22) -> linux:192 (KEY_F22) -> atset1:57465 */
|
||||||
"F23": 0x6d, /* html:F23 (F23) -> linux:193 (KEY_F23) -> atset1:109 */
|
"F23": 0x6d, /* html:F23 (F23) -> linux:193 (KEY_F23) -> atset1:109 */
|
||||||
"F24": 0x6f, /* html:F24 (F24) -> linux:194 (KEY_F24) -> atset1:111 */
|
"F24": 0x6f, /* html:F24 (F24) -> linux:194 (KEY_F24) -> atset1:111 */
|
||||||
"F3": 0x3d, /* html:F3 (F3) -> linux:61 (KEY_F3) -> atset1:61 */
|
"F3": 0x3d, /* html:F3 (F3) -> linux:61 (KEY_F3) -> atset1:61 */
|
||||||
"F4": 0x3e, /* html:F4 (F4) -> linux:62 (KEY_F4) -> atset1:62 */
|
"F4": 0x3e, /* html:F4 (F4) -> linux:62 (KEY_F4) -> atset1:62 */
|
||||||
"F5": 0x3f, /* html:F5 (F5) -> linux:63 (KEY_F5) -> atset1:63 */
|
"F5": 0x3f, /* html:F5 (F5) -> linux:63 (KEY_F5) -> atset1:63 */
|
||||||
"F6": 0x40, /* html:F6 (F6) -> linux:64 (KEY_F6) -> atset1:64 */
|
"F6": 0x40, /* html:F6 (F6) -> linux:64 (KEY_F6) -> atset1:64 */
|
||||||
"F7": 0x41, /* html:F7 (F7) -> linux:65 (KEY_F7) -> atset1:65 */
|
"F7": 0x41, /* html:F7 (F7) -> linux:65 (KEY_F7) -> atset1:65 */
|
||||||
"F8": 0x42, /* html:F8 (F8) -> linux:66 (KEY_F8) -> atset1:66 */
|
"F8": 0x42, /* html:F8 (F8) -> linux:66 (KEY_F8) -> atset1:66 */
|
||||||
"F9": 0x43, /* html:F9 (F9) -> linux:67 (KEY_F9) -> atset1:67 */
|
"F9": 0x43, /* html:F9 (F9) -> linux:67 (KEY_F9) -> atset1:67 */
|
||||||
"Find": 0xe041, /* html:Find (Find) -> linux:136 (KEY_FIND) -> atset1:57409 */
|
"Find": 0xe041, /* html:Find (Find) -> linux:136 (KEY_FIND) -> atset1:57409 */
|
||||||
"Help": 0xe075, /* html:Help (Help) -> linux:138 (KEY_HELP) -> atset1:57461 */
|
"Help": 0xe075, /* html:Help (Help) -> linux:138 (KEY_HELP) -> atset1:57461 */
|
||||||
"Hiragana": 0x77, /* html:Hiragana (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
|
"Hiragana": 0x77, /* html:Hiragana (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
|
||||||
"Home": 0xe047, /* html:Home (Home) -> linux:102 (KEY_HOME) -> atset1:57415 */
|
"Home": 0xe047, /* html:Home (Home) -> linux:102 (KEY_HOME) -> atset1:57415 */
|
||||||
"Insert": 0xe052, /* html:Insert (Insert) -> linux:110 (KEY_INSERT) -> atset1:57426 */
|
"Insert": 0xe052, /* html:Insert (Insert) -> linux:110 (KEY_INSERT) -> atset1:57426 */
|
||||||
"IntlBackslash": 0x56, /* html:IntlBackslash (IntlBackslash) -> linux:86 (KEY_102ND) -> atset1:86 */
|
"IntlBackslash": 0x56, /* html:IntlBackslash (IntlBackslash) -> linux:86 (KEY_102ND) -> atset1:86 */
|
||||||
"IntlRo": 0x73, /* html:IntlRo (IntlRo) -> linux:89 (KEY_RO) -> atset1:115 */
|
"IntlRo": 0x73, /* html:IntlRo (IntlRo) -> linux:89 (KEY_RO) -> atset1:115 */
|
||||||
"IntlYen": 0x7d, /* html:IntlYen (IntlYen) -> linux:124 (KEY_YEN) -> atset1:125 */
|
"IntlYen": 0x7d, /* html:IntlYen (IntlYen) -> linux:124 (KEY_YEN) -> atset1:125 */
|
||||||
"KanaMode": 0x70, /* html:KanaMode (KanaMode) -> linux:93 (KEY_KATAKANAHIRAGANA) -> atset1:112 */
|
"KanaMode": 0x70, /* html:KanaMode (KanaMode) -> linux:93 (KEY_KATAKANAHIRAGANA) -> atset1:112 */
|
||||||
"Katakana": 0x78, /* html:Katakana (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
|
"Katakana": 0x78, /* html:Katakana (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
|
||||||
"KeyA": 0x1e, /* html:KeyA (KeyA) -> linux:30 (KEY_A) -> atset1:30 */
|
"KeyA": 0x1e, /* html:KeyA (KeyA) -> linux:30 (KEY_A) -> atset1:30 */
|
||||||
"KeyB": 0x30, /* html:KeyB (KeyB) -> linux:48 (KEY_B) -> atset1:48 */
|
"KeyB": 0x30, /* html:KeyB (KeyB) -> linux:48 (KEY_B) -> atset1:48 */
|
||||||
"KeyC": 0x2e, /* html:KeyC (KeyC) -> linux:46 (KEY_C) -> atset1:46 */
|
"KeyC": 0x2e, /* html:KeyC (KeyC) -> linux:46 (KEY_C) -> atset1:46 */
|
||||||
"KeyD": 0x20, /* html:KeyD (KeyD) -> linux:32 (KEY_D) -> atset1:32 */
|
"KeyD": 0x20, /* html:KeyD (KeyD) -> linux:32 (KEY_D) -> atset1:32 */
|
||||||
"KeyE": 0x12, /* html:KeyE (KeyE) -> linux:18 (KEY_E) -> atset1:18 */
|
"KeyE": 0x12, /* html:KeyE (KeyE) -> linux:18 (KEY_E) -> atset1:18 */
|
||||||
"KeyF": 0x21, /* html:KeyF (KeyF) -> linux:33 (KEY_F) -> atset1:33 */
|
"KeyF": 0x21, /* html:KeyF (KeyF) -> linux:33 (KEY_F) -> atset1:33 */
|
||||||
"KeyG": 0x22, /* html:KeyG (KeyG) -> linux:34 (KEY_G) -> atset1:34 */
|
"KeyG": 0x22, /* html:KeyG (KeyG) -> linux:34 (KEY_G) -> atset1:34 */
|
||||||
"KeyH": 0x23, /* html:KeyH (KeyH) -> linux:35 (KEY_H) -> atset1:35 */
|
"KeyH": 0x23, /* html:KeyH (KeyH) -> linux:35 (KEY_H) -> atset1:35 */
|
||||||
"KeyI": 0x17, /* html:KeyI (KeyI) -> linux:23 (KEY_I) -> atset1:23 */
|
"KeyI": 0x17, /* html:KeyI (KeyI) -> linux:23 (KEY_I) -> atset1:23 */
|
||||||
"KeyJ": 0x24, /* html:KeyJ (KeyJ) -> linux:36 (KEY_J) -> atset1:36 */
|
"KeyJ": 0x24, /* html:KeyJ (KeyJ) -> linux:36 (KEY_J) -> atset1:36 */
|
||||||
"KeyK": 0x25, /* html:KeyK (KeyK) -> linux:37 (KEY_K) -> atset1:37 */
|
"KeyK": 0x25, /* html:KeyK (KeyK) -> linux:37 (KEY_K) -> atset1:37 */
|
||||||
"KeyL": 0x26, /* html:KeyL (KeyL) -> linux:38 (KEY_L) -> atset1:38 */
|
"KeyL": 0x26, /* html:KeyL (KeyL) -> linux:38 (KEY_L) -> atset1:38 */
|
||||||
"KeyM": 0x32, /* html:KeyM (KeyM) -> linux:50 (KEY_M) -> atset1:50 */
|
"KeyM": 0x32, /* html:KeyM (KeyM) -> linux:50 (KEY_M) -> atset1:50 */
|
||||||
"KeyN": 0x31, /* html:KeyN (KeyN) -> linux:49 (KEY_N) -> atset1:49 */
|
"KeyN": 0x31, /* html:KeyN (KeyN) -> linux:49 (KEY_N) -> atset1:49 */
|
||||||
"KeyO": 0x18, /* html:KeyO (KeyO) -> linux:24 (KEY_O) -> atset1:24 */
|
"KeyO": 0x18, /* html:KeyO (KeyO) -> linux:24 (KEY_O) -> atset1:24 */
|
||||||
"KeyP": 0x19, /* html:KeyP (KeyP) -> linux:25 (KEY_P) -> atset1:25 */
|
"KeyP": 0x19, /* html:KeyP (KeyP) -> linux:25 (KEY_P) -> atset1:25 */
|
||||||
"KeyQ": 0x10, /* html:KeyQ (KeyQ) -> linux:16 (KEY_Q) -> atset1:16 */
|
"KeyQ": 0x10, /* html:KeyQ (KeyQ) -> linux:16 (KEY_Q) -> atset1:16 */
|
||||||
"KeyR": 0x13, /* html:KeyR (KeyR) -> linux:19 (KEY_R) -> atset1:19 */
|
"KeyR": 0x13, /* html:KeyR (KeyR) -> linux:19 (KEY_R) -> atset1:19 */
|
||||||
"KeyS": 0x1f, /* html:KeyS (KeyS) -> linux:31 (KEY_S) -> atset1:31 */
|
"KeyS": 0x1f, /* html:KeyS (KeyS) -> linux:31 (KEY_S) -> atset1:31 */
|
||||||
"KeyT": 0x14, /* html:KeyT (KeyT) -> linux:20 (KEY_T) -> atset1:20 */
|
"KeyT": 0x14, /* html:KeyT (KeyT) -> linux:20 (KEY_T) -> atset1:20 */
|
||||||
"KeyU": 0x16, /* html:KeyU (KeyU) -> linux:22 (KEY_U) -> atset1:22 */
|
"KeyU": 0x16, /* html:KeyU (KeyU) -> linux:22 (KEY_U) -> atset1:22 */
|
||||||
"KeyV": 0x2f, /* html:KeyV (KeyV) -> linux:47 (KEY_V) -> atset1:47 */
|
"KeyV": 0x2f, /* html:KeyV (KeyV) -> linux:47 (KEY_V) -> atset1:47 */
|
||||||
"KeyW": 0x11, /* html:KeyW (KeyW) -> linux:17 (KEY_W) -> atset1:17 */
|
"KeyW": 0x11, /* html:KeyW (KeyW) -> linux:17 (KEY_W) -> atset1:17 */
|
||||||
"KeyX": 0x2d, /* html:KeyX (KeyX) -> linux:45 (KEY_X) -> atset1:45 */
|
"KeyX": 0x2d, /* html:KeyX (KeyX) -> linux:45 (KEY_X) -> atset1:45 */
|
||||||
"KeyY": 0x15, /* html:KeyY (KeyY) -> linux:21 (KEY_Y) -> atset1:21 */
|
"KeyY": 0x15, /* html:KeyY (KeyY) -> linux:21 (KEY_Y) -> atset1:21 */
|
||||||
"KeyZ": 0x2c, /* html:KeyZ (KeyZ) -> linux:44 (KEY_Z) -> atset1:44 */
|
"KeyZ": 0x2c, /* html:KeyZ (KeyZ) -> linux:44 (KEY_Z) -> atset1:44 */
|
||||||
"Lang3": 0x78, /* html:Lang3 (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
|
"Lang3": 0x78, /* html:Lang3 (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
|
||||||
"Lang4": 0x77, /* html:Lang4 (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
|
"Lang4": 0x77, /* html:Lang4 (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
|
||||||
"Lang5": 0x76, /* html:Lang5 (Lang5) -> linux:85 (KEY_ZENKAKUHANKAKU) -> atset1:118 */
|
"Lang5": 0x76, /* html:Lang5 (Lang5) -> linux:85 (KEY_ZENKAKUHANKAKU) -> atset1:118 */
|
||||||
"LaunchApp1": 0xe06b, /* html:LaunchApp1 (LaunchApp1) -> linux:157 (KEY_COMPUTER) -> atset1:57451 */
|
"LaunchApp1": 0xe06b, /* html:LaunchApp1 (LaunchApp1) -> linux:157 (KEY_COMPUTER) -> atset1:57451 */
|
||||||
"LaunchApp2": 0xe021, /* html:LaunchApp2 (LaunchApp2) -> linux:140 (KEY_CALC) -> atset1:57377 */
|
"LaunchApp2": 0xe021, /* html:LaunchApp2 (LaunchApp2) -> linux:140 (KEY_CALC) -> atset1:57377 */
|
||||||
"LaunchMail": 0xe06c, /* html:LaunchMail (LaunchMail) -> linux:155 (KEY_MAIL) -> atset1:57452 */
|
"LaunchMail": 0xe06c, /* html:LaunchMail (LaunchMail) -> linux:155 (KEY_MAIL) -> atset1:57452 */
|
||||||
"MediaPlayPause": 0xe022, /* html:MediaPlayPause (MediaPlayPause) -> linux:164 (KEY_PLAYPAUSE) -> atset1:57378 */
|
"MediaPlayPause": 0xe022, /* html:MediaPlayPause (MediaPlayPause) -> linux:164 (KEY_PLAYPAUSE) -> atset1:57378 */
|
||||||
"MediaSelect": 0xe06d, /* html:MediaSelect (MediaSelect) -> linux:226 (KEY_MEDIA) -> atset1:57453 */
|
"MediaSelect": 0xe06d, /* html:MediaSelect (MediaSelect) -> linux:226 (KEY_MEDIA) -> atset1:57453 */
|
||||||
"MediaStop": 0xe024, /* html:MediaStop (MediaStop) -> linux:166 (KEY_STOPCD) -> atset1:57380 */
|
"MediaStop": 0xe024, /* html:MediaStop (MediaStop) -> linux:166 (KEY_STOPCD) -> atset1:57380 */
|
||||||
"MediaTrackNext": 0xe019, /* html:MediaTrackNext (MediaTrackNext) -> linux:163 (KEY_NEXTSONG) -> atset1:57369 */
|
"MediaTrackNext": 0xe019, /* html:MediaTrackNext (MediaTrackNext) -> linux:163 (KEY_NEXTSONG) -> atset1:57369 */
|
||||||
"MediaTrackPrevious": 0xe010, /* html:MediaTrackPrevious (MediaTrackPrevious) -> linux:165 (KEY_PREVIOUSSONG) -> atset1:57360 */
|
"MediaTrackPrevious": 0xe010, /* html:MediaTrackPrevious (MediaTrackPrevious) -> linux:165 (KEY_PREVIOUSSONG) -> atset1:57360 */
|
||||||
"MetaLeft": 0xe05b, /* html:MetaLeft (MetaLeft) -> linux:125 (KEY_LEFTMETA) -> atset1:57435 */
|
"MetaLeft": 0xe05b, /* html:MetaLeft (MetaLeft) -> linux:125 (KEY_LEFTMETA) -> atset1:57435 */
|
||||||
"MetaRight": 0xe05c, /* html:MetaRight (MetaRight) -> linux:126 (KEY_RIGHTMETA) -> atset1:57436 */
|
"MetaRight": 0xe05c, /* html:MetaRight (MetaRight) -> linux:126 (KEY_RIGHTMETA) -> atset1:57436 */
|
||||||
"Minus": 0xc, /* html:Minus (Minus) -> linux:12 (KEY_MINUS) -> atset1:12 */
|
"Minus": 0xc, /* html:Minus (Minus) -> linux:12 (KEY_MINUS) -> atset1:12 */
|
||||||
"NonConvert": 0x7b, /* html:NonConvert (NonConvert) -> linux:94 (KEY_MUHENKAN) -> atset1:123 */
|
"NonConvert": 0x7b, /* html:NonConvert (NonConvert) -> linux:94 (KEY_MUHENKAN) -> atset1:123 */
|
||||||
"NumLock": 0x45, /* html:NumLock (NumLock) -> linux:69 (KEY_NUMLOCK) -> atset1:69 */
|
"NumLock": 0x45, /* html:NumLock (NumLock) -> linux:69 (KEY_NUMLOCK) -> atset1:69 */
|
||||||
"Numpad0": 0x52, /* html:Numpad0 (Numpad0) -> linux:82 (KEY_KP0) -> atset1:82 */
|
"Numpad0": 0x52, /* html:Numpad0 (Numpad0) -> linux:82 (KEY_KP0) -> atset1:82 */
|
||||||
"Numpad1": 0x4f, /* html:Numpad1 (Numpad1) -> linux:79 (KEY_KP1) -> atset1:79 */
|
"Numpad1": 0x4f, /* html:Numpad1 (Numpad1) -> linux:79 (KEY_KP1) -> atset1:79 */
|
||||||
"Numpad2": 0x50, /* html:Numpad2 (Numpad2) -> linux:80 (KEY_KP2) -> atset1:80 */
|
"Numpad2": 0x50, /* html:Numpad2 (Numpad2) -> linux:80 (KEY_KP2) -> atset1:80 */
|
||||||
"Numpad3": 0x51, /* html:Numpad3 (Numpad3) -> linux:81 (KEY_KP3) -> atset1:81 */
|
"Numpad3": 0x51, /* html:Numpad3 (Numpad3) -> linux:81 (KEY_KP3) -> atset1:81 */
|
||||||
"Numpad4": 0x4b, /* html:Numpad4 (Numpad4) -> linux:75 (KEY_KP4) -> atset1:75 */
|
"Numpad4": 0x4b, /* html:Numpad4 (Numpad4) -> linux:75 (KEY_KP4) -> atset1:75 */
|
||||||
"Numpad5": 0x4c, /* html:Numpad5 (Numpad5) -> linux:76 (KEY_KP5) -> atset1:76 */
|
"Numpad5": 0x4c, /* html:Numpad5 (Numpad5) -> linux:76 (KEY_KP5) -> atset1:76 */
|
||||||
"Numpad6": 0x4d, /* html:Numpad6 (Numpad6) -> linux:77 (KEY_KP6) -> atset1:77 */
|
"Numpad6": 0x4d, /* html:Numpad6 (Numpad6) -> linux:77 (KEY_KP6) -> atset1:77 */
|
||||||
"Numpad7": 0x47, /* html:Numpad7 (Numpad7) -> linux:71 (KEY_KP7) -> atset1:71 */
|
"Numpad7": 0x47, /* html:Numpad7 (Numpad7) -> linux:71 (KEY_KP7) -> atset1:71 */
|
||||||
"Numpad8": 0x48, /* html:Numpad8 (Numpad8) -> linux:72 (KEY_KP8) -> atset1:72 */
|
"Numpad8": 0x48, /* html:Numpad8 (Numpad8) -> linux:72 (KEY_KP8) -> atset1:72 */
|
||||||
"Numpad9": 0x49, /* html:Numpad9 (Numpad9) -> linux:73 (KEY_KP9) -> atset1:73 */
|
"Numpad9": 0x49, /* html:Numpad9 (Numpad9) -> linux:73 (KEY_KP9) -> atset1:73 */
|
||||||
"NumpadAdd": 0x4e, /* html:NumpadAdd (NumpadAdd) -> linux:78 (KEY_KPPLUS) -> atset1:78 */
|
"NumpadAdd": 0x4e, /* html:NumpadAdd (NumpadAdd) -> linux:78 (KEY_KPPLUS) -> atset1:78 */
|
||||||
"NumpadComma": 0x7e, /* html:NumpadComma (NumpadComma) -> linux:121 (KEY_KPCOMMA) -> atset1:126 */
|
"NumpadComma": 0x7e, /* html:NumpadComma (NumpadComma) -> linux:121 (KEY_KPCOMMA) -> atset1:126 */
|
||||||
"NumpadDecimal": 0x53, /* html:NumpadDecimal (NumpadDecimal) -> linux:83 (KEY_KPDOT) -> atset1:83 */
|
"NumpadDecimal": 0x53, /* html:NumpadDecimal (NumpadDecimal) -> linux:83 (KEY_KPDOT) -> atset1:83 */
|
||||||
"NumpadDivide": 0xe035, /* html:NumpadDivide (NumpadDivide) -> linux:98 (KEY_KPSLASH) -> atset1:57397 */
|
"NumpadDivide": 0xe035, /* html:NumpadDivide (NumpadDivide) -> linux:98 (KEY_KPSLASH) -> atset1:57397 */
|
||||||
"NumpadEnter": 0xe01c, /* html:NumpadEnter (NumpadEnter) -> linux:96 (KEY_KPENTER) -> atset1:57372 */
|
"NumpadEnter": 0xe01c, /* html:NumpadEnter (NumpadEnter) -> linux:96 (KEY_KPENTER) -> atset1:57372 */
|
||||||
"NumpadEqual": 0x59, /* html:NumpadEqual (NumpadEqual) -> linux:117 (KEY_KPEQUAL) -> atset1:89 */
|
"NumpadEqual": 0x59, /* html:NumpadEqual (NumpadEqual) -> linux:117 (KEY_KPEQUAL) -> atset1:89 */
|
||||||
"NumpadMultiply": 0x37, /* html:NumpadMultiply (NumpadMultiply) -> linux:55 (KEY_KPASTERISK) -> atset1:55 */
|
"NumpadMultiply": 0x37, /* html:NumpadMultiply (NumpadMultiply) -> linux:55 (KEY_KPASTERISK) -> atset1:55 */
|
||||||
"NumpadParenLeft": 0xe076, /* html:NumpadParenLeft (NumpadParenLeft) -> linux:179 (KEY_KPLEFTPAREN) -> atset1:57462 */
|
"NumpadParenLeft": 0xe076, /* html:NumpadParenLeft (NumpadParenLeft) -> linux:179 (KEY_KPLEFTPAREN) -> atset1:57462 */
|
||||||
"NumpadParenRight": 0xe07b, /* html:NumpadParenRight (NumpadParenRight) -> linux:180 (KEY_KPRIGHTPAREN) -> atset1:57467 */
|
"NumpadParenRight": 0xe07b, /* html:NumpadParenRight (NumpadParenRight) -> linux:180 (KEY_KPRIGHTPAREN) -> atset1:57467 */
|
||||||
"NumpadSubtract": 0x4a, /* html:NumpadSubtract (NumpadSubtract) -> linux:74 (KEY_KPMINUS) -> atset1:74 */
|
"NumpadSubtract": 0x4a, /* html:NumpadSubtract (NumpadSubtract) -> linux:74 (KEY_KPMINUS) -> atset1:74 */
|
||||||
"Open": 0x64, /* html:Open (Open) -> linux:134 (KEY_OPEN) -> atset1:100 */
|
"Open": 0x64, /* html:Open (Open) -> linux:134 (KEY_OPEN) -> atset1:100 */
|
||||||
"PageDown": 0xe051, /* html:PageDown (PageDown) -> linux:109 (KEY_PAGEDOWN) -> atset1:57425 */
|
"PageDown": 0xe051, /* html:PageDown (PageDown) -> linux:109 (KEY_PAGEDOWN) -> atset1:57425 */
|
||||||
"PageUp": 0xe049, /* html:PageUp (PageUp) -> linux:104 (KEY_PAGEUP) -> atset1:57417 */
|
"PageUp": 0xe049, /* html:PageUp (PageUp) -> linux:104 (KEY_PAGEUP) -> atset1:57417 */
|
||||||
"Paste": 0x65, /* html:Paste (Paste) -> linux:135 (KEY_PASTE) -> atset1:101 */
|
"Paste": 0x65, /* html:Paste (Paste) -> linux:135 (KEY_PASTE) -> atset1:101 */
|
||||||
"Pause": 0xe046, /* html:Pause (Pause) -> linux:119 (KEY_PAUSE) -> atset1:57414 */
|
"Pause": 0xe046, /* html:Pause (Pause) -> linux:119 (KEY_PAUSE) -> atset1:57414 */
|
||||||
"Period": 0x34, /* html:Period (Period) -> linux:52 (KEY_DOT) -> atset1:52 */
|
"Period": 0x34, /* html:Period (Period) -> linux:52 (KEY_DOT) -> atset1:52 */
|
||||||
"Power": 0xe05e, /* html:Power (Power) -> linux:116 (KEY_POWER) -> atset1:57438 */
|
"Power": 0xe05e, /* html:Power (Power) -> linux:116 (KEY_POWER) -> atset1:57438 */
|
||||||
"PrintScreen": 0x54, /* html:PrintScreen (PrintScreen) -> linux:99 (KEY_SYSRQ) -> atset1:84 */
|
"PrintScreen": 0x54, /* html:PrintScreen (PrintScreen) -> linux:99 (KEY_SYSRQ) -> atset1:84 */
|
||||||
"Props": 0xe006, /* html:Props (Props) -> linux:130 (KEY_PROPS) -> atset1:57350 */
|
"Props": 0xe006, /* html:Props (Props) -> linux:130 (KEY_PROPS) -> atset1:57350 */
|
||||||
"Quote": 0x28, /* html:Quote (Quote) -> linux:40 (KEY_APOSTROPHE) -> atset1:40 */
|
"Quote": 0x28, /* html:Quote (Quote) -> linux:40 (KEY_APOSTROPHE) -> atset1:40 */
|
||||||
"ScrollLock": 0x46, /* html:ScrollLock (ScrollLock) -> linux:70 (KEY_SCROLLLOCK) -> atset1:70 */
|
"ScrollLock": 0x46, /* html:ScrollLock (ScrollLock) -> linux:70 (KEY_SCROLLLOCK) -> atset1:70 */
|
||||||
"Semicolon": 0x27, /* html:Semicolon (Semicolon) -> linux:39 (KEY_SEMICOLON) -> atset1:39 */
|
"Semicolon": 0x27, /* html:Semicolon (Semicolon) -> linux:39 (KEY_SEMICOLON) -> atset1:39 */
|
||||||
"ShiftLeft": 0x2a, /* html:ShiftLeft (ShiftLeft) -> linux:42 (KEY_LEFTSHIFT) -> atset1:42 */
|
"ShiftLeft": 0x2a, /* html:ShiftLeft (ShiftLeft) -> linux:42 (KEY_LEFTSHIFT) -> atset1:42 */
|
||||||
"ShiftRight": 0x36, /* html:ShiftRight (ShiftRight) -> linux:54 (KEY_RIGHTSHIFT) -> atset1:54 */
|
"ShiftRight": 0x36, /* html:ShiftRight (ShiftRight) -> linux:54 (KEY_RIGHTSHIFT) -> atset1:54 */
|
||||||
"Slash": 0x35, /* html:Slash (Slash) -> linux:53 (KEY_SLASH) -> atset1:53 */
|
"Slash": 0x35, /* html:Slash (Slash) -> linux:53 (KEY_SLASH) -> atset1:53 */
|
||||||
"Sleep": 0xe05f, /* html:Sleep (Sleep) -> linux:142 (KEY_SLEEP) -> atset1:57439 */
|
"Sleep": 0xe05f, /* html:Sleep (Sleep) -> linux:142 (KEY_SLEEP) -> atset1:57439 */
|
||||||
"Space": 0x39, /* html:Space (Space) -> linux:57 (KEY_SPACE) -> atset1:57 */
|
"Space": 0x39, /* html:Space (Space) -> linux:57 (KEY_SPACE) -> atset1:57 */
|
||||||
"Suspend": 0xe025, /* html:Suspend (Suspend) -> linux:205 (KEY_SUSPEND) -> atset1:57381 */
|
"Suspend": 0xe025, /* html:Suspend (Suspend) -> linux:205 (KEY_SUSPEND) -> atset1:57381 */
|
||||||
"Tab": 0xf, /* html:Tab (Tab) -> linux:15 (KEY_TAB) -> atset1:15 */
|
"Tab": 0xf, /* html:Tab (Tab) -> linux:15 (KEY_TAB) -> atset1:15 */
|
||||||
"Undo": 0xe007, /* html:Undo (Undo) -> linux:131 (KEY_UNDO) -> atset1:57351 */
|
"Undo": 0xe007, /* html:Undo (Undo) -> linux:131 (KEY_UNDO) -> atset1:57351 */
|
||||||
"WakeUp": 0xe063, /* html:WakeUp (WakeUp) -> linux:143 (KEY_WAKEUP) -> atset1:57443 */
|
"WakeUp": 0xe063, /* html:WakeUp (WakeUp) -> linux:143 (KEY_WAKEUP) -> atset1:57443 */
|
||||||
};
|
};
|
||||||
|
|
|
||||||
1182
core/rfb.js
1182
core/rfb.js
File diff suppressed because it is too large
Load Diff
|
|
@ -8,24 +8,48 @@
|
||||||
|
|
||||||
import * as Log from './logging.js';
|
import * as Log from './logging.js';
|
||||||
|
|
||||||
|
export function isMac() {
|
||||||
|
return navigator && !!(/mac/i).exec(navigator.platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isIE() {
|
||||||
|
return navigator && !!(/trident/i).exec(navigator.userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isEdge() {
|
||||||
|
return navigator && !!(/edge/i).exec(navigator.userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isWindows() {
|
||||||
|
return navigator && !!(/win/i).exec(navigator.platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isIOS() {
|
||||||
|
return navigator &&
|
||||||
|
(!!(/ipad/i).exec(navigator.platform) ||
|
||||||
|
!!(/iphone/i).exec(navigator.platform) ||
|
||||||
|
!!(/ipod/i).exec(navigator.platform));
|
||||||
|
}
|
||||||
|
|
||||||
// Touch detection
|
// Touch detection
|
||||||
export var isTouchDevice = ('ontouchstart' in document.documentElement) ||
|
export let isTouchDevice = ('ontouchstart' in document.documentElement) ||
|
||||||
// requried for Chrome debugger
|
// requried for Chrome debugger
|
||||||
(document.ontouchstart !== undefined) ||
|
(document.ontouchstart !== undefined) ||
|
||||||
// required for MS Surface
|
// required for MS Surface
|
||||||
(navigator.maxTouchPoints > 0) ||
|
(navigator.maxTouchPoints > 0) ||
|
||||||
(navigator.msMaxTouchPoints > 0);
|
(navigator.msMaxTouchPoints > 0);
|
||||||
|
|
||||||
window.addEventListener('touchstart', function onFirstTouch() {
|
window.addEventListener('touchstart', function onFirstTouch() {
|
||||||
isTouchDevice = true;
|
isTouchDevice = true;
|
||||||
window.removeEventListener('touchstart', onFirstTouch, false);
|
window.removeEventListener('touchstart', onFirstTouch, false);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
var _cursor_uris_supported = null;
|
let _cursor_uris_supported = null;
|
||||||
|
|
||||||
export function browserSupportsCursorURIs () {
|
export function browserSupportsCursorURIs () {
|
||||||
if (_cursor_uris_supported === null) {
|
if (_cursor_uris_supported !== null) {
|
||||||
try {
|
try {
|
||||||
var target = document.createElement('canvas');
|
const target = document.createElement('canvas');
|
||||||
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
|
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
|
||||||
|
|
||||||
if (target.style.cursor) {
|
if (target.style.cursor) {
|
||||||
|
|
@ -42,4 +66,4 @@ export function browserSupportsCursorURIs () {
|
||||||
}
|
}
|
||||||
|
|
||||||
return _cursor_uris_supported;
|
return _cursor_uris_supported;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,26 +10,24 @@
|
||||||
* Cross-browser event and position routines
|
* Cross-browser event and position routines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Log from './logging.js';
|
|
||||||
|
|
||||||
export function getPointerEvent (e) {
|
export function getPointerEvent (e) {
|
||||||
return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;
|
return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;
|
||||||
};
|
}
|
||||||
|
|
||||||
export function stopEvent (e) {
|
export function stopEvent (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
}
|
||||||
|
|
||||||
// Emulate Element.setCapture() when not supported
|
// Emulate Element.setCapture() when not supported
|
||||||
var _captureRecursion = false;
|
let _captureRecursion = false;
|
||||||
var _captureElem = null;
|
let _captureElem = null;
|
||||||
function _captureProxy(e) {
|
function _captureProxy(e) {
|
||||||
// Recursion protection as we'll see our own event
|
// Recursion protection as we'll see our own event
|
||||||
if (_captureRecursion) return;
|
if (_captureRecursion) return;
|
||||||
|
|
||||||
// Clone the event as we cannot dispatch an already dispatched event
|
// Clone the event as we cannot dispatch an already dispatched event
|
||||||
var newEv = new e.constructor(e.type, e);
|
const newEv = new e.constructor(e.type, e);
|
||||||
|
|
||||||
_captureRecursion = true;
|
_captureRecursion = true;
|
||||||
_captureElem.dispatchEvent(newEv);
|
_captureElem.dispatchEvent(newEv);
|
||||||
|
|
@ -47,16 +45,17 @@ function _captureProxy(e) {
|
||||||
if (e.type === "mouseup") {
|
if (e.type === "mouseup") {
|
||||||
releaseCapture();
|
releaseCapture();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Follow cursor style of target element
|
// Follow cursor style of target element
|
||||||
function _captureElemChanged() {
|
function _captureElemChanged() {
|
||||||
var captureElem = document.getElementById("noVNC_mouse_capture_elem");
|
const captureElem = document.getElementById("noVNC_mouse_capture_elem");
|
||||||
captureElem.style.cursor = window.getComputedStyle(_captureElem).cursor;
|
captureElem.style.cursor = window.getComputedStyle(_captureElem).cursor;
|
||||||
};
|
}
|
||||||
var _captureObserver = new MutationObserver(_captureElemChanged);
|
|
||||||
|
|
||||||
var _captureIndex = 0;
|
let _captureObserver = new MutationObserver(_captureElemChanged);
|
||||||
|
|
||||||
|
let _captureIndex = 0;
|
||||||
|
|
||||||
export function setCapture (elem) {
|
export function setCapture (elem) {
|
||||||
if (elem.setCapture) {
|
if (elem.setCapture) {
|
||||||
|
|
@ -71,7 +70,7 @@ export function setCapture (elem) {
|
||||||
// called multiple times without coordination
|
// called multiple times without coordination
|
||||||
releaseCapture();
|
releaseCapture();
|
||||||
|
|
||||||
var captureElem = document.getElementById("noVNC_mouse_capture_elem");
|
let captureElem = document.getElementById("noVNC_mouse_capture_elem");
|
||||||
|
|
||||||
if (captureElem === null) {
|
if (captureElem === null) {
|
||||||
captureElem = document.createElement("div");
|
captureElem = document.createElement("div");
|
||||||
|
|
@ -107,13 +106,11 @@ export function setCapture (elem) {
|
||||||
window.addEventListener('mousemove', _captureProxy);
|
window.addEventListener('mousemove', _captureProxy);
|
||||||
window.addEventListener('mouseup', _captureProxy);
|
window.addEventListener('mouseup', _captureProxy);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function releaseCapture () {
|
export function releaseCapture () {
|
||||||
if (document.releaseCapture) {
|
if (document.releaseCapture) {
|
||||||
|
|
||||||
document.releaseCapture();
|
document.releaseCapture();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!_captureElem) {
|
if (!_captureElem) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -121,7 +118,7 @@ export function releaseCapture () {
|
||||||
|
|
||||||
// There might be events already queued, so we need to wait for
|
// There might be events already queued, so we need to wait for
|
||||||
// them to flush. E.g. contextmenu in Microsoft Edge
|
// them to flush. E.g. contextmenu in Microsoft Edge
|
||||||
window.setTimeout(function(expected) {
|
window.setTimeout((expected) => {
|
||||||
// Only clear it if it's the expected grab (i.e. no one
|
// Only clear it if it's the expected grab (i.e. no one
|
||||||
// else has initiated a new grab)
|
// else has initiated a new grab)
|
||||||
if (_captureIndex === expected) {
|
if (_captureIndex === expected) {
|
||||||
|
|
@ -131,10 +128,10 @@ export function releaseCapture () {
|
||||||
|
|
||||||
_captureObserver.disconnect();
|
_captureObserver.disconnect();
|
||||||
|
|
||||||
var captureElem = document.getElementById("noVNC_mouse_capture_elem");
|
const captureElem = document.getElementById("noVNC_mouse_capture_elem");
|
||||||
captureElem.style.display = "none";
|
captureElem.style.display = "none";
|
||||||
|
|
||||||
window.removeEventListener('mousemove', _captureProxy);
|
window.removeEventListener('mousemove', _captureProxy);
|
||||||
window.removeEventListener('mouseup', _captureProxy);
|
window.removeEventListener('mouseup', _captureProxy);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,12 @@
|
||||||
* See README.md for usage and integration instructions.
|
* See README.md for usage and integration instructions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var EventTargetMixin = {
|
export default class EventTargetMixin {
|
||||||
_listeners: null,
|
constructor() {
|
||||||
|
this._listeners = null;
|
||||||
|
}
|
||||||
|
|
||||||
addEventListener: function(type, callback) {
|
addEventListener(type, callback) {
|
||||||
if (!this._listeners) {
|
if (!this._listeners) {
|
||||||
this._listeners = new Map();
|
this._listeners = new Map();
|
||||||
}
|
}
|
||||||
|
|
@ -17,24 +19,22 @@ var EventTargetMixin = {
|
||||||
this._listeners.set(type, new Set());
|
this._listeners.set(type, new Set());
|
||||||
}
|
}
|
||||||
this._listeners.get(type).add(callback);
|
this._listeners.get(type).add(callback);
|
||||||
},
|
}
|
||||||
|
|
||||||
removeEventListener: function(type, callback) {
|
removeEventListener(type, callback) {
|
||||||
if (!this._listeners || !this._listeners.has(type)) {
|
if (!this._listeners || !this._listeners.has(type)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._listeners.get(type).delete(callback);
|
this._listeners.get(type).delete(callback);
|
||||||
},
|
}
|
||||||
|
|
||||||
dispatchEvent: function(event) {
|
dispatchEvent(event) {
|
||||||
if (!this._listeners || !this._listeners.has(event.type)) {
|
if (!this._listeners || !this._listeners.has(event.type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this._listeners.get(event.type).forEach(function (callback) {
|
this._listeners.get(event.type).forEach((callback) => {
|
||||||
callback.call(this, event);
|
callback.call(this, event);
|
||||||
}, this);
|
}, this);
|
||||||
return !event.defaultPrevented;
|
return !event.defaultPrevented;
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default EventTargetMixin;
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@
|
||||||
* Logging/debug routines
|
* Logging/debug routines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var _log_level = 'warn';
|
let _log_level = 'warn';
|
||||||
|
|
||||||
var Debug = function (msg) {};
|
let Debug = () => {};
|
||||||
var Info = function (msg) {};
|
let Info = () => {};
|
||||||
var Warn = function (msg) {};
|
let Warn = () => {};
|
||||||
var Error = function (msg) {};
|
let Error = () => {};
|
||||||
|
|
||||||
export function init_logging (level) {
|
export function init_logging (level) {
|
||||||
if (typeof level === 'undefined') {
|
if (typeof level === 'undefined') {
|
||||||
|
|
@ -24,9 +24,9 @@ export function init_logging (level) {
|
||||||
_log_level = level;
|
_log_level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug = Info = Warn = Error = function (msg) {};
|
Debug = Info = Warn = Error = () => {};
|
||||||
if (typeof window.console !== "undefined") {
|
if (typeof window.console !== "undefined") {
|
||||||
/* jshint -W086 */
|
/* eslint-disable no-fallthrough, no-console */
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case 'debug':
|
case 'debug':
|
||||||
Debug = console.debug.bind(window.console);
|
Debug = console.debug.bind(window.console);
|
||||||
|
|
@ -41,12 +41,14 @@ export function init_logging (level) {
|
||||||
default:
|
default:
|
||||||
throw new Error("invalid logging type '" + level + "'");
|
throw new Error("invalid logging type '" + level + "'");
|
||||||
}
|
}
|
||||||
/* jshint +W086 */
|
/* eslint-enable no-fallthrough, no-console */
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export function get_logging () {
|
export function get_logging () {
|
||||||
return _log_level;
|
return _log_level;
|
||||||
};
|
}
|
||||||
|
|
||||||
export { Debug, Info, Warn, Error };
|
export { Debug, Info, Warn, Error };
|
||||||
|
|
||||||
// Initialize logging level
|
// Initialize logging level
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,18 @@
|
||||||
if (typeof Object.assign != 'function') {
|
if (typeof Object.assign != 'function') {
|
||||||
// Must be writable: true, enumerable: false, configurable: true
|
// Must be writable: true, enumerable: false, configurable: true
|
||||||
Object.defineProperty(Object, "assign", {
|
Object.defineProperty(Object, "assign", {
|
||||||
value: function assign(target, varArgs) { // .length of function is 2
|
value(target) { // .length of function is 2
|
||||||
'use strict';
|
|
||||||
if (target == null) { // TypeError if undefined or null
|
if (target == null) { // TypeError if undefined or null
|
||||||
throw new TypeError('Cannot convert undefined or null to object');
|
throw new TypeError('Cannot convert undefined or null to object');
|
||||||
}
|
}
|
||||||
|
|
||||||
var to = Object(target);
|
const to = Object(target);
|
||||||
|
|
||||||
for (var index = 1; index < arguments.length; index++) {
|
for (let index = 1; index < arguments.length; index++) {
|
||||||
var nextSource = arguments[index];
|
const nextSource = arguments[index];
|
||||||
|
|
||||||
if (nextSource != null) { // Skip over if undefined or null
|
if (nextSource != null) { // Skip over if undefined or null
|
||||||
for (var nextKey in nextSource) {
|
for (let nextKey in nextSource) {
|
||||||
// Avoid bugs when hasOwnProperty is shadowed
|
// Avoid bugs when hasOwnProperty is shadowed
|
||||||
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
||||||
to[nextKey] = nextSource[nextKey];
|
to[nextKey] = nextSource[nextKey];
|
||||||
|
|
@ -38,17 +37,17 @@ if (typeof Object.assign != 'function') {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CustomEvent constructor (taken from MDN) */
|
/* CustomEvent constructor (taken from MDN) */
|
||||||
(function () {
|
(() => {
|
||||||
function CustomEvent ( event, params ) {
|
function CustomEvent( event, params ) {
|
||||||
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
||||||
var evt = document.createEvent( 'CustomEvent' );
|
const evt = document.createEvent( 'CustomEvent' );
|
||||||
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
|
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomEvent.prototype = window.Event.prototype;
|
CustomEvent.prototype = window.Event.prototype;
|
||||||
|
|
||||||
if (typeof window.CustomEvent !== "function") {
|
if (typeof window.CustomEvent !== 'function') {
|
||||||
window.CustomEvent = CustomEvent;
|
window.CustomEvent = CustomEvent;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,5 @@
|
||||||
* Decode from UTF-8
|
* Decode from UTF-8
|
||||||
*/
|
*/
|
||||||
export function decodeUTF8 (utf8string) {
|
export function decodeUTF8 (utf8string) {
|
||||||
"use strict";
|
|
||||||
return decodeURIComponent(escape(utf8string));
|
return decodeURIComponent(escape(utf8string));
|
||||||
};
|
}
|
||||||
|
|
|
||||||
261
core/websock.js
261
core/websock.js
|
|
@ -14,207 +14,199 @@
|
||||||
|
|
||||||
import * as Log from './util/logging.js';
|
import * as Log from './util/logging.js';
|
||||||
|
|
||||||
/*jslint browser: true, bitwise: true */
|
|
||||||
/*global Util*/
|
|
||||||
|
|
||||||
export default function Websock() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
this._websocket = null; // WebSocket object
|
|
||||||
|
|
||||||
this._rQi = 0; // Receive queue index
|
|
||||||
this._rQlen = 0; // Next write position in the receive queue
|
|
||||||
this._rQbufferSize = 1024 * 1024 * 4; // Receive queue buffer size (4 MiB)
|
|
||||||
this._rQmax = this._rQbufferSize / 8;
|
|
||||||
// called in init: this._rQ = new Uint8Array(this._rQbufferSize);
|
|
||||||
this._rQ = null; // Receive queue
|
|
||||||
|
|
||||||
this._sQbufferSize = 1024 * 10; // 10 KiB
|
|
||||||
// called in init: this._sQ = new Uint8Array(this._sQbufferSize);
|
|
||||||
this._sQlen = 0;
|
|
||||||
this._sQ = null; // Send queue
|
|
||||||
|
|
||||||
this._eventHandlers = {
|
|
||||||
'message': function () {},
|
|
||||||
'open': function () {},
|
|
||||||
'close': function () {},
|
|
||||||
'error': function () {}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// this has performance issues in some versions Chromium, and
|
// this has performance issues in some versions Chromium, and
|
||||||
// doesn't gain a tremendous amount of performance increase in Firefox
|
// doesn't gain a tremendous amount of performance increase in Firefox
|
||||||
// at the moment. It may be valuable to turn it on in the future.
|
// at the moment. It may be valuable to turn it on in the future.
|
||||||
var ENABLE_COPYWITHIN = false;
|
const ENABLE_COPYWITHIN = false;
|
||||||
|
|
||||||
var MAX_RQ_GROW_SIZE = 40 * 1024 * 1024; // 40 MiB
|
const MAX_RQ_GROW_SIZE = 40 * 1024 * 1024; // 40 MiB
|
||||||
|
|
||||||
var typedArrayToString = (function () {
|
const typedArrayToString = (() => {
|
||||||
// This is only for PhantomJS, which doesn't like apply-ing
|
// This is only for PhantomJS, which doesn't like apply-ing
|
||||||
// with Typed Arrays
|
// with Typed Arrays
|
||||||
try {
|
try {
|
||||||
var arr = new Uint8Array([1, 2, 3]);
|
const arr = new Uint8Array([1, 2, 3]);
|
||||||
String.fromCharCode.apply(null, arr);
|
String.fromCharCode.apply(null, arr);
|
||||||
return function (a) { return String.fromCharCode.apply(null, a); };
|
return (a) => String.fromCharCode.apply(null, a);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return function (a) {
|
return (a) =>
|
||||||
return String.fromCharCode.apply(
|
String.fromCharCode.apply(
|
||||||
null, Array.prototype.slice.call(a));
|
null, Array.prototype.slice.call(a));
|
||||||
};
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
Websock.prototype = {
|
export default class Websock {
|
||||||
|
constructor() {
|
||||||
|
this._websocket = null; // WebSocket object
|
||||||
|
|
||||||
|
this._rQi = 0; // Receive queue index
|
||||||
|
this._rQlen = 0; // Next write position in the receive queue
|
||||||
|
this._rQbufferSize = 1024 * 1024 * 4; // Receive queue buffer size (4 MiB)
|
||||||
|
this._rQmax = this._rQbufferSize / 8;
|
||||||
|
// called in init: this._rQ = new Uint8Array(this._rQbufferSize);
|
||||||
|
this._rQ = null; // Receive queue
|
||||||
|
|
||||||
|
this._sQbufferSize = 1024 * 10; // 10 KiB
|
||||||
|
// called in init: this._sQ = new Uint8Array(this._sQbufferSize);
|
||||||
|
this._sQlen = 0;
|
||||||
|
this._sQ = null; // Send queue
|
||||||
|
|
||||||
|
this._eventHandlers = {
|
||||||
|
'message'() {},
|
||||||
|
'open'() {},
|
||||||
|
'close'() {},
|
||||||
|
'error'() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Getters and Setters
|
// Getters and Setters
|
||||||
get_sQ: function () {
|
get_sQ() {
|
||||||
return this._sQ;
|
return this._sQ;
|
||||||
},
|
}
|
||||||
|
|
||||||
get_rQ: function () {
|
get_rQ() {
|
||||||
return this._rQ;
|
return this._rQ;
|
||||||
},
|
}
|
||||||
|
|
||||||
get_rQi: function () {
|
get_rQi() {
|
||||||
return this._rQi;
|
return this._rQi;
|
||||||
},
|
}
|
||||||
|
|
||||||
set_rQi: function (val) {
|
set_rQi(val) {
|
||||||
this._rQi = val;
|
this._rQi = val;
|
||||||
},
|
}
|
||||||
|
|
||||||
// Receive Queue
|
// Receive Queue
|
||||||
rQlen: function () {
|
rQlen() {
|
||||||
return this._rQlen - this._rQi;
|
return this._rQlen - this._rQi;
|
||||||
},
|
}
|
||||||
|
|
||||||
rQpeek8: function () {
|
rQpeek8() {
|
||||||
return this._rQ[this._rQi];
|
return this._rQ[this._rQi];
|
||||||
},
|
}
|
||||||
|
|
||||||
rQshift8: function () {
|
rQshift8() {
|
||||||
return this._rQ[this._rQi++];
|
return this._rQ[this._rQi++];
|
||||||
},
|
}
|
||||||
|
|
||||||
rQskip8: function () {
|
rQskip8() {
|
||||||
this._rQi++;
|
this._rQi++;
|
||||||
},
|
}
|
||||||
|
|
||||||
rQskipBytes: function (num) {
|
rQskipBytes(num) {
|
||||||
this._rQi += num;
|
this._rQi += num;
|
||||||
},
|
}
|
||||||
|
|
||||||
// TODO(directxman12): test performance with these vs a DataView
|
// TODO(directxman12): test performance with these vs a DataView
|
||||||
rQshift16: function () {
|
rQshift16() {
|
||||||
return (this._rQ[this._rQi++] << 8) +
|
return (this._rQ[this._rQi++] << 8) +
|
||||||
this._rQ[this._rQi++];
|
this._rQ[this._rQi++];
|
||||||
},
|
}
|
||||||
|
|
||||||
rQshift32: function () {
|
rQshift32() {
|
||||||
return (this._rQ[this._rQi++] << 24) +
|
return (this._rQ[this._rQi++] << 24) +
|
||||||
(this._rQ[this._rQi++] << 16) +
|
(this._rQ[this._rQi++] << 16) +
|
||||||
(this._rQ[this._rQi++] << 8) +
|
(this._rQ[this._rQi++] << 8) +
|
||||||
this._rQ[this._rQi++];
|
this._rQ[this._rQi++];
|
||||||
},
|
}
|
||||||
|
|
||||||
rQshiftStr: function (len) {
|
rQshiftStr(len) {
|
||||||
if (typeof(len) === 'undefined') { len = this.rQlen(); }
|
if (typeof(len) === 'undefined') { len = this.rQlen(); }
|
||||||
var arr = new Uint8Array(this._rQ.buffer, this._rQi, len);
|
const arr = new Uint8Array(this._rQ.buffer, this._rQi, len);
|
||||||
this._rQi += len;
|
this._rQi += len;
|
||||||
return typedArrayToString(arr);
|
return typedArrayToString(arr);
|
||||||
},
|
}
|
||||||
|
|
||||||
rQshiftBytes: function (len) {
|
rQshiftBytes(len) {
|
||||||
if (typeof(len) === 'undefined') { len = this.rQlen(); }
|
if (typeof(len) === 'undefined') { len = this.rQlen(); }
|
||||||
this._rQi += len;
|
this._rQi += len;
|
||||||
return new Uint8Array(this._rQ.buffer, this._rQi - len, len);
|
return new Uint8Array(this._rQ.buffer, this._rQi - len, len);
|
||||||
},
|
}
|
||||||
|
|
||||||
rQshiftTo: function (target, len) {
|
rQshiftTo(target, len) {
|
||||||
if (len === undefined) { len = this.rQlen(); }
|
if (len === undefined) { len = this.rQlen(); }
|
||||||
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ
|
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ
|
||||||
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len));
|
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len));
|
||||||
this._rQi += len;
|
this._rQi += len;
|
||||||
},
|
}
|
||||||
|
|
||||||
rQwhole: function () {
|
rQwhole() {
|
||||||
return new Uint8Array(this._rQ.buffer, 0, this._rQlen);
|
return new Uint8Array(this._rQ.buffer, 0, this._rQlen);
|
||||||
},
|
}
|
||||||
|
|
||||||
rQslice: function (start, end) {
|
rQslice(start, end) {
|
||||||
if (end) {
|
if (end) {
|
||||||
return new Uint8Array(this._rQ.buffer, this._rQi + start, end - start);
|
return new Uint8Array(this._rQ.buffer, this._rQi + start, end - start);
|
||||||
} else {
|
} else {
|
||||||
return new Uint8Array(this._rQ.buffer, this._rQi + start, this._rQlen - this._rQi - start);
|
return new Uint8Array(this._rQ.buffer, this._rQi + start, this._rQlen - this._rQi - start);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
|
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
|
||||||
// to be available in the receive queue. Return true if we need to
|
// to be available in the receive queue. Return true if we need to
|
||||||
// wait (and possibly print a debug message), otherwise false.
|
// wait (and possibly print a debug message), otherwise false.
|
||||||
rQwait: function (msg, num, goback) {
|
rQwait(msg, num, goback) {
|
||||||
var rQlen = this._rQlen - this._rQi; // Skip rQlen() function call
|
const rQlen = this._rQlen - this._rQi; // Skip rQlen() function call
|
||||||
if (rQlen < num) {
|
if (rQlen >= num) {
|
||||||
if (goback) {
|
return false;
|
||||||
if (this._rQi < goback) {
|
|
||||||
throw new Error("rQwait cannot backup " + goback + " bytes");
|
|
||||||
}
|
|
||||||
this._rQi -= goback;
|
|
||||||
}
|
|
||||||
return true; // true means need more data
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
},
|
if (goback) {
|
||||||
|
if (this._rQi < goback) {
|
||||||
|
throw new Error("rQwait cannot backup " + goback + " bytes");
|
||||||
|
}
|
||||||
|
this._rQi -= goback;
|
||||||
|
}
|
||||||
|
return true; // true means need more data
|
||||||
|
}
|
||||||
|
|
||||||
// Send Queue
|
// Send Queue
|
||||||
|
|
||||||
flush: function () {
|
flush() {
|
||||||
if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) {
|
if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) {
|
||||||
this._websocket.send(this._encode_message());
|
this._websocket.send(this._encode_message());
|
||||||
this._sQlen = 0;
|
this._sQlen = 0;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
send: function (arr) {
|
send(arr) {
|
||||||
this._sQ.set(arr, this._sQlen);
|
this._sQ.set(arr, this._sQlen);
|
||||||
this._sQlen += arr.length;
|
this._sQlen += arr.length;
|
||||||
this.flush();
|
this.flush();
|
||||||
},
|
}
|
||||||
|
|
||||||
send_string: function (str) {
|
send_string(str) {
|
||||||
this.send(str.split('').map(function (chr) {
|
this.send(str.split('').map(chr => chr.charCodeAt(0)));
|
||||||
return chr.charCodeAt(0);
|
}
|
||||||
}));
|
|
||||||
},
|
|
||||||
|
|
||||||
// Event Handlers
|
// Event Handlers
|
||||||
off: function (evt) {
|
off(evt) {
|
||||||
this._eventHandlers[evt] = function () {};
|
this._eventHandlers[evt] = () => {};
|
||||||
},
|
}
|
||||||
|
|
||||||
on: function (evt, handler) {
|
on(evt, handler) {
|
||||||
this._eventHandlers[evt] = handler;
|
this._eventHandlers[evt] = handler;
|
||||||
},
|
}
|
||||||
|
|
||||||
_allocate_buffers: function () {
|
_allocate_buffers() {
|
||||||
this._rQ = new Uint8Array(this._rQbufferSize);
|
this._rQ = new Uint8Array(this._rQbufferSize);
|
||||||
this._sQ = new Uint8Array(this._sQbufferSize);
|
this._sQ = new Uint8Array(this._sQbufferSize);
|
||||||
},
|
}
|
||||||
|
|
||||||
init: function () {
|
init() {
|
||||||
this._allocate_buffers();
|
this._allocate_buffers();
|
||||||
this._rQi = 0;
|
this._rQi = 0;
|
||||||
this._websocket = null;
|
this._websocket = null;
|
||||||
},
|
}
|
||||||
|
|
||||||
open: function (uri, protocols) {
|
open(uri, protocols) {
|
||||||
var ws_schema = uri.match(/^([a-z]+):\/\//)[1];
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
this._websocket = new WebSocket(uri, protocols);
|
this._websocket = new WebSocket(uri, protocols);
|
||||||
this._websocket.binaryType = 'arraybuffer';
|
this._websocket.binaryType = 'arraybuffer';
|
||||||
|
|
||||||
this._websocket.onmessage = this._recv_message.bind(this);
|
this._websocket.onmessage = this._recv_message.bind(this);
|
||||||
this._websocket.onopen = (function () {
|
this._websocket.onopen = () => {
|
||||||
Log.Debug('>> WebSock.onopen');
|
Log.Debug('>> WebSock.onopen');
|
||||||
if (this._websocket.protocol) {
|
if (this._websocket.protocol) {
|
||||||
Log.Info("Server choose sub-protocol: " + this._websocket.protocol);
|
Log.Info("Server choose sub-protocol: " + this._websocket.protocol);
|
||||||
|
|
@ -222,20 +214,20 @@ Websock.prototype = {
|
||||||
|
|
||||||
this._eventHandlers.open();
|
this._eventHandlers.open();
|
||||||
Log.Debug("<< WebSock.onopen");
|
Log.Debug("<< WebSock.onopen");
|
||||||
}).bind(this);
|
};
|
||||||
this._websocket.onclose = (function (e) {
|
this._websocket.onclose = (e) => {
|
||||||
Log.Debug(">> WebSock.onclose");
|
Log.Debug(">> WebSock.onclose");
|
||||||
this._eventHandlers.close(e);
|
this._eventHandlers.close(e);
|
||||||
Log.Debug("<< WebSock.onclose");
|
Log.Debug("<< WebSock.onclose");
|
||||||
}).bind(this);
|
};
|
||||||
this._websocket.onerror = (function (e) {
|
this._websocket.onerror = (e) => {
|
||||||
Log.Debug(">> WebSock.onerror: " + e);
|
Log.Debug(">> WebSock.onerror: " + e);
|
||||||
this._eventHandlers.error(e);
|
this._eventHandlers.error(e);
|
||||||
Log.Debug("<< WebSock.onerror: " + e);
|
Log.Debug("<< WebSock.onerror: " + e);
|
||||||
}).bind(this);
|
};
|
||||||
},
|
}
|
||||||
|
|
||||||
close: function () {
|
close() {
|
||||||
if (this._websocket) {
|
if (this._websocket) {
|
||||||
if ((this._websocket.readyState === WebSocket.OPEN) ||
|
if ((this._websocket.readyState === WebSocket.OPEN) ||
|
||||||
(this._websocket.readyState === WebSocket.CONNECTING)) {
|
(this._websocket.readyState === WebSocket.CONNECTING)) {
|
||||||
|
|
@ -243,19 +235,19 @@ Websock.prototype = {
|
||||||
this._websocket.close();
|
this._websocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._websocket.onmessage = function (e) { return; };
|
this._websocket.onmessage = () => {};
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
_encode_message: function () {
|
_encode_message() {
|
||||||
// Put in a binary arraybuffer
|
// Put in a binary arraybuffer
|
||||||
// according to the spec, you can send ArrayBufferViews with the send method
|
// according to the spec, you can send ArrayBufferViews with the send method
|
||||||
return new Uint8Array(this._sQ.buffer, 0, this._sQlen);
|
return new Uint8Array(this._sQ.buffer, 0, this._sQlen);
|
||||||
},
|
}
|
||||||
|
|
||||||
_expand_compact_rQ: function (min_fit) {
|
_expand_compact_rQ(min_fit) {
|
||||||
var resizeNeeded = min_fit || this._rQlen - this._rQi > this._rQbufferSize / 2;
|
const resizeNeeded = min_fit || this._rQlen - this._rQi > this._rQbufferSize / 2;
|
||||||
if (resizeNeeded) {
|
if (resizeNeeded) {
|
||||||
if (!min_fit) {
|
if (!min_fit) {
|
||||||
// just double the size if we need to do compaction
|
// just double the size if we need to do compaction
|
||||||
|
|
@ -270,12 +262,12 @@ Websock.prototype = {
|
||||||
if (this._rQbufferSize > MAX_RQ_GROW_SIZE) {
|
if (this._rQbufferSize > MAX_RQ_GROW_SIZE) {
|
||||||
this._rQbufferSize = MAX_RQ_GROW_SIZE;
|
this._rQbufferSize = MAX_RQ_GROW_SIZE;
|
||||||
if (this._rQbufferSize - this._rQlen - this._rQi < min_fit) {
|
if (this._rQbufferSize - this._rQlen - this._rQi < min_fit) {
|
||||||
throw new Exception("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit");
|
throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resizeNeeded) {
|
if (resizeNeeded) {
|
||||||
var old_rQbuffer = this._rQ.buffer;
|
const old_rQbuffer = this._rQ.buffer;
|
||||||
this._rQmax = this._rQbufferSize / 8;
|
this._rQmax = this._rQbufferSize / 8;
|
||||||
this._rQ = new Uint8Array(this._rQbufferSize);
|
this._rQ = new Uint8Array(this._rQbufferSize);
|
||||||
this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi));
|
this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi));
|
||||||
|
|
@ -289,31 +281,32 @@ Websock.prototype = {
|
||||||
|
|
||||||
this._rQlen = this._rQlen - this._rQi;
|
this._rQlen = this._rQlen - this._rQi;
|
||||||
this._rQi = 0;
|
this._rQi = 0;
|
||||||
},
|
}
|
||||||
|
|
||||||
_decode_message: function (data) {
|
_decode_message(data) {
|
||||||
// push arraybuffer values onto the end
|
// push arraybuffer values onto the end
|
||||||
var u8 = new Uint8Array(data);
|
const u8 = new Uint8Array(data);
|
||||||
if (u8.length > this._rQbufferSize - this._rQlen) {
|
if (u8.length > this._rQbufferSize - this._rQlen) {
|
||||||
this._expand_compact_rQ(u8.length);
|
this._expand_compact_rQ(u8.length);
|
||||||
}
|
}
|
||||||
this._rQ.set(u8, this._rQlen);
|
this._rQ.set(u8, this._rQlen);
|
||||||
this._rQlen += u8.length;
|
this._rQlen += u8.length;
|
||||||
},
|
}
|
||||||
|
|
||||||
_recv_message: function (e) {
|
_recv_message(e) {
|
||||||
this._decode_message(e.data);
|
this._decode_message(e.data);
|
||||||
if (this.rQlen() > 0) {
|
if (this.rQlen() <= 0) {
|
||||||
this._eventHandlers.message();
|
|
||||||
// Compact the receive queue
|
|
||||||
if (this._rQlen == this._rQi) {
|
|
||||||
this._rQlen = 0;
|
|
||||||
this._rQi = 0;
|
|
||||||
} else if (this._rQlen > this._rQmax) {
|
|
||||||
this._expand_compact_rQ();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.Debug("Ignoring empty message");
|
Log.Debug("Ignoring empty message");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._eventHandlers.message();
|
||||||
|
// Compact the receive queue
|
||||||
|
if (this._rQlen == this._rQi) {
|
||||||
|
this._rQlen = 0;
|
||||||
|
this._rQi = 0;
|
||||||
|
} else if (this._rQlen > this._rQmax) {
|
||||||
|
this._expand_compact_rQ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ connection to a specified VNC server.
|
||||||
|
|
||||||
##### Syntax
|
##### Syntax
|
||||||
|
|
||||||
var rfb = new RFB( target, url [, options] );
|
const rfb = new RFB( target, url [, options] );
|
||||||
|
|
||||||
###### Parameters
|
###### Parameters
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,29 +4,27 @@ module.exports = function(config) {
|
||||||
var customLaunchers = {};
|
var customLaunchers = {};
|
||||||
var browsers = [];
|
var browsers = [];
|
||||||
var useSauce = false;
|
var useSauce = false;
|
||||||
|
var transpile = false;
|
||||||
|
|
||||||
// use Sauce when running on Travis
|
// use Sauce when running on Travis
|
||||||
if (process.env.TRAVIS_JOB_NUMBER) {
|
if (process.env.TRAVIS_JOB_NUMBER) {
|
||||||
useSauce = true;
|
useSauce = true;
|
||||||
|
transpile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useSauce && process.env.TEST_BROWSER_NAME && process.env.TEST_BROWSER_NAME != 'PhantomJS') {
|
if (useSauce && process.env.TEST_BROWSER_NAME && process.env.TEST_BROWSER_NAME != 'PhantomJS') {
|
||||||
var names = process.env.TEST_BROWSER_NAME.split(',');
|
var names = process.env.TEST_BROWSER_NAME.split(',');
|
||||||
var platforms = process.env.TEST_BROWSER_OS.split(',');
|
var platforms = process.env.TEST_BROWSER_OS.split(',');
|
||||||
var versions = [];
|
var versions = process.env.TEST_BROWSER_VERSION
|
||||||
if (process.env.TEST_BROWSER_VERSION) {
|
? process.env.TEST_BROWSER_VERSION.split(',')
|
||||||
versions = process.env.TEST_BROWSER_VERSION.split(',');
|
: [null];
|
||||||
} else {
|
|
||||||
versions = [null];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < names.length; i++) {
|
for (var i = 0; i < names.length; i++) {
|
||||||
for (var j = 0; j < platforms.length; j++) {
|
for (var j = 0; j < platforms.length; j++) {
|
||||||
for (var k = 0; k < versions.length; k++) {
|
for (var k = 0; k < versions.length; k++) {
|
||||||
var launcher_name = 'sl_' + platforms[j].replace(/[^a-zA-Z0-9]/g, '') + '_' + names[i];
|
var launcher_name = versions[k]
|
||||||
if (versions[k]) {
|
? '_' + versions[k]
|
||||||
launcher_name += '_' + versions[k];
|
: 'sl_' + platforms[j].replace(/[^a-zA-Z0-9]/g, '') + '_' + names[i];
|
||||||
}
|
|
||||||
|
|
||||||
customLaunchers[launcher_name] = {
|
customLaunchers[launcher_name] = {
|
||||||
base: 'SauceLabs',
|
base: 'SauceLabs',
|
||||||
|
|
@ -101,6 +99,7 @@ module.exports = function(config) {
|
||||||
|
|
||||||
babelPreprocessor: {
|
babelPreprocessor: {
|
||||||
options: {
|
options: {
|
||||||
|
presets: transpile ? ['es2015'] : [],
|
||||||
plugins: ['transform-es2015-modules-amd', 'syntax-dynamic-import'],
|
plugins: ['transform-es2015-modules-amd', 'syntax-dynamic-import'],
|
||||||
sourceMap: 'inline',
|
sourceMap: 'inline',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -7,7 +7,8 @@
|
||||||
"test": "tests"
|
"test": "tests"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "PATH=$PATH:node_modules/karma/bin karma start karma.conf.js",
|
"lint": "eslint app core tests utils",
|
||||||
|
"test": "karma start karma.conf.js",
|
||||||
"prepare": "node ./utils/use_require.js --as commonjs --clean"
|
"prepare": "node ./utils/use_require.js --as commonjs --clean"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
@ -35,11 +36,13 @@
|
||||||
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
|
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
|
||||||
"babel-plugin-transform-es2015-modules-systemjs": "^6.22.0",
|
"babel-plugin-transform-es2015-modules-systemjs": "^6.22.0",
|
||||||
"babel-plugin-transform-es2015-modules-umd": "^6.22.0",
|
"babel-plugin-transform-es2015-modules-umd": "^6.22.0",
|
||||||
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"babelify": "^7.3.0",
|
"babelify": "^7.3.0",
|
||||||
"browserify": "^13.1.0",
|
"browserify": "^13.1.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"commander": "^2.9.0",
|
"commander": "^2.9.0",
|
||||||
"es-module-loader": "^2.1.0",
|
"es-module-loader": "^2.1.0",
|
||||||
|
"eslint": "^4.16.0",
|
||||||
"fs-extra": "^1.0.0",
|
"fs-extra": "^1.0.0",
|
||||||
"jsdom": "*",
|
"jsdom": "*",
|
||||||
"karma": "^1.3.0",
|
"karma": "^1.3.0",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"chai": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,23 +5,21 @@ chai.use(sinonChai);
|
||||||
// noVNC specific assertions
|
// noVNC specific assertions
|
||||||
chai.use(function (_chai, utils) {
|
chai.use(function (_chai, utils) {
|
||||||
_chai.Assertion.addMethod('displayed', function (target_data) {
|
_chai.Assertion.addMethod('displayed', function (target_data) {
|
||||||
var obj = this._obj;
|
const obj = this._obj;
|
||||||
var ctx = obj._target.getContext('2d');
|
const ctx = obj._target.getContext('2d');
|
||||||
var data_cl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
|
const data_cl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data;
|
||||||
// NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
|
// NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
|
||||||
var data = new Uint8Array(data_cl);
|
const data = new Uint8Array(data_cl);
|
||||||
var len = data_cl.length;
|
const len = data_cl.length;
|
||||||
new chai.Assertion(len).to.be.equal(target_data.length, "unexpected display size");
|
new chai.Assertion(len).to.be.equal(target_data.length, "unexpected display size");
|
||||||
var same = true;
|
let same = true;
|
||||||
for (var i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
if (data[i] != target_data[i]) {
|
if (data[i] != target_data[i]) {
|
||||||
same = false;
|
same = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!same) {
|
|
||||||
console.log("expected data: %o, actual data: %o", target_data, data);
|
|
||||||
}
|
|
||||||
this.assert(same,
|
this.assert(same,
|
||||||
"expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
|
"expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
|
||||||
"expected #{this} not to have displayed the image #{act}",
|
"expected #{this} not to have displayed the image #{act}",
|
||||||
|
|
@ -30,28 +28,26 @@ chai.use(function (_chai, utils) {
|
||||||
});
|
});
|
||||||
|
|
||||||
_chai.Assertion.addMethod('sent', function (target_data) {
|
_chai.Assertion.addMethod('sent', function (target_data) {
|
||||||
var obj = this._obj;
|
const obj = this._obj;
|
||||||
obj.inspect = function () {
|
obj.inspect = () => {
|
||||||
var res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
|
const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
|
||||||
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
|
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
|
||||||
res.prototype = obj;
|
res.prototype = obj;
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
var data = obj._websocket._get_sent_data();
|
const data = obj._websocket._get_sent_data();
|
||||||
var same = true;
|
let same = true;
|
||||||
if (data.length != target_data.length) {
|
if (data.length != target_data.length) {
|
||||||
same = false;
|
same = false;
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
if (data[i] != target_data[i]) {
|
if (data[i] != target_data[i]) {
|
||||||
same = false;
|
same = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!same) {
|
|
||||||
console.log("expected data: %o, actual data: %o", target_data, data);
|
|
||||||
}
|
|
||||||
this.assert(same,
|
this.assert(same,
|
||||||
"expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
|
"expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
|
||||||
"expected #{this} not to have sent the data #{act}",
|
"expected #{this} not to have sent the data #{act}",
|
||||||
|
|
@ -66,13 +62,11 @@ chai.use(function (_chai, utils) {
|
||||||
_chai.Assertion.overwriteMethod('equal', function (_super) {
|
_chai.Assertion.overwriteMethod('equal', function (_super) {
|
||||||
return function assertArrayEqual(target) {
|
return function assertArrayEqual(target) {
|
||||||
if (utils.flag(this, 'array')) {
|
if (utils.flag(this, 'array')) {
|
||||||
var obj = this._obj;
|
const obj = this._obj;
|
||||||
|
let same = true;
|
||||||
var i;
|
|
||||||
var same = true;
|
|
||||||
|
|
||||||
if (utils.flag(this, 'deep')) {
|
if (utils.flag(this, 'deep')) {
|
||||||
for (i = 0; i < obj.length; i++) {
|
for (let i = 0; i < obj.length; i++) {
|
||||||
if (!utils.eql(obj[i], target[i])) {
|
if (!utils.eql(obj[i], target[i])) {
|
||||||
same = false;
|
same = false;
|
||||||
break;
|
break;
|
||||||
|
|
@ -84,7 +78,7 @@ chai.use(function (_chai, utils) {
|
||||||
"expected #{this} not to have elements deeply equal to #{exp}",
|
"expected #{this} not to have elements deeply equal to #{exp}",
|
||||||
Array.prototype.slice.call(target));
|
Array.prototype.slice.call(target));
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < obj.length; i++) {
|
for (let i = 0; i < obj.length; i++) {
|
||||||
if (obj[i] != target[i]) {
|
if (obj[i] != target[i]) {
|
||||||
same = false;
|
same = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,45 @@
|
||||||
|
import Base64 from '../core/base64.js';
|
||||||
|
|
||||||
// PhantomJS can't create Event objects directly, so we need to use this
|
// PhantomJS can't create Event objects directly, so we need to use this
|
||||||
function make_event(name, props) {
|
function make_event(name, props) {
|
||||||
var evt = document.createEvent('Event');
|
const evt = document.createEvent('Event');
|
||||||
evt.initEvent(name, true, true);
|
evt.initEvent(name, true, true);
|
||||||
if (props) {
|
if (props) {
|
||||||
for (var prop in props) {
|
for (let prop in props) {
|
||||||
evt[prop] = props[prop];
|
evt[prop] = props[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FakeWebSocket (uri, protocols) {
|
export default class FakeWebSocket {
|
||||||
this.url = uri;
|
constructor(uri, protocols) {
|
||||||
this.binaryType = "arraybuffer";
|
this.url = uri;
|
||||||
this.extensions = "";
|
this.binaryType = "arraybuffer";
|
||||||
|
this.extensions = "";
|
||||||
|
|
||||||
if (!protocols || typeof protocols === 'string') {
|
if (!protocols || typeof protocols === 'string') {
|
||||||
this.protocol = protocols;
|
this.protocol = protocols;
|
||||||
} else {
|
} else {
|
||||||
this.protocol = protocols[0];
|
this.protocol = protocols[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
this._send_queue = new Uint8Array(20000);
|
||||||
|
|
||||||
|
this.readyState = FakeWebSocket.CONNECTING;
|
||||||
|
this.bufferedAmount = 0;
|
||||||
|
|
||||||
|
this.__is_fake = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._send_queue = new Uint8Array(20000);
|
close(code, reason) {
|
||||||
|
|
||||||
this.readyState = FakeWebSocket.CONNECTING;
|
|
||||||
this.bufferedAmount = 0;
|
|
||||||
|
|
||||||
this.__is_fake = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
FakeWebSocket.prototype = {
|
|
||||||
close: function (code, reason) {
|
|
||||||
this.readyState = FakeWebSocket.CLOSED;
|
this.readyState = FakeWebSocket.CLOSED;
|
||||||
if (this.onclose) {
|
if (this.onclose) {
|
||||||
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
|
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
send: function (data) {
|
send(data) {
|
||||||
if (this.protocol == 'base64') {
|
if (this.protocol == 'base64') {
|
||||||
data = Base64.decode(data);
|
data = Base64.decode(data);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -45,25 +47,25 @@ FakeWebSocket.prototype = {
|
||||||
}
|
}
|
||||||
this._send_queue.set(data, this.bufferedAmount);
|
this._send_queue.set(data, this.bufferedAmount);
|
||||||
this.bufferedAmount += data.length;
|
this.bufferedAmount += data.length;
|
||||||
},
|
}
|
||||||
|
|
||||||
_get_sent_data: function () {
|
_get_sent_data() {
|
||||||
var res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
const res = new Uint8Array(this._send_queue.buffer, 0, this.bufferedAmount);
|
||||||
this.bufferedAmount = 0;
|
this.bufferedAmount = 0;
|
||||||
return res;
|
return res;
|
||||||
},
|
}
|
||||||
|
|
||||||
_open: function (data) {
|
_open() {
|
||||||
this.readyState = FakeWebSocket.OPEN;
|
this.readyState = FakeWebSocket.OPEN;
|
||||||
if (this.onopen) {
|
if (this.onopen) {
|
||||||
this.onopen(make_event('open'));
|
this.onopen(make_event('open'));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_receive_data: function (data) {
|
_receive_data(data) {
|
||||||
this.onmessage(make_event("message", { 'data': data }));
|
this.onmessage(make_event("message", { 'data': data }));
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
FakeWebSocket.OPEN = WebSocket.OPEN;
|
FakeWebSocket.OPEN = WebSocket.OPEN;
|
||||||
FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
|
FakeWebSocket.CONNECTING = WebSocket.CONNECTING;
|
||||||
|
|
@ -72,16 +74,18 @@ FakeWebSocket.CLOSED = WebSocket.CLOSED;
|
||||||
|
|
||||||
FakeWebSocket.__is_fake = true;
|
FakeWebSocket.__is_fake = true;
|
||||||
|
|
||||||
FakeWebSocket.replace = function () {
|
FakeWebSocket.replace = () => {
|
||||||
if (!WebSocket.__is_fake) {
|
if (!WebSocket.__is_fake) {
|
||||||
var real_version = WebSocket;
|
const real_version = WebSocket;
|
||||||
|
// eslint-disable-next-line no-global-assign
|
||||||
WebSocket = FakeWebSocket;
|
WebSocket = FakeWebSocket;
|
||||||
FakeWebSocket.__real_version = real_version;
|
FakeWebSocket.__real_version = real_version;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWebSocket.restore = function () {
|
FakeWebSocket.restore = () => {
|
||||||
if (WebSocket.__is_fake) {
|
if (WebSocket.__is_fake) {
|
||||||
|
// eslint-disable-next-line no-global-assign
|
||||||
WebSocket = WebSocket.__real_version;
|
WebSocket = WebSocket.__real_version;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,19 @@
|
||||||
|
/* global VNC_frame_data, VNC_frame_encoding */
|
||||||
|
|
||||||
import * as WebUtil from '../app/webutil.js';
|
import * as WebUtil from '../app/webutil.js';
|
||||||
import RecordingPlayer from './playback.js';
|
import RecordingPlayer from './playback.js';
|
||||||
|
|
||||||
var frames = null;
|
let frames = null;
|
||||||
var encoding = null;
|
let encoding = null;
|
||||||
|
|
||||||
function message(str) {
|
function message(str) {
|
||||||
console.log(str);
|
const cell = document.getElementById('messages');
|
||||||
var cell = document.getElementById('messages');
|
|
||||||
cell.textContent += str + "\n";
|
cell.textContent += str + "\n";
|
||||||
cell.scrollTop = cell.scrollHeight;
|
cell.scrollTop = cell.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFile() {
|
function loadFile() {
|
||||||
const fname = WebUtil.getQueryVar('data', null);
|
const fname = WebUtil.getQueryconst('data', null);
|
||||||
|
|
||||||
if (!fname) {
|
if (!fname) {
|
||||||
return Promise.reject("Must specify data=FOO in query string.");
|
return Promise.reject("Must specify data=FOO in query string.");
|
||||||
|
|
@ -21,7 +22,7 @@ function loadFile() {
|
||||||
message("Loading " + fname);
|
message("Loading " + fname);
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
script.onload = resolve;
|
script.onload = resolve;
|
||||||
script.onerror = reject;
|
script.onerror = reject;
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
|
|
@ -30,10 +31,10 @@ function loadFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableUI() {
|
function enableUI() {
|
||||||
var iterations = WebUtil.getQueryVar('iterations', 3);
|
const iterations = WebUtil.getQueryconst('iterations', 3);
|
||||||
document.getElementById('iterations').value = iterations;
|
document.getElementById('iterations').value = iterations;
|
||||||
|
|
||||||
var mode = WebUtil.getQueryVar('mode', 3);
|
const mode = WebUtil.getQueryconst('mode', 3);
|
||||||
if (mode === 'realtime') {
|
if (mode === 'realtime') {
|
||||||
document.getElementById('mode2').checked = true;
|
document.getElementById('mode2').checked = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -120,7 +121,7 @@ IterationPlayer.prototype = {
|
||||||
this._state = 'failed';
|
this._state = 'failed';
|
||||||
}
|
}
|
||||||
|
|
||||||
var evt = new Event('rfbdisconnected');
|
const evt = new Event('rfbdisconnected');
|
||||||
evt.clean = clean;
|
evt.clean = clean;
|
||||||
evt.frame = frame;
|
evt.frame = frame;
|
||||||
evt.iteration = this._iteration;
|
evt.iteration = this._iteration;
|
||||||
|
|
@ -135,7 +136,7 @@ function start() {
|
||||||
|
|
||||||
const iterations = document.getElementById('iterations').value;
|
const iterations = document.getElementById('iterations').value;
|
||||||
|
|
||||||
var mode;
|
let mode;
|
||||||
|
|
||||||
if (document.getElementById('mode1').checked) {
|
if (document.getElementById('mode1').checked) {
|
||||||
message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
|
message(`Starting performance playback (fullspeed) [${iterations} iteration(s)]`);
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,12 @@ import Base64 from '../core/base64.js';
|
||||||
|
|
||||||
// Immediate polyfill
|
// Immediate polyfill
|
||||||
if (setImmediate === undefined) {
|
if (setImmediate === undefined) {
|
||||||
var _immediateIdCounter = 1;
|
let _immediateIdCounter = 1;
|
||||||
var _immediateFuncs = {};
|
const _immediateFuncs = {};
|
||||||
|
|
||||||
var setImmediate = function (func) {
|
// eslint-disable-next-line no-unused-vars
|
||||||
var index = _immediateIdCounter++;
|
const setImmediate = function (func) {
|
||||||
|
const index = _immediateIdCounter++;
|
||||||
_immediateFuncs[index] = func;
|
_immediateFuncs[index] = func;
|
||||||
window.postMessage("noVNC immediate trigger:" + index, "*");
|
window.postMessage("noVNC immediate trigger:" + index, "*");
|
||||||
return index;
|
return index;
|
||||||
|
|
@ -24,15 +25,15 @@ if (setImmediate === undefined) {
|
||||||
_immediateFuncs[id];
|
_immediateFuncs[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
var _onMessage = function (event) {
|
const _onMessage = function (event) {
|
||||||
if ((typeof event.data !== "string") ||
|
if ((typeof event.data !== "string") ||
|
||||||
(event.data.indexOf("noVNC immediate trigger:") !== 0)) {
|
(event.data.indexOf("noVNC immediate trigger:") !== 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var index = event.data.slice("noVNC immediate trigger:".length);
|
const index = event.data.slice("noVNC immediate trigger:".length);
|
||||||
|
|
||||||
var callback = _immediateFuncs[index];
|
const callback = _immediateFuncs[index];
|
||||||
if (callback === undefined) {
|
if (callback === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -70,11 +71,11 @@ export default function RecordingPlayer (frames, encoding, disconnected) {
|
||||||
|
|
||||||
this._running = false;
|
this._running = false;
|
||||||
|
|
||||||
this.onfinish = function () {};
|
this.onfinish = () => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordingPlayer.prototype = {
|
RecordingPlayer.prototype = {
|
||||||
run: function (realtime, trafficManagement) {
|
run(realtime, trafficManagement) {
|
||||||
// initialize a new RFB
|
// initialize a new RFB
|
||||||
this._rfb = new RFB(document.getElementById('VNC_screen'), 'wss://test');
|
this._rfb = new RFB(document.getElementById('VNC_screen'), 'wss://test');
|
||||||
this._rfb.viewOnly = true;
|
this._rfb.viewOnly = true;
|
||||||
|
|
@ -95,20 +96,20 @@ RecordingPlayer.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// _enablePlaybackMode mocks out things not required for running playback
|
// _enablePlaybackMode mocks out things not required for running playback
|
||||||
_enablePlaybackMode: function () {
|
_enablePlaybackMode() {
|
||||||
this._rfb._sock.send = function (arr) {};
|
this._rfb._sock.send = () => {};
|
||||||
this._rfb._sock.close = function () {};
|
this._rfb._sock.close = () => {};
|
||||||
this._rfb._sock.flush = function () {};
|
this._rfb._sock.flush = () => {};
|
||||||
this._rfb._sock.open = function () {
|
this._rfb._sock.open = () => {
|
||||||
this.init();
|
this.init();
|
||||||
this._eventHandlers.open();
|
this._eventHandlers.open();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
_queueNextPacket: function () {
|
_queueNextPacket() {
|
||||||
if (!this._running) { return; }
|
if (!this._running) { return; }
|
||||||
|
|
||||||
var frame = this._frames[this._frame_index];
|
let frame = this._frames[this._frame_index];
|
||||||
|
|
||||||
// skip send frames
|
// skip send frames
|
||||||
while (this._frame_index < this._frame_length && frame.charAt(0) === "}") {
|
while (this._frame_index < this._frame_length && frame.charAt(0) === "}") {
|
||||||
|
|
@ -140,7 +141,7 @@ RecordingPlayer.prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_doPacket: function () {
|
_doPacket() {
|
||||||
// Avoid having excessive queue buildup in non-realtime mode
|
// Avoid having excessive queue buildup in non-realtime mode
|
||||||
if (this._trafficManagement && this._rfb._flushing) {
|
if (this._trafficManagement && this._rfb._flushing) {
|
||||||
let player = this;
|
let player = this;
|
||||||
|
|
@ -154,12 +155,13 @@ RecordingPlayer.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const frame = this._frames[this._frame_index];
|
const frame = this._frames[this._frame_index];
|
||||||
var start = frame.indexOf('{', 1) + 1;
|
let start = frame.indexOf('{', 1) + 1;
|
||||||
|
let u8;
|
||||||
if (this._encoding === 'base64') {
|
if (this._encoding === 'base64') {
|
||||||
var u8 = Base64.decode(frame.slice(start));
|
u8 = Base64.decode(frame.slice(start));
|
||||||
start = 0;
|
start = 0;
|
||||||
} else {
|
} else {
|
||||||
var u8 = new Uint8Array(frame.length - start);
|
u8 = new Uint8Array(frame.length - start);
|
||||||
for (let i = 0; i < frame.length - start; i++) {
|
for (let i = 0; i < frame.length - start; i++) {
|
||||||
u8[i] = frame.charCodeAt(start + i);
|
u8[i] = frame.charCodeAt(start + i);
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +175,7 @@ RecordingPlayer.prototype = {
|
||||||
|
|
||||||
_finish() {
|
_finish() {
|
||||||
if (this._rfb._display.pending()) {
|
if (this._rfb._display.pending()) {
|
||||||
var player = this;
|
const player = this;
|
||||||
this._rfb._display.onflush = function () {
|
this._rfb._display.onflush = function () {
|
||||||
if (player._rfb._flushing) {
|
if (player._rfb._flushing) {
|
||||||
player._rfb._onFlush();
|
player._rfb._onFlush();
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
var assert = chai.assert;
|
const expect = chai.expect;
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import Base64 from '../core/base64.js';
|
import Base64 from '../core/base64.js';
|
||||||
|
|
||||||
describe('Base64 Tools', function() {
|
describe('Base64 Tools', function() {
|
||||||
"use strict";
|
const BIN_ARR = new Array(256);
|
||||||
|
for (let i = 0; i < 256; i++) {
|
||||||
var BIN_ARR = new Array(256);
|
|
||||||
for (var i = 0; i < 256; i++) {
|
|
||||||
BIN_ARR[i] = i;
|
BIN_ARR[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
var B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
|
const B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
|
||||||
|
|
||||||
|
|
||||||
describe('encode', function() {
|
describe('encode', function() {
|
||||||
it('should encode a binary string into Base64', function() {
|
it('should encode a binary string into Base64', function() {
|
||||||
var encoded = Base64.encode(BIN_ARR);
|
const encoded = Base64.encode(BIN_ARR);
|
||||||
expect(encoded).to.equal(B64_STR);
|
expect(encoded).to.equal(B64_STR);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('decode', function() {
|
describe('decode', function() {
|
||||||
it('should decode a Base64 string into a normal string', function() {
|
it('should decode a Base64 string into a normal string', function() {
|
||||||
var decoded = Base64.decode(B64_STR);
|
const decoded = Base64.decode(B64_STR);
|
||||||
expect(decoded).to.deep.equal(BIN_ARR);
|
expect(decoded).to.deep.equal(BIN_ARR);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
/* jshint expr: true */
|
const expect = chai.expect;
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import Base64 from '../core/base64.js';
|
import Base64 from '../core/base64.js';
|
||||||
import Display from '../core/display.js';
|
import Display from '../core/display.js';
|
||||||
|
|
@ -7,37 +6,35 @@ import Display from '../core/display.js';
|
||||||
import sinon from '../vendor/sinon.js';
|
import sinon from '../vendor/sinon.js';
|
||||||
|
|
||||||
describe('Display/Canvas Helper', function () {
|
describe('Display/Canvas Helper', function () {
|
||||||
var checked_data = [
|
const checked_data = new Uint8Array([
|
||||||
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
|
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
|
||||||
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
|
0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255, 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255,
|
||||||
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
|
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255,
|
||||||
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
|
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
|
||||||
];
|
]);
|
||||||
checked_data = new Uint8Array(checked_data);
|
|
||||||
|
|
||||||
var basic_data = [0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255];
|
const basic_data = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]);
|
||||||
basic_data = new Uint8Array(basic_data);
|
|
||||||
|
|
||||||
function make_image_canvas (input_data) {
|
function make_image_canvas (input_data) {
|
||||||
var canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = 4;
|
canvas.width = 4;
|
||||||
canvas.height = 4;
|
canvas.height = 4;
|
||||||
var ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
var data = ctx.createImageData(4, 4);
|
const data = ctx.createImageData(4, 4);
|
||||||
for (var i = 0; i < checked_data.length; i++) { data.data[i] = input_data[i]; }
|
for (let i = 0; i < checked_data.length; i++) { data.data[i] = input_data[i]; }
|
||||||
ctx.putImageData(data, 0, 0);
|
ctx.putImageData(data, 0, 0);
|
||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_image_png (input_data) {
|
function make_image_png (input_data) {
|
||||||
var canvas = make_image_canvas(input_data);
|
const canvas = make_image_canvas(input_data);
|
||||||
var url = canvas.toDataURL();
|
const url = canvas.toDataURL();
|
||||||
var data = url.split(",")[1];
|
const data = url.split(",")[1];
|
||||||
return Base64.decode(data);
|
return Base64.decode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('viewport handling', function () {
|
describe('viewport handling', function () {
|
||||||
var display;
|
let display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'));
|
display = new Display(document.createElement('canvas'));
|
||||||
display.clipViewport = true;
|
display.clipViewport = true;
|
||||||
|
|
@ -52,10 +49,9 @@ describe('Display/Canvas Helper', function () {
|
||||||
display.drawImage(make_image_canvas(basic_data), 1, 1);
|
display.drawImage(make_image_canvas(basic_data), 1, 1);
|
||||||
display.flip();
|
display.flip();
|
||||||
|
|
||||||
var expected = new Uint8Array(16);
|
const expected = new Uint8Array(16);
|
||||||
var i;
|
for (let i = 0; i < 8; i++) { expected[i] = basic_data[i]; }
|
||||||
for (i = 0; i < 8; i++) { expected[i] = basic_data[i]; }
|
for (let i = 8; i < 16; i++) { expected[i] = 0; }
|
||||||
for (i = 8; i < 16; i++) { expected[i] = 0; }
|
|
||||||
expect(display).to.have.displayed(expected);
|
expect(display).to.have.displayed(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -120,7 +116,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('resizing', function () {
|
describe('resizing', function () {
|
||||||
var display;
|
let display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'));
|
display = new Display(document.createElement('canvas'));
|
||||||
display.clipViewport = false;
|
display.clipViewport = false;
|
||||||
|
|
@ -137,8 +133,8 @@ describe('Display/Canvas Helper', function () {
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
||||||
display.resize(2, 2);
|
display.resize(2, 2);
|
||||||
display.flip();
|
display.flip();
|
||||||
var expected = [];
|
const expected = [];
|
||||||
for (var i = 0; i < 4 * 2*2; i += 4) {
|
for (let i = 0; i < 4 * 2*2; i += 4) {
|
||||||
expected[i] = 0xff;
|
expected[i] = 0xff;
|
||||||
expected[i+1] = expected[i+2] = 0;
|
expected[i+1] = expected[i+2] = 0;
|
||||||
expected[i+3] = 0xff;
|
expected[i+3] = 0xff;
|
||||||
|
|
@ -180,8 +176,8 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('rescaling', function () {
|
describe('rescaling', function () {
|
||||||
var display;
|
let display;
|
||||||
var canvas;
|
let canvas;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
canvas = document.createElement('canvas');
|
canvas = document.createElement('canvas');
|
||||||
|
|
@ -221,8 +217,8 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('autoscaling', function () {
|
describe('autoscaling', function () {
|
||||||
var display;
|
let display;
|
||||||
var canvas;
|
let canvas;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
canvas = document.createElement('canvas');
|
canvas = document.createElement('canvas');
|
||||||
|
|
@ -269,7 +265,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
|
|
||||||
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the
|
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the
|
||||||
// basic cases
|
// basic cases
|
||||||
var display;
|
let display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'));
|
display = new Display(document.createElement('canvas'));
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
|
|
@ -280,15 +276,15 @@ describe('Display/Canvas Helper', function () {
|
||||||
display._logo = null;
|
display._logo = null;
|
||||||
display.clear();
|
display.clear();
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
var empty = [];
|
const empty = [];
|
||||||
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; }
|
for (let i = 0; i < 4 * display._fb_width * display._fb_height; i++) { empty[i] = 0; }
|
||||||
expect(display).to.have.displayed(new Uint8Array(empty));
|
expect(display).to.have.displayed(new Uint8Array(empty));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should draw the logo on #clear with a logo set', function (done) {
|
it('should draw the logo on #clear with a logo set', function (done) {
|
||||||
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
|
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
|
||||||
display.clear();
|
display.clear();
|
||||||
display.onflush = function () {
|
display.onflush = () => {
|
||||||
expect(display).to.have.displayed(checked_data);
|
expect(display).to.have.displayed(checked_data);
|
||||||
expect(display._fb_width).to.equal(4);
|
expect(display._fb_width).to.equal(4);
|
||||||
expect(display._fb_height).to.equal(4);
|
expect(display._fb_height).to.equal(4);
|
||||||
|
|
@ -301,8 +297,8 @@ describe('Display/Canvas Helper', function () {
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
display.fillRect(0, 0, 4, 4, [0, 0, 0xff]);
|
||||||
display.flip();
|
display.flip();
|
||||||
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
display.fillRect(0, 0, 4, 4, [0, 0xff, 0]);
|
||||||
var expected = [];
|
const expected = [];
|
||||||
for (var i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
for (let i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
|
||||||
expected[i] = 0xff;
|
expected[i] = 0xff;
|
||||||
expected[i+1] = expected[i+2] = 0;
|
expected[i+1] = expected[i+2] = 0;
|
||||||
expected[i+3] = 0xff;
|
expected[i+3] = 0xff;
|
||||||
|
|
@ -329,7 +325,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
it('should support drawing images via #imageRect', function (done) {
|
it('should support drawing images via #imageRect', function (done) {
|
||||||
display.imageRect(0, 0, "image/png", make_image_png(checked_data));
|
display.imageRect(0, 0, "image/png", make_image_png(checked_data));
|
||||||
display.flip();
|
display.flip();
|
||||||
display.onflush = function () {
|
display.onflush = () => {
|
||||||
expect(display).to.have.displayed(checked_data);
|
expect(display).to.have.displayed(checked_data);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
@ -372,8 +368,8 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support drawing BGRX blit images with true color via #blitImage', function () {
|
it('should support drawing BGRX blit images with true color via #blitImage', function () {
|
||||||
var data = [];
|
const data = [];
|
||||||
for (var i = 0; i < 16; i++) {
|
for (let i = 0; i < 16; i++) {
|
||||||
data[i * 4] = checked_data[i * 4 + 2];
|
data[i * 4] = checked_data[i * 4 + 2];
|
||||||
data[i * 4 + 1] = checked_data[i * 4 + 1];
|
data[i * 4 + 1] = checked_data[i * 4 + 1];
|
||||||
data[i * 4 + 2] = checked_data[i * 4];
|
data[i * 4 + 2] = checked_data[i * 4];
|
||||||
|
|
@ -385,8 +381,8 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support drawing RGB blit images with true color via #blitRgbImage', function () {
|
it('should support drawing RGB blit images with true color via #blitRgbImage', function () {
|
||||||
var data = [];
|
const data = [];
|
||||||
for (var i = 0; i < 16; i++) {
|
for (let i = 0; i < 16; i++) {
|
||||||
data[i * 3] = checked_data[i * 4];
|
data[i * 3] = checked_data[i * 4];
|
||||||
data[i * 3 + 1] = checked_data[i * 4 + 1];
|
data[i * 3 + 1] = checked_data[i * 4 + 1];
|
||||||
data[i * 3 + 2] = checked_data[i * 4 + 2];
|
data[i * 3 + 2] = checked_data[i * 4 + 2];
|
||||||
|
|
@ -397,7 +393,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support drawing an image object via #drawImage', function () {
|
it('should support drawing an image object via #drawImage', function () {
|
||||||
var img = make_image_canvas(checked_data);
|
const img = make_image_canvas(checked_data);
|
||||||
display.drawImage(img, 0, 0);
|
display.drawImage(img, 0, 0);
|
||||||
display.flip();
|
display.flip();
|
||||||
expect(display).to.have.displayed(checked_data);
|
expect(display).to.have.displayed(checked_data);
|
||||||
|
|
@ -405,7 +401,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('the render queue processor', function () {
|
describe('the render queue processor', function () {
|
||||||
var display;
|
let display;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
display = new Display(document.createElement('canvas'));
|
display = new Display(document.createElement('canvas'));
|
||||||
display.resize(4, 4);
|
display.resize(4, 4);
|
||||||
|
|
@ -428,7 +424,7 @@ describe('Display/Canvas Helper', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () {
|
it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () {
|
||||||
var img = { complete: false, addEventListener: sinon.spy() }
|
const img = { complete: false, addEventListener: sinon.spy() }
|
||||||
display._renderQ = [{ type: 'img', x: 3, y: 4, img: img },
|
display._renderQ = [{ type: 'img', x: 3, y: 4, img: img },
|
||||||
{ type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5 }];
|
{ type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5 }];
|
||||||
display.drawImage = sinon.spy();
|
display.drawImage = sinon.spy();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
var assert = chai.assert;
|
const expect = chai.expect;
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import keysyms from '../core/input/keysymdef.js';
|
import keysyms from '../core/input/keysymdef.js';
|
||||||
import * as KeyboardUtil from "../core/input/util.js";
|
import * as KeyboardUtil from "../core/input/util.js";
|
||||||
|
|
@ -12,8 +11,6 @@ function isEdge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Helpers', function() {
|
describe('Helpers', function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
describe('keysyms.lookup', function() {
|
describe('keysyms.lookup', function() {
|
||||||
it('should map ASCII characters to keysyms', function() {
|
it('should map ASCII characters to keysyms', function() {
|
||||||
expect(keysyms.lookup('a'.charCodeAt())).to.be.equal(0x61);
|
expect(keysyms.lookup('a'.charCodeAt())).to.be.equal(0x61);
|
||||||
|
|
@ -71,7 +68,7 @@ describe('Helpers', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Fix Meta on macOS', function() {
|
describe('Fix Meta on macOS', function() {
|
||||||
var origNavigator;
|
let origNavigator;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// window.navigator is a protected read-only property in many
|
// window.navigator is a protected read-only property in many
|
||||||
// environments, so we need to redefine it whilst running these
|
// environments, so we need to redefine it whilst running these
|
||||||
|
|
@ -134,7 +131,7 @@ describe('Helpers', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Broken key AltGraph on IE/Edge', function() {
|
describe('Broken key AltGraph on IE/Edge', function() {
|
||||||
var origNavigator;
|
let origNavigator;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// window.navigator is a protected read-only property in many
|
// window.navigator is a protected read-only property in many
|
||||||
// environments, so we need to redefine it whilst running these
|
// environments, so we need to redefine it whilst running these
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
var assert = chai.assert;
|
const expect = chai.expect;
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import sinon from '../vendor/sinon.js';
|
import sinon from '../vendor/sinon.js';
|
||||||
|
|
||||||
|
|
@ -12,27 +11,24 @@ function isEdge() {
|
||||||
return navigator && !!(/edge/i).exec(navigator.userAgent);
|
return navigator && !!(/edge/i).exec(navigator.userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* jshint newcap: false, expr: true */
|
|
||||||
describe('Key Event Handling', function() {
|
describe('Key Event Handling', function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// The real KeyboardEvent constructor might not work everywhere we
|
// The real KeyboardEvent constructor might not work everywhere we
|
||||||
// want to run these tests
|
// want to run these tests
|
||||||
function keyevent(typeArg, KeyboardEventInit) {
|
function keyevent(typeArg, KeyboardEventInit) {
|
||||||
var e = { type: typeArg };
|
const e = { type: typeArg };
|
||||||
for (var key in KeyboardEventInit) {
|
for (let key in KeyboardEventInit) {
|
||||||
e[key] = KeyboardEventInit[key];
|
e[key] = KeyboardEventInit[key];
|
||||||
}
|
}
|
||||||
e.stopPropagation = sinon.spy();
|
e.stopPropagation = sinon.spy();
|
||||||
e.preventDefault = sinon.spy();
|
e.preventDefault = sinon.spy();
|
||||||
return e;
|
return e;
|
||||||
};
|
}
|
||||||
|
|
||||||
describe('Decode Keyboard Events', function() {
|
describe('Decode Keyboard Events', function() {
|
||||||
it('should decode keydown events', function(done) {
|
it('should decode keydown events', function(done) {
|
||||||
if (isIE() || isEdge()) this.skip();
|
if (isIE() || isEdge()) this.skip();
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -42,9 +38,9 @@ describe('Key Event Handling', function() {
|
||||||
});
|
});
|
||||||
it('should decode keyup events', function(done) {
|
it('should decode keyup events', function(done) {
|
||||||
if (isIE() || isEdge()) this.skip();
|
if (isIE() || isEdge()) this.skip();
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
if (calls++ === 1) {
|
if (calls++ === 1) {
|
||||||
|
|
@ -58,14 +54,14 @@ describe('Key Event Handling', function() {
|
||||||
|
|
||||||
describe('Legacy keypress Events', function() {
|
describe('Legacy keypress Events', function() {
|
||||||
it('should wait for keypress when needed', function() {
|
it('should wait for keypress when needed', function() {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = sinon.spy();
|
kbd.onkeyevent = sinon.spy();
|
||||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
it('should decode keypress events', function(done) {
|
it('should decode keypress events', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -75,15 +71,15 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyA', charCode: 0x61}));
|
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyA', charCode: 0x61}));
|
||||||
});
|
});
|
||||||
it('should ignore keypress with different code', function() {
|
it('should ignore keypress with different code', function() {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = sinon.spy();
|
kbd.onkeyevent = sinon.spy();
|
||||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
|
||||||
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyB', charCode: 0x61}));
|
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyB', charCode: 0x61}));
|
||||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
it('should handle keypress with missing code', function(done) {
|
it('should handle keypress with missing code', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -93,8 +89,8 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyPress(keyevent('keypress', {charCode: 0x61}));
|
kbd._handleKeyPress(keyevent('keypress', {charCode: 0x61}));
|
||||||
});
|
});
|
||||||
it('should guess key if no keypress and numeric key', function(done) {
|
it('should guess key if no keypress and numeric key', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x32);
|
expect(keysym).to.be.equal(0x32);
|
||||||
expect(code).to.be.equal('Digit2');
|
expect(code).to.be.equal('Digit2');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -103,8 +99,8 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyDown(keyevent('keydown', {code: 'Digit2', keyCode: 0x32}));
|
kbd._handleKeyDown(keyevent('keydown', {code: 'Digit2', keyCode: 0x32}));
|
||||||
});
|
});
|
||||||
it('should guess key if no keypress and alpha key', function(done) {
|
it('should guess key if no keypress and alpha key', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -113,8 +109,8 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: false}));
|
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: false}));
|
||||||
});
|
});
|
||||||
it('should guess key if no keypress and alpha key (with shift)', function(done) {
|
it('should guess key if no keypress and alpha key (with shift)', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x41);
|
expect(keysym).to.be.equal(0x41);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -123,8 +119,8 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: true}));
|
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: true}));
|
||||||
});
|
});
|
||||||
it('should not guess key if no keypress and unknown key', function(done) {
|
it('should not guess key if no keypress and unknown key', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0);
|
expect(keysym).to.be.equal(0);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -139,27 +135,27 @@ describe('Key Event Handling', function() {
|
||||||
if (isIE() || isEdge()) this.skip();
|
if (isIE() || isEdge()) this.skip();
|
||||||
});
|
});
|
||||||
it('should suppress anything with a valid key', function() {
|
it('should suppress anything with a valid key', function() {
|
||||||
var kbd = new Keyboard(document, {});
|
const kbd = new Keyboard(document, {});
|
||||||
var evt = keyevent('keydown', {code: 'KeyA', key: 'a'});
|
const evt1 = keyevent('keydown', {code: 'KeyA', key: 'a'});
|
||||||
kbd._handleKeyDown(evt);
|
kbd._handleKeyDown(evt1);
|
||||||
expect(evt.preventDefault).to.have.been.called;
|
expect(evt1.preventDefault).to.have.been.called;
|
||||||
evt = keyevent('keyup', {code: 'KeyA', key: 'a'});
|
const evt2 = keyevent('keyup', {code: 'KeyA', key: 'a'});
|
||||||
kbd._handleKeyUp(evt);
|
kbd._handleKeyUp(evt2);
|
||||||
expect(evt.preventDefault).to.have.been.called;
|
expect(evt2.preventDefault).to.have.been.called;
|
||||||
});
|
});
|
||||||
it('should not suppress keys without key', function() {
|
it('should not suppress keys without key', function() {
|
||||||
var kbd = new Keyboard(document, {});
|
const kbd = new Keyboard(document, {});
|
||||||
var evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
const evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
||||||
kbd._handleKeyDown(evt);
|
kbd._handleKeyDown(evt);
|
||||||
expect(evt.preventDefault).to.not.have.been.called;
|
expect(evt.preventDefault).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
it('should suppress the following keypress event', function() {
|
it('should suppress the following keypress event', function() {
|
||||||
var kbd = new Keyboard(document, {});
|
const kbd = new Keyboard(document, {});
|
||||||
var evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
const evt1 = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
|
||||||
kbd._handleKeyDown(evt);
|
kbd._handleKeyDown(evt1);
|
||||||
var evt = keyevent('keypress', {code: 'KeyA', charCode: 0x41});
|
const evt2 = keyevent('keypress', {code: 'KeyA', charCode: 0x41});
|
||||||
kbd._handleKeyPress(evt);
|
kbd._handleKeyPress(evt2);
|
||||||
expect(evt.preventDefault).to.have.been.called;
|
expect(evt2.preventDefault).to.have.been.called;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -167,9 +163,9 @@ describe('Key Event Handling', function() {
|
||||||
describe('Fake keyup', function() {
|
describe('Fake keyup', function() {
|
||||||
it('should fake keyup events for virtual keyboards', function(done) {
|
it('should fake keyup events for virtual keyboards', function(done) {
|
||||||
if (isIE() || isEdge()) this.skip();
|
if (isIE() || isEdge()) this.skip();
|
||||||
var count = 0;
|
let count = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
switch (count++) {
|
switch (count++) {
|
||||||
case 0:
|
case 0:
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
|
|
@ -187,7 +183,7 @@ describe('Key Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('iOS', function() {
|
describe('iOS', function() {
|
||||||
var origNavigator;
|
let origNavigator;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// window.navigator is a protected read-only property in many
|
// window.navigator is a protected read-only property in many
|
||||||
// environments, so we need to redefine it whilst running these
|
// environments, so we need to redefine it whilst running these
|
||||||
|
|
@ -214,9 +210,9 @@ describe('Key Event Handling', function() {
|
||||||
|
|
||||||
it('should fake keyup events on iOS', function(done) {
|
it('should fake keyup events on iOS', function(done) {
|
||||||
if (isIE() || isEdge()) this.skip();
|
if (isIE() || isEdge()) this.skip();
|
||||||
var count = 0;
|
let count = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
switch (count++) {
|
switch (count++) {
|
||||||
case 0:
|
case 0:
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
|
|
@ -240,8 +236,8 @@ describe('Key Event Handling', function() {
|
||||||
if (isIE() || isEdge()) this.skip();
|
if (isIE() || isEdge()) this.skip();
|
||||||
});
|
});
|
||||||
it('should send release using the same keysym as the press', function(done) {
|
it('should send release using the same keysym as the press', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
if (!down) {
|
if (!down) {
|
||||||
|
|
@ -252,9 +248,9 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'b'}));
|
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'b'}));
|
||||||
});
|
});
|
||||||
it('should send the same keysym for multiple presses', function() {
|
it('should send the same keysym for multiple presses', function() {
|
||||||
var count = 0;
|
let count = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('KeyA');
|
expect(code).to.be.equal('KeyA');
|
||||||
expect(down).to.be.equal(true);
|
expect(down).to.be.equal(true);
|
||||||
|
|
@ -265,7 +261,7 @@ describe('Key Event Handling', function() {
|
||||||
expect(count).to.be.equal(2);
|
expect(count).to.be.equal(2);
|
||||||
});
|
});
|
||||||
it('should do nothing on keyup events if no keys are down', function() {
|
it('should do nothing on keyup events if no keys are down', function() {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = sinon.spy();
|
kbd.onkeyevent = sinon.spy();
|
||||||
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
|
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
|
||||||
expect(kbd.onkeyevent).to.not.have.been.called;
|
expect(kbd.onkeyevent).to.not.have.been.called;
|
||||||
|
|
@ -273,8 +269,8 @@ describe('Key Event Handling', function() {
|
||||||
|
|
||||||
describe('Legacy Events', function() {
|
describe('Legacy Events', function() {
|
||||||
it('should track keys using keyCode if no code', function(done) {
|
it('should track keys using keyCode if no code', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('Platform65');
|
expect(code).to.be.equal('Platform65');
|
||||||
if (!down) {
|
if (!down) {
|
||||||
|
|
@ -285,16 +281,16 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyUp(keyevent('keyup', {keyCode: 65, key: 'b'}));
|
kbd._handleKeyUp(keyevent('keyup', {keyCode: 65, key: 'b'}));
|
||||||
});
|
});
|
||||||
it('should ignore compositing code', function() {
|
it('should ignore compositing code', function() {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('Unidentified');
|
expect(code).to.be.equal('Unidentified');
|
||||||
};
|
};
|
||||||
kbd._handleKeyDown(keyevent('keydown', {keyCode: 229, key: 'a'}));
|
kbd._handleKeyDown(keyevent('keydown', {keyCode: 229, key: 'a'}));
|
||||||
});
|
});
|
||||||
it('should track keys using keyIdentifier if no code', function(done) {
|
it('should track keys using keyIdentifier if no code', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
expect(code).to.be.equal('Platform65');
|
expect(code).to.be.equal('Platform65');
|
||||||
if (!down) {
|
if (!down) {
|
||||||
|
|
@ -308,7 +304,7 @@ describe('Key Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Shuffle modifiers on macOS', function() {
|
describe('Shuffle modifiers on macOS', function() {
|
||||||
var origNavigator;
|
let origNavigator;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// window.navigator is a protected read-only property in many
|
// window.navigator is a protected read-only property in many
|
||||||
// environments, so we need to redefine it whilst running these
|
// environments, so we need to redefine it whilst running these
|
||||||
|
|
@ -334,9 +330,9 @@ describe('Key Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should change Alt to AltGraph', function() {
|
it('should change Alt to AltGraph', function() {
|
||||||
var count = 0;
|
let count = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code) => {
|
||||||
switch (count++) {
|
switch (count++) {
|
||||||
case 0:
|
case 0:
|
||||||
expect(keysym).to.be.equal(0xFF7E);
|
expect(keysym).to.be.equal(0xFF7E);
|
||||||
|
|
@ -353,8 +349,8 @@ describe('Key Event Handling', function() {
|
||||||
expect(count).to.be.equal(2);
|
expect(count).to.be.equal(2);
|
||||||
});
|
});
|
||||||
it('should change left Super to Alt', function(done) {
|
it('should change left Super to Alt', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code) => {
|
||||||
expect(keysym).to.be.equal(0xFFE9);
|
expect(keysym).to.be.equal(0xFFE9);
|
||||||
expect(code).to.be.equal('MetaLeft');
|
expect(code).to.be.equal('MetaLeft');
|
||||||
done();
|
done();
|
||||||
|
|
@ -362,8 +358,8 @@ describe('Key Event Handling', function() {
|
||||||
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaLeft', key: 'Meta', location: 1}));
|
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaLeft', key: 'Meta', location: 1}));
|
||||||
});
|
});
|
||||||
it('should change right Super to left Super', function(done) {
|
it('should change right Super to left Super', function(done) {
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code) => {
|
||||||
expect(keysym).to.be.equal(0xFFEB);
|
expect(keysym).to.be.equal(0xFFEB);
|
||||||
expect(code).to.be.equal('MetaRight');
|
expect(code).to.be.equal('MetaRight');
|
||||||
done();
|
done();
|
||||||
|
|
@ -373,7 +369,7 @@ describe('Key Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Escape AltGraph on Windows', function() {
|
describe('Escape AltGraph on Windows', function() {
|
||||||
var origNavigator;
|
let origNavigator;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// window.navigator is a protected read-only property in many
|
// window.navigator is a protected read-only property in many
|
||||||
// environments, so we need to redefine it whilst running these
|
// environments, so we need to redefine it whilst running these
|
||||||
|
|
@ -399,9 +395,9 @@ describe('Key Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate fake undo/redo events on press when AltGraph is down', function() {
|
it('should generate fake undo/redo events on press when AltGraph is down', function() {
|
||||||
var times_called = 0;
|
let times_called = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
switch(times_called++) {
|
switch(times_called++) {
|
||||||
case 0:
|
case 0:
|
||||||
expect(keysym).to.be.equal(0xFFE3);
|
expect(keysym).to.be.equal(0xFFE3);
|
||||||
|
|
@ -448,9 +444,9 @@ describe('Key Event Handling', function() {
|
||||||
expect(times_called).to.be.equal(7);
|
expect(times_called).to.be.equal(7);
|
||||||
});
|
});
|
||||||
it('should no do anything on key release', function() {
|
it('should no do anything on key release', function() {
|
||||||
var times_called = 0;
|
let times_called = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
switch(times_called++) {
|
switch(times_called++) {
|
||||||
case 7:
|
case 7:
|
||||||
expect(keysym).to.be.equal(0x61);
|
expect(keysym).to.be.equal(0x61);
|
||||||
|
|
@ -468,9 +464,9 @@ describe('Key Event Handling', function() {
|
||||||
expect(times_called).to.be.equal(8);
|
expect(times_called).to.be.equal(8);
|
||||||
});
|
});
|
||||||
it('should not consider a char modifier to be down on the modifier key itself', function() {
|
it('should not consider a char modifier to be down on the modifier key itself', function() {
|
||||||
var times_called = 0;
|
let times_called = 0;
|
||||||
var kbd = new Keyboard(document);
|
const kbd = new Keyboard(document);
|
||||||
kbd.onkeyevent = function(keysym, code, down) {
|
kbd.onkeyevent = (keysym, code, down) => {
|
||||||
switch(times_called++) {
|
switch(times_called++) {
|
||||||
case 0:
|
case 0:
|
||||||
expect(keysym).to.be.equal(0xFFE3);
|
expect(keysym).to.be.equal(0xFFE3);
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
/* jshint expr: true */
|
const expect = chai.expect;
|
||||||
|
|
||||||
var assert = chai.assert;
|
import { l10n } from '../app/localization.js';
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import l10nGet, { l10n } from '../app/localization.js';
|
|
||||||
|
|
||||||
describe('Localization', function() {
|
describe('Localization', function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
describe('language selection', function () {
|
describe('language selection', function () {
|
||||||
var origNavigator;
|
let origNavigator;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// window.navigator is a protected read-only property in many
|
// window.navigator is a protected read-only property in many
|
||||||
// environments, so we need to redefine it whilst running these
|
// environments, so we need to redefine it whilst running these
|
||||||
|
|
@ -35,7 +30,8 @@ describe('Localization', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use English by default', function() {
|
it('should use English by default', function() {
|
||||||
expect(l10n.language).to.equal('en');
|
const a = l10n.language;
|
||||||
|
expect(a).to.equal('en');
|
||||||
});
|
});
|
||||||
it('should use English if no user language matches', function() {
|
it('should use English if no user language matches', function() {
|
||||||
window.navigator.languages = ["nl", "de"];
|
window.navigator.languages = ["nl", "de"];
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,36 @@
|
||||||
var assert = chai.assert;
|
const expect = chai.expect;
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import sinon from '../vendor/sinon.js';
|
import sinon from '../vendor/sinon.js';
|
||||||
|
|
||||||
import Mouse from '../core/input/mouse.js';
|
import Mouse from '../core/input/mouse.js';
|
||||||
import * as eventUtils from '../core/util/events.js';
|
import * as eventUtils from '../core/util/events.js';
|
||||||
|
|
||||||
/* jshint newcap: false, expr: true */
|
|
||||||
describe('Mouse Event Handling', function() {
|
describe('Mouse Event Handling', function() {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
sinon.stub(eventUtils, 'setCapture');
|
sinon.stub(eventUtils, 'setCapture');
|
||||||
// This function is only used on target (the canvas)
|
// This function is only used on target (the canvas)
|
||||||
// and for these tests we can assume that the canvas is 100x100
|
// and for these tests we can assume that the canvas is 100x100
|
||||||
// located at coordinates 10x10
|
// located at coordinates 10x10
|
||||||
sinon.stub(Element.prototype, 'getBoundingClientRect').returns(
|
sinon.stub(Element.prototype, 'getBoundingClientRect').returns(
|
||||||
{left: 10, right: 110, top: 10, bottom: 110, width: 100, height: 100});
|
{left: 10, right: 110, top: 10, bottom: 110, width: 100, height: 100});
|
||||||
var target = document.createElement('canvas');
|
const target = document.createElement('canvas');
|
||||||
|
|
||||||
// The real constructors might not work everywhere we
|
// The real constructors might not work everywhere we
|
||||||
// want to run these tests
|
// want to run these tests
|
||||||
var mouseevent, touchevent;
|
const touchevent = (typeArg, MouseEventInit) => {
|
||||||
mouseevent = touchevent = function(typeArg, MouseEventInit) {
|
const e = { type: typeArg };
|
||||||
var e = { type: typeArg };
|
for (let key in MouseEventInit) {
|
||||||
for (var key in MouseEventInit) {
|
|
||||||
e[key] = MouseEventInit[key];
|
e[key] = MouseEventInit[key];
|
||||||
}
|
}
|
||||||
e.stopPropagation = sinon.spy();
|
e.stopPropagation = sinon.spy();
|
||||||
e.preventDefault = sinon.spy();
|
e.preventDefault = sinon.spy();
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
|
const mouseevent = touchevent;
|
||||||
|
|
||||||
describe('Decode Mouse Events', function() {
|
describe('Decode Mouse Events', function() {
|
||||||
it('should decode mousedown events', function(done) {
|
it('should decode mousedown events', function(done) {
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down, bmask) => {
|
||||||
expect(bmask).to.be.equal(0x01);
|
expect(bmask).to.be.equal(0x01);
|
||||||
expect(down).to.be.equal(1);
|
expect(down).to.be.equal(1);
|
||||||
done();
|
done();
|
||||||
|
|
@ -42,9 +38,9 @@ describe('Mouse Event Handling', function() {
|
||||||
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
|
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
|
||||||
});
|
});
|
||||||
it('should decode mouseup events', function(done) {
|
it('should decode mouseup events', function(done) {
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down, bmask) => {
|
||||||
expect(bmask).to.be.equal(0x01);
|
expect(bmask).to.be.equal(0x01);
|
||||||
if (calls++ === 1) {
|
if (calls++ === 1) {
|
||||||
expect(down).to.not.be.equal(1);
|
expect(down).to.not.be.equal(1);
|
||||||
|
|
@ -55,8 +51,8 @@ describe('Mouse Event Handling', function() {
|
||||||
mouse._handleMouseUp(mouseevent('mouseup', { button: '0x01' }));
|
mouse._handleMouseUp(mouseevent('mouseup', { button: '0x01' }));
|
||||||
});
|
});
|
||||||
it('should decode mousemove events', function(done) {
|
it('should decode mousemove events', function(done) {
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousemove = function(x, y) {
|
mouse.onmousemove = (x, y) => {
|
||||||
// Note that target relative coordinates are sent
|
// Note that target relative coordinates are sent
|
||||||
expect(x).to.be.equal(40);
|
expect(x).to.be.equal(40);
|
||||||
expect(y).to.be.equal(10);
|
expect(y).to.be.equal(10);
|
||||||
|
|
@ -66,9 +62,9 @@ describe('Mouse Event Handling', function() {
|
||||||
{ clientX: 50, clientY: 20 }));
|
{ clientX: 50, clientY: 20 }));
|
||||||
});
|
});
|
||||||
it('should decode mousewheel events', function(done) {
|
it('should decode mousewheel events', function(done) {
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down, bmask) => {
|
||||||
calls++;
|
calls++;
|
||||||
expect(bmask).to.be.equal(1<<6);
|
expect(bmask).to.be.equal(1<<6);
|
||||||
if (calls === 1) {
|
if (calls === 1) {
|
||||||
|
|
@ -90,9 +86,9 @@ describe('Mouse Event Handling', function() {
|
||||||
afterEach(function () { this.clock.restore(); });
|
afterEach(function () { this.clock.restore(); });
|
||||||
|
|
||||||
it('should use same pos for 2nd tap if close enough', function(done) {
|
it('should use same pos for 2nd tap if close enough', function(done) {
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down) => {
|
||||||
calls++;
|
calls++;
|
||||||
if (calls === 1) {
|
if (calls === 1) {
|
||||||
expect(down).to.be.equal(1);
|
expect(down).to.be.equal(1);
|
||||||
|
|
@ -121,9 +117,9 @@ describe('Mouse Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not modify 2nd tap pos if far apart', function(done) {
|
it('should not modify 2nd tap pos if far apart', function(done) {
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down) => {
|
||||||
calls++;
|
calls++;
|
||||||
if (calls === 1) {
|
if (calls === 1) {
|
||||||
expect(down).to.be.equal(1);
|
expect(down).to.be.equal(1);
|
||||||
|
|
@ -150,9 +146,9 @@ describe('Mouse Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not modify 2nd tap pos if not soon enough', function(done) {
|
it('should not modify 2nd tap pos if not soon enough', function(done) {
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down) => {
|
||||||
calls++;
|
calls++;
|
||||||
if (calls === 1) {
|
if (calls === 1) {
|
||||||
expect(down).to.be.equal(1);
|
expect(down).to.be.equal(1);
|
||||||
|
|
@ -179,9 +175,9 @@ describe('Mouse Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not modify 2nd tap pos if not touch', function(done) {
|
it('should not modify 2nd tap pos if not touch', function(done) {
|
||||||
var calls = 0;
|
let calls = 0;
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = function(x, y, down, bmask) {
|
mouse.onmousebutton = (x, y, down) => {
|
||||||
calls++;
|
calls++;
|
||||||
if (calls === 1) {
|
if (calls === 1) {
|
||||||
expect(down).to.be.equal(1);
|
expect(down).to.be.equal(1);
|
||||||
|
|
@ -215,7 +211,7 @@ describe('Mouse Event Handling', function() {
|
||||||
afterEach(function () { this.clock.restore(); });
|
afterEach(function () { this.clock.restore(); });
|
||||||
|
|
||||||
it('should accumulate wheel events if small enough', function () {
|
it('should accumulate wheel events if small enough', function () {
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = sinon.spy();
|
mouse.onmousebutton = sinon.spy();
|
||||||
|
|
||||||
mouse._handleMouseWheel(mouseevent(
|
mouse._handleMouseWheel(mouseevent(
|
||||||
|
|
@ -248,7 +244,7 @@ describe('Mouse Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not accumulate large wheel events', function () {
|
it('should not accumulate large wheel events', function () {
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = sinon.spy();
|
mouse.onmousebutton = sinon.spy();
|
||||||
|
|
||||||
mouse._handleMouseWheel(mouseevent(
|
mouse._handleMouseWheel(mouseevent(
|
||||||
|
|
@ -267,7 +263,7 @@ describe('Mouse Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send even small wheel events after a timeout', function () {
|
it('should send even small wheel events after a timeout', function () {
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = sinon.spy();
|
mouse.onmousebutton = sinon.spy();
|
||||||
|
|
||||||
mouse._handleMouseWheel(mouseevent(
|
mouse._handleMouseWheel(mouseevent(
|
||||||
|
|
@ -279,7 +275,7 @@ describe('Mouse Event Handling', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should account for non-zero deltaMode', function () {
|
it('should account for non-zero deltaMode', function () {
|
||||||
var mouse = new Mouse(target);
|
const mouse = new Mouse(target);
|
||||||
mouse.onmousebutton = sinon.spy();
|
mouse.onmousebutton = sinon.spy();
|
||||||
|
|
||||||
mouse._handleMouseWheel(mouseevent(
|
mouse._handleMouseWheel(mouseevent(
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,7 +1,5 @@
|
||||||
/* jshint expr: true */
|
/* eslint-disable no-console */
|
||||||
|
const expect = chai.expect;
|
||||||
var assert = chai.assert;
|
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import * as Log from '../core/util/logging.js';
|
import * as Log from '../core/util/logging.js';
|
||||||
|
|
||||||
|
|
@ -70,3 +68,4 @@ describe('Utils', function() {
|
||||||
// (we can't really test them against the browsers, except for Gecko
|
// (we can't really test them against the browsers, except for Gecko
|
||||||
// via PhantomJS, the default test driver)
|
// via PhantomJS, the default test driver)
|
||||||
});
|
});
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
/* jshint expr: true */
|
const expect = chai.expect;
|
||||||
var assert = chai.assert;
|
|
||||||
var expect = chai.expect;
|
|
||||||
|
|
||||||
import Websock from '../core/websock.js';
|
import Websock from '../core/websock.js';
|
||||||
import FakeWebSocket from './fake.websocket.js';
|
import FakeWebSocket from './fake.websocket.js';
|
||||||
|
|
@ -11,8 +9,8 @@ describe('Websock', function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe('Queue methods', function () {
|
describe('Queue methods', function () {
|
||||||
var sock;
|
let sock;
|
||||||
var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
const RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new Websock();
|
||||||
|
|
@ -37,8 +35,8 @@ describe('Websock', function() {
|
||||||
|
|
||||||
describe('rQpeek8', function () {
|
describe('rQpeek8', function () {
|
||||||
it('should peek at the next byte without poping it off the queue', function () {
|
it('should peek at the next byte without poping it off the queue', function () {
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
var peek = sock.rQpeek8();
|
const peek = sock.rQpeek8();
|
||||||
expect(sock.rQpeek8()).to.equal(peek);
|
expect(sock.rQpeek8()).to.equal(peek);
|
||||||
expect(sock.rQlen()).to.equal(bef_len);
|
expect(sock.rQlen()).to.equal(bef_len);
|
||||||
});
|
});
|
||||||
|
|
@ -46,8 +44,8 @@ describe('Websock', function() {
|
||||||
|
|
||||||
describe('rQshift8', function () {
|
describe('rQshift8', function () {
|
||||||
it('should pop a single byte from the receive queue', function () {
|
it('should pop a single byte from the receive queue', function () {
|
||||||
var peek = sock.rQpeek8();
|
const peek = sock.rQpeek8();
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
expect(sock.rQshift8()).to.equal(peek);
|
expect(sock.rQshift8()).to.equal(peek);
|
||||||
expect(sock.rQlen()).to.equal(bef_len - 1);
|
expect(sock.rQlen()).to.equal(bef_len - 1);
|
||||||
});
|
});
|
||||||
|
|
@ -55,8 +53,8 @@ describe('Websock', function() {
|
||||||
|
|
||||||
describe('rQshift16', function () {
|
describe('rQshift16', function () {
|
||||||
it('should pop two bytes from the receive queue and return a single number', function () {
|
it('should pop two bytes from the receive queue and return a single number', function () {
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
var expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1];
|
const expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1];
|
||||||
expect(sock.rQshift16()).to.equal(expected);
|
expect(sock.rQshift16()).to.equal(expected);
|
||||||
expect(sock.rQlen()).to.equal(bef_len - 2);
|
expect(sock.rQlen()).to.equal(bef_len - 2);
|
||||||
});
|
});
|
||||||
|
|
@ -64,8 +62,8 @@ describe('Websock', function() {
|
||||||
|
|
||||||
describe('rQshift32', function () {
|
describe('rQshift32', function () {
|
||||||
it('should pop four bytes from the receive queue and return a single number', function () {
|
it('should pop four bytes from the receive queue and return a single number', function () {
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
var expected = (RQ_TEMPLATE[0] << 24) +
|
const expected = (RQ_TEMPLATE[0] << 24) +
|
||||||
(RQ_TEMPLATE[1] << 16) +
|
(RQ_TEMPLATE[1] << 16) +
|
||||||
(RQ_TEMPLATE[2] << 8) +
|
(RQ_TEMPLATE[2] << 8) +
|
||||||
RQ_TEMPLATE[3];
|
RQ_TEMPLATE[3];
|
||||||
|
|
@ -76,9 +74,9 @@ describe('Websock', function() {
|
||||||
|
|
||||||
describe('rQshiftStr', function () {
|
describe('rQshiftStr', function () {
|
||||||
it('should shift the given number of bytes off of the receive queue and return a string', function () {
|
it('should shift the given number of bytes off of the receive queue and return a string', function () {
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
var bef_rQi = sock.get_rQi();
|
const bef_rQi = sock.get_rQi();
|
||||||
var shifted = sock.rQshiftStr(3);
|
const shifted = sock.rQshiftStr(3);
|
||||||
expect(shifted).to.be.a('string');
|
expect(shifted).to.be.a('string');
|
||||||
expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3))));
|
expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3))));
|
||||||
expect(sock.rQlen()).to.equal(bef_len - 3);
|
expect(sock.rQlen()).to.equal(bef_len - 3);
|
||||||
|
|
@ -92,9 +90,9 @@ describe('Websock', function() {
|
||||||
|
|
||||||
describe('rQshiftBytes', function () {
|
describe('rQshiftBytes', function () {
|
||||||
it('should shift the given number of bytes of the receive queue and return an array', function () {
|
it('should shift the given number of bytes of the receive queue and return an array', function () {
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
var bef_rQi = sock.get_rQi();
|
const bef_rQi = sock.get_rQi();
|
||||||
var shifted = sock.rQshiftBytes(3);
|
const shifted = sock.rQshiftBytes(3);
|
||||||
expect(shifted).to.be.an.instanceof(Uint8Array);
|
expect(shifted).to.be.an.instanceof(Uint8Array);
|
||||||
expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3));
|
expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3));
|
||||||
expect(sock.rQlen()).to.equal(bef_len - 3);
|
expect(sock.rQlen()).to.equal(bef_len - 3);
|
||||||
|
|
@ -112,19 +110,19 @@ describe('Websock', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not modify the receive queue', function () {
|
it('should not modify the receive queue', function () {
|
||||||
var bef_len = sock.rQlen();
|
const bef_len = sock.rQlen();
|
||||||
sock.rQslice(0, 2);
|
sock.rQslice(0, 2);
|
||||||
expect(sock.rQlen()).to.equal(bef_len);
|
expect(sock.rQlen()).to.equal(bef_len);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return an array containing the given slice of the receive queue', function () {
|
it('should return an array containing the given slice of the receive queue', function () {
|
||||||
var sl = sock.rQslice(0, 2);
|
const sl = sock.rQslice(0, 2);
|
||||||
expect(sl).to.be.an.instanceof(Uint8Array);
|
expect(sl).to.be.an.instanceof(Uint8Array);
|
||||||
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 0, 2));
|
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 0, 2));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use the rest of the receive queue if no end is given', function () {
|
it('should use the rest of the receive queue if no end is given', function () {
|
||||||
var sl = sock.rQslice(1);
|
const sl = sock.rQslice(1);
|
||||||
expect(sl).to.have.length(RQ_TEMPLATE.length - 1);
|
expect(sl).to.have.length(RQ_TEMPLATE.length - 1);
|
||||||
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 1));
|
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 1));
|
||||||
});
|
});
|
||||||
|
|
@ -178,7 +176,7 @@ describe('Websock', function() {
|
||||||
sock._websocket.readyState = WebSocket.OPEN
|
sock._websocket.readyState = WebSocket.OPEN
|
||||||
sock._sQ = new Uint8Array([1, 2, 3]);
|
sock._sQ = new Uint8Array([1, 2, 3]);
|
||||||
sock._sQlen = 3;
|
sock._sQlen = 3;
|
||||||
var encoded = sock._encode_message();
|
const encoded = sock._encode_message();
|
||||||
|
|
||||||
sock.flush();
|
sock.flush();
|
||||||
expect(sock._websocket.send).to.have.been.calledOnce;
|
expect(sock._websocket.send).to.have.been.calledOnce;
|
||||||
|
|
@ -202,7 +200,7 @@ describe('Websock', function() {
|
||||||
|
|
||||||
it('should add to the send queue', function () {
|
it('should add to the send queue', function () {
|
||||||
sock.send([1, 2, 3]);
|
sock.send([1, 2, 3]);
|
||||||
var sq = sock.get_sQ();
|
const sq = sock.get_sQ();
|
||||||
expect(new Uint8Array(sq.buffer, sock._sQlen - 3, 3)).to.array.equal(new Uint8Array([1, 2, 3]));
|
expect(new Uint8Array(sq.buffer, sock._sQlen - 3, 3)).to.array.equal(new Uint8Array([1, 2, 3]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -225,14 +223,15 @@ describe('Websock', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('lifecycle methods', function () {
|
describe('lifecycle methods', function () {
|
||||||
var old_WS;
|
let old_WS;
|
||||||
before(function () {
|
before(function () {
|
||||||
old_WS = WebSocket;
|
old_WS = WebSocket;
|
||||||
});
|
});
|
||||||
|
|
||||||
var sock;
|
let sock;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new Websock();
|
||||||
|
// eslint-disable-next-line no-global-assign
|
||||||
WebSocket = sinon.spy();
|
WebSocket = sinon.spy();
|
||||||
WebSocket.OPEN = old_WS.OPEN;
|
WebSocket.OPEN = old_WS.OPEN;
|
||||||
WebSocket.CONNECTING = old_WS.CONNECTING;
|
WebSocket.CONNECTING = old_WS.CONNECTING;
|
||||||
|
|
@ -328,19 +327,20 @@ describe('Websock', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
|
// eslint-disable-next-line no-global-assign
|
||||||
WebSocket = old_WS;
|
WebSocket = old_WS;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('WebSocket Receiving', function () {
|
describe('WebSocket Receiving', function () {
|
||||||
var sock;
|
let sock;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new Websock();
|
||||||
sock._allocate_buffers();
|
sock._allocate_buffers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support adding binary Uint8Array data to the receive queue', function () {
|
it('should support adding binary Uint8Array data to the receive queue', function () {
|
||||||
var msg = { data: new Uint8Array([1, 2, 3]) };
|
const msg = { data: new Uint8Array([1, 2, 3]) };
|
||||||
sock._mode = 'binary';
|
sock._mode = 'binary';
|
||||||
sock._recv_message(msg);
|
sock._recv_message(msg);
|
||||||
expect(sock.rQshiftStr(3)).to.equal('\x01\x02\x03');
|
expect(sock.rQshiftStr(3)).to.equal('\x01\x02\x03');
|
||||||
|
|
@ -348,7 +348,7 @@ describe('Websock', function() {
|
||||||
|
|
||||||
it('should call the message event handler if present', function () {
|
it('should call the message event handler if present', function () {
|
||||||
sock._eventHandlers.message = sinon.spy();
|
sock._eventHandlers.message = sinon.spy();
|
||||||
var msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
const msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||||
sock._mode = 'binary';
|
sock._mode = 'binary';
|
||||||
sock._recv_message(msg);
|
sock._recv_message(msg);
|
||||||
expect(sock._eventHandlers.message).to.have.been.calledOnce;
|
expect(sock._eventHandlers.message).to.have.been.calledOnce;
|
||||||
|
|
@ -356,7 +356,7 @@ describe('Websock', function() {
|
||||||
|
|
||||||
it('should not call the message event handler if there is nothing in the receive queue', function () {
|
it('should not call the message event handler if there is nothing in the receive queue', function () {
|
||||||
sock._eventHandlers.message = sinon.spy();
|
sock._eventHandlers.message = sinon.spy();
|
||||||
var msg = { data: new Uint8Array([]).buffer };
|
const msg = { data: new Uint8Array([]).buffer };
|
||||||
sock._mode = 'binary';
|
sock._mode = 'binary';
|
||||||
sock._recv_message(msg);
|
sock._recv_message(msg);
|
||||||
expect(sock._eventHandlers.message).not.to.have.been.called;
|
expect(sock._eventHandlers.message).not.to.have.been.called;
|
||||||
|
|
@ -369,7 +369,7 @@ describe('Websock', function() {
|
||||||
sock._rQlen = 6;
|
sock._rQlen = 6;
|
||||||
sock.set_rQi(6);
|
sock.set_rQi(6);
|
||||||
sock._rQmax = 3;
|
sock._rQmax = 3;
|
||||||
var msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
const msg = { data: new Uint8Array([1, 2, 3]).buffer };
|
||||||
sock._mode = 'binary';
|
sock._mode = 'binary';
|
||||||
sock._recv_message(msg);
|
sock._recv_message(msg);
|
||||||
expect(sock._rQlen).to.equal(3);
|
expect(sock._rQlen).to.equal(3);
|
||||||
|
|
@ -382,12 +382,12 @@ describe('Websock', function() {
|
||||||
sock.set_rQi(0);
|
sock.set_rQi(0);
|
||||||
sock._rQbufferSize = 20;
|
sock._rQbufferSize = 20;
|
||||||
sock._rQmax = 2;
|
sock._rQmax = 2;
|
||||||
var msg = { data: new Uint8Array(30).buffer };
|
const msg = { data: new Uint8Array(30).buffer };
|
||||||
sock._mode = 'binary';
|
sock._mode = 'binary';
|
||||||
sock._recv_message(msg);
|
sock._recv_message(msg);
|
||||||
expect(sock._rQlen).to.equal(30);
|
expect(sock._rQlen).to.equal(30);
|
||||||
expect(sock.get_rQi()).to.equal(0);
|
expect(sock.get_rQi()).to.equal(0);
|
||||||
expect(sock._rQ.length).to.equal(240); // keep the invariant that rQbufferSize / 8 >= rQlen
|
expect(sock._rQ.length).to.equal(240); // keep the inconstiant that rQbufferSize / 8 >= rQlen
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -396,7 +396,7 @@ describe('Websock', function() {
|
||||||
after(function () { FakeWebSocket.restore(); });
|
after(function () { FakeWebSocket.restore(); });
|
||||||
|
|
||||||
describe('as binary data', function () {
|
describe('as binary data', function () {
|
||||||
var sock;
|
let sock;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sock = new Websock();
|
sock = new Websock();
|
||||||
sock.open('ws://', 'binary');
|
sock.open('ws://', 'binary');
|
||||||
|
|
@ -406,7 +406,7 @@ describe('Websock', function() {
|
||||||
it('should only send the send queue up to the send queue length', function () {
|
it('should only send the send queue up to the send queue length', function () {
|
||||||
sock._sQ = new Uint8Array([1, 2, 3, 4, 5]);
|
sock._sQ = new Uint8Array([1, 2, 3, 4, 5]);
|
||||||
sock._sQlen = 3;
|
sock._sQlen = 3;
|
||||||
var res = sock._encode_message();
|
const res = sock._encode_message();
|
||||||
expect(res).to.array.equal(new Uint8Array([1, 2, 3]));
|
expect(res).to.array.equal(new Uint8Array([1, 2, 3]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"no-console": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var show_help = process.argv.length === 2;
|
let show_help = process.argv.length === 2;
|
||||||
var filename;
|
let filename;
|
||||||
|
|
||||||
for (var i = 2; i < process.argv.length; ++i) {
|
for (let i = 2; i < process.argv.length; ++i) {
|
||||||
switch (process.argv[i]) {
|
switch (process.argv[i]) {
|
||||||
case "--help":
|
case "--help":
|
||||||
case "-h":
|
case "-h":
|
||||||
|
|
@ -36,37 +36,37 @@ if (show_help) {
|
||||||
console.log("Usage: node parse.js [options] filename:");
|
console.log("Usage: node parse.js [options] filename:");
|
||||||
console.log(" -h [ --help ] Produce this help message");
|
console.log(" -h [ --help ] Produce this help message");
|
||||||
console.log(" filename The keysymdef.h file to parse");
|
console.log(" filename The keysymdef.h file to parse");
|
||||||
return;
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf = fs.readFileSync(filename);
|
const buf = fs.readFileSync(filename);
|
||||||
var str = buf.toString('utf8');
|
const str = buf.toString('utf8');
|
||||||
|
|
||||||
var re = /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/m;
|
const re = /^#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/m;
|
||||||
|
|
||||||
var arr = str.split('\n');
|
const arr = str.split('\n');
|
||||||
|
|
||||||
var codepoints = {};
|
const codepoints = {};
|
||||||
|
|
||||||
for (var i = 0; i < arr.length; ++i) {
|
for (let i = 0; i < arr.length; ++i) {
|
||||||
var result = re.exec(arr[i]);
|
const result = re.exec(arr[i]);
|
||||||
if (result){
|
if (result){
|
||||||
var keyname = result[1];
|
const name = result[1];
|
||||||
var keysym = parseInt(result[2], 16);
|
const keysym = parseInt(result[2], 16);
|
||||||
var remainder = result[3];
|
const remainder = result[3];
|
||||||
|
|
||||||
var unicodeRes = /U\+([0-9a-fA-F]+)/.exec(remainder);
|
const unicodeRes = /U\+([0-9a-fA-F]+)/.exec(remainder);
|
||||||
if (unicodeRes) {
|
if (unicodeRes) {
|
||||||
var unicode = parseInt(unicodeRes[1], 16);
|
const unicode = parseInt(unicodeRes[1], 16);
|
||||||
// The first entry is the preferred one
|
// The first entry is the preferred one
|
||||||
if (!codepoints[unicode]){
|
if (!codepoints[unicode]){
|
||||||
codepoints[unicode] = { keysym: keysym, name: keyname };
|
codepoints[unicode] = { keysym, name };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var out =
|
let out =
|
||||||
"/*\n" +
|
"/*\n" +
|
||||||
" * Mapping from Unicode codepoints to X11/RFB keysyms\n" +
|
" * Mapping from Unicode codepoints to X11/RFB keysyms\n" +
|
||||||
" *\n" +
|
" *\n" +
|
||||||
|
|
@ -79,14 +79,14 @@ var out =
|
||||||
"var codepoints = {\n";
|
"var codepoints = {\n";
|
||||||
|
|
||||||
function toHex(num) {
|
function toHex(num) {
|
||||||
var s = num.toString(16);
|
let s = num.toString(16);
|
||||||
if (s.length < 4) {
|
if (s.length < 4) {
|
||||||
s = ("0000" + s).slice(-4);
|
s = ("0000" + s).slice(-4);
|
||||||
}
|
}
|
||||||
return "0x" + s;
|
return "0x" + s;
|
||||||
};
|
}
|
||||||
|
|
||||||
for (var codepoint in codepoints) {
|
for (let codepoint in codepoints) {
|
||||||
codepoint = parseInt(codepoint);
|
codepoint = parseInt(codepoint);
|
||||||
|
|
||||||
// Latin-1?
|
// Latin-1?
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var program = require('commander');
|
const program = require('commander');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var fse = require('fs-extra');
|
const fse = require('fs-extra');
|
||||||
|
|
||||||
const SUPPORTED_FORMATS = new Set(['amd', 'commonjs', 'systemjs', 'umd']);
|
const SUPPORTED_FORMATS = new Set(['amd', 'commonjs', 'systemjs', 'umd']);
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ no_copy_files.forEach((file) => no_transform_files.add(file));
|
||||||
|
|
||||||
// walkDir *recursively* walks directories trees,
|
// walkDir *recursively* walks directories trees,
|
||||||
// calling the callback for all normal files found.
|
// calling the callback for all normal files found.
|
||||||
var walkDir = function (base_path, cb, filter) {
|
function walkDir(base_path, cb, filter) {
|
||||||
fs.readdir(base_path, (err, files) => {
|
fs.readdir(base_path, (err, files) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
|
|
@ -56,26 +56,26 @@ var walkDir = function (base_path, cb, filter) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
var transform_html = function (new_script) {
|
function transform_html(new_script) {
|
||||||
// write out the modified vnc.html file that works with the bundle
|
// write out the modified vnc.html file that works with the bundle
|
||||||
var src_html_path = path.resolve(__dirname, '..', 'vnc.html');
|
const src_html_path = path.resolve(__dirname, '..', 'vnc.html');
|
||||||
var out_html_path = path.resolve(paths.out_dir_base, 'vnc.html');
|
const out_html_path = path.resolve(paths.out_dir_base, 'vnc.html');
|
||||||
fs.readFile(src_html_path, (err, contents_raw) => {
|
fs.readFile(src_html_path, (err, contents_raw) => {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
|
|
||||||
var contents = contents_raw.toString();
|
let contents = contents_raw.toString();
|
||||||
|
|
||||||
var start_marker = '<!-- begin scripts -->\n';
|
const start_marker = '<!-- begin scripts -->\n';
|
||||||
var end_marker = '<!-- end scripts -->';
|
const end_marker = '<!-- end scripts -->';
|
||||||
var start_ind = contents.indexOf(start_marker) + start_marker.length;
|
const start_ind = contents.indexOf(start_marker) + start_marker.length;
|
||||||
var end_ind = contents.indexOf(end_marker, start_ind);
|
const end_ind = contents.indexOf(end_marker, start_ind);
|
||||||
|
|
||||||
contents = contents.slice(0, start_ind) + `${new_script}\n` + contents.slice(end_ind);
|
contents = contents.slice(0, start_ind) + `${new_script}\n` + contents.slice(end_ind);
|
||||||
|
|
||||||
console.log(`Writing ${out_html_path}`);
|
console.log(`Writing ${out_html_path}`);
|
||||||
fs.writeFile(out_html_path, contents, function (err) {
|
fs.writeFile(out_html_path, contents, (err) => {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -90,18 +90,20 @@ var make_lib_files = function (import_format, source_maps, with_app_dir) {
|
||||||
|
|
||||||
// NB: we need to make a copy of babel_opts, since babel sets some defaults on it
|
// NB: we need to make a copy of babel_opts, since babel sets some defaults on it
|
||||||
const babel_opts = () => ({
|
const babel_opts = () => ({
|
||||||
|
presets: ['es2015'],
|
||||||
plugins: [`transform-es2015-modules-${import_format}`],
|
plugins: [`transform-es2015-modules-${import_format}`],
|
||||||
ast: false,
|
ast: false,
|
||||||
sourceMaps: source_maps,
|
sourceMaps: source_maps,
|
||||||
});
|
});
|
||||||
const babel = require('babel-core');
|
const babel = require('babel-core');
|
||||||
|
|
||||||
var in_path;
|
let in_path;
|
||||||
|
let out_path_base;
|
||||||
if (with_app_dir) {
|
if (with_app_dir) {
|
||||||
var out_path_base = paths.out_dir_base;
|
out_path_base = paths.out_dir_base;
|
||||||
in_path = paths.main;
|
in_path = paths.main;
|
||||||
} else {
|
} else {
|
||||||
var out_path_base = paths.lib_dir_base;
|
out_path_base = paths.lib_dir_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
fse.ensureDirSync(out_path_base);
|
fse.ensureDirSync(out_path_base);
|
||||||
|
|
@ -109,7 +111,7 @@ var make_lib_files = function (import_format, source_maps, with_app_dir) {
|
||||||
const helpers = require('./use_require_helpers');
|
const helpers = require('./use_require_helpers');
|
||||||
const helper = helpers[import_format];
|
const helper = helpers[import_format];
|
||||||
|
|
||||||
var handleDir = (js_only, vendor_rewrite, in_path_base, filename) => {
|
const handleDir = (js_only, vendor_rewrite, in_path_base, filename) => {
|
||||||
if (no_copy_files.has(filename)) return;
|
if (no_copy_files.has(filename)) return;
|
||||||
|
|
||||||
const out_path = path.join(out_path_base, path.relative(in_path_base, filename));
|
const out_path = path.join(out_path_base, path.relative(in_path_base, filename));
|
||||||
|
|
@ -143,7 +145,7 @@ var make_lib_files = function (import_format, source_maps, with_app_dir) {
|
||||||
babel.transformFile(filename, opts, (err, res) => {
|
babel.transformFile(filename, opts, (err, res) => {
|
||||||
console.log(`Writing ${out_path}`);
|
console.log(`Writing ${out_path}`);
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
var {code, map, ast} = res;
|
let {code, map} = res;
|
||||||
if (source_maps === true) {
|
if (source_maps === true) {
|
||||||
// append URL for external source map
|
// append URL for external source map
|
||||||
code += `\n//# sourceMappingURL=${path.basename(out_path)}.map\n`;
|
code += `\n//# sourceMappingURL=${path.basename(out_path)}.map\n`;
|
||||||
|
|
@ -161,11 +163,11 @@ var make_lib_files = function (import_format, source_maps, with_app_dir) {
|
||||||
helper.noCopyOverride(paths, no_copy_files);
|
helper.noCopyOverride(paths, no_copy_files);
|
||||||
}
|
}
|
||||||
|
|
||||||
walkDir(paths.vendor, handleDir.bind(null, true, false, in_path || paths.main), (filename, stats) => !no_copy_files.has(filename));
|
walkDir(paths.vendor, handleDir.bind(null, true, false, in_path || paths.main), filename => !no_copy_files.has(filename));
|
||||||
walkDir(paths.core, handleDir.bind(null, true, !in_path, in_path || paths.core), (filename, stats) => !no_copy_files.has(filename));
|
walkDir(paths.core, handleDir.bind(null, true, !in_path, in_path || paths.core), filename => !no_copy_files.has(filename));
|
||||||
|
|
||||||
if (with_app_dir) {
|
if (with_app_dir) {
|
||||||
walkDir(paths.app, handleDir.bind(null, false, false, in_path), (filename, stats) => !no_copy_files.has(filename));
|
walkDir(paths.app, handleDir.bind(null, false, false, in_path), filename => !no_copy_files.has(filename));
|
||||||
|
|
||||||
const out_app_path = path.join(out_path_base, 'app.js');
|
const out_app_path = path.join(out_path_base, 'app.js');
|
||||||
if (helper && helper.appWriter) {
|
if (helper && helper.appWriter) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// writes helpers require for vnc.html (they should output app.js)
|
// writes helpers require for vnc.html (they should output app.js)
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var fse = require('fs-extra');
|
const path = require('path');
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'amd': {
|
'amd': {
|
||||||
|
|
@ -19,8 +18,8 @@ module.exports = {
|
||||||
opts.plugins.unshift("add-module-exports");
|
opts.plugins.unshift("add-module-exports");
|
||||||
},
|
},
|
||||||
appWriter: (base_out_path, out_path) => {
|
appWriter: (base_out_path, out_path) => {
|
||||||
var browserify = require('browserify');
|
const browserify = require('browserify');
|
||||||
var b = browserify(path.join(base_out_path, 'app/ui.js'), {});
|
const b = browserify(path.join(base_out_path, 'app/ui.js'), {});
|
||||||
b.bundle().pipe(fs.createWriteStream(out_path));
|
b.bundle().pipe(fs.createWriteStream(out_path));
|
||||||
return `<script src="${path.relative(base_out_path, out_path)}"></script>`;
|
return `<script src="${path.relative(base_out_path, out_path)}"></script>`;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ function longest_match(s, cur_match) {
|
||||||
* the 256th check will be made at strstart+258.
|
* the 256th check will be made at strstart+258.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
/*jshint noempty:false*/
|
// Do nothing
|
||||||
} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
||||||
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
||||||
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
||||||
|
|
@ -892,7 +892,7 @@ function deflate_rle(s, flush) {
|
||||||
if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
|
if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
|
||||||
strend = s.strstart + MAX_MATCH;
|
strend = s.strstart + MAX_MATCH;
|
||||||
do {
|
do {
|
||||||
/*jshint noempty:false*/
|
// Do nothing
|
||||||
} while (prev === _win[++scan] && prev === _win[++scan] &&
|
} while (prev === _win[++scan] && prev === _win[++scan] &&
|
||||||
prev === _win[++scan] && prev === _win[++scan] &&
|
prev === _win[++scan] && prev === _win[++scan] &&
|
||||||
prev === _win[++scan] && prev === _win[++scan] &&
|
prev === _win[++scan] && prev === _win[++scan] &&
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue