Use RequireJS module system

Use a standard module system rather than a home grown one, and
RequireJS fits better with browsers than CommonJS.
This commit is contained in:
Pierre Ossman 2017-01-18 16:57:20 +01:00
parent 8ad1347fe3
commit 6bc9cadaef
41 changed files with 2634 additions and 5031 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
*.pyc
*.o
inflator/inflator-merged.js
inflator/pako
tests/data_*.js
utils/rebind.so
utils/websockify

View File

@ -5,7 +5,10 @@
* DO NOT EDIT!
*/
Language = {
"use strict";
define(function() {
return {
"Connecting...": "Verbunden...",
"Connected (encrypted) to ": "Verbunden mit (verschlüsselt) ",
"Connected (unencrypted) to ": "Verbunden mit (unverschlüsselt) ",
@ -16,3 +19,4 @@ Language = {
"Forcing clipping mode since scrollbars aren't supported by IE in fullscreen": "'Clipping-Modus' aktiviert, Scrollbalken in 'IE-Vollbildmodus' werden nicht unterstützt",
"Disconnect timeout": "Timeout beim trennen",
};
});

View File

@ -5,7 +5,10 @@
* DO NOT EDIT!
*/
Language = {
"use strict";
define(function() {
return {
"Connecting...": "Συνδέεται...",
"Connected (encrypted) to ": "Συνδέθηκε (κρυπτογραφημένα) με το ",
"Connected (unencrypted) to ": "Συνδέθηκε (μη κρυπτογραφημένα) με το ",
@ -72,3 +75,4 @@ Language = {
"Send Password": "Αποστολή Κωδικού Πρόσβασης",
"Canvas not supported.": "Δεν υποστηρίζεται το στοιχείο Canvas",
};
});

View File

@ -5,7 +5,10 @@
* DO NOT EDIT!
*/
Language = {
"use strict";
define(function() {
return {
"Connecting...": "Verbinden...",
"Connected (encrypted) to ": "Verbonden (versleuteld) met ",
"Connected (unencrypted) to ": "Verbonden (onversleuteld) met ",
@ -16,3 +19,4 @@ Language = {
"Forcing clipping mode since scrollbars aren't supported by IE in fullscreen": "''Clipping mode' ingeschakeld, omdat schuifbalken in volledige-scherm-modus in IE niet worden ondersteund",
"Disconnect timeout": "Timeout tijdens verbreken van verbinding",
};
});

View File

@ -5,7 +5,10 @@
* DO NOT EDIT!
*/
Language = {
"use strict";
define(function() {
return {
"Connecting...": "Ansluter...",
"Connected (encrypted) to ": "Ansluten (krypterat) till ",
"Connected (unencrypted) to ": "Ansluten (okrypterat) till ",
@ -75,3 +78,4 @@ Language = {
"Send Password": "Skicka Lösenord",
"Canvas not supported.": "Canvas stöds ej",
};
});

22
app/novnc.js Normal file
View File

@ -0,0 +1,22 @@
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
/* jslint white: false, browser: true */
"use strict";
requirejs.config({
baseUrl: '',
});
requirejs(['app/ui', 'core/util'],
function(ui, util) {
// Set up translations, then start the UI
var LINGUAS = ["de", "el", "nl", "sv"];
util.Localisation.setup(LINGUAS, "app/locale", ui.load);
});

5
app/require.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -2,29 +2,19 @@
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2016 Samuel Mannehed for Cendio AB
* Copyright (C) 2016 Pierre Ossman for Cendio AB
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
/* jslint white: false, browser: true */
/* global window, document.getElementById, Util, WebUtil, RFB, Display */
/* [module]
* import Util from "../core/util";
* import KeyTable from "../core/input/keysym";
* import keysyms from "./keysymdef";
* import RFB from "../core/rfb";
* import Display from "../core/display";
* import WebUtil from "./webutil";
*/
"use strict";
var UI;
(function () {
define(["app/webutil", "core/rfb", "core/util",
"core/input/keysym", "core/input/keysymdef"],
function (WebUtil, rfb, Util, KeyTable, keysyms) {
// Fallback for all uncought errors
window.addEventListener('error', function(event) {
@ -66,27 +56,9 @@ var UI;
return false;
});
// Set up translations
var LINGUAS = ["de", "el", "nl", "sv"];
Util.Localisation.setup(LINGUAS);
if (Util.Localisation.language !== "en") {
WebUtil.load_scripts(
{'app': ["locale/" + Util.Localisation.language + ".js"]});
}
/* [begin skip-as-module] */
// Load supporting scripts
WebUtil.load_scripts(
{'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js",
"input/xtscancodes.js", "input/util.js", "input/devices.js",
"display.js", "inflator.js", "rfb.js", "input/keysym.js"]});
window.onscriptsload = function () { UI.load(); };
/* [end skip-as-module] */
var _ = Util.Localisation.get;
UI = {
var UI = {
connected: false,
desktopName: "",
@ -390,7 +362,7 @@ var UI;
initRFB: function() {
try {
UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
UI.rfb = new rfb.RFB({'target': document.getElementById('noVNC_canvas'),
'onNotification': UI.notification,
'onUpdateState': UI.updateState,
'onDisconnected': UI.disconnectFinished,
@ -1679,7 +1651,5 @@ var UI;
*/
};
/* [module] UI.load(); */
})();
/* [module] export default UI; */
return UI;
});

View File

@ -2,38 +2,28 @@
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 NTT corp.
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
/*jslint bitwise: false, white: false, browser: true, devel: true */
/*global Util, window, document */
/* [module]
* import Util from "../core/util";
*/
"use strict";
// Globals defined here
define(['core/util'],
function(Util) {
var WebUtil = {};
/*
* ------------------------------------------------------
* Namespaced in WebUtil
* ------------------------------------------------------
*/
// init log level reading the logging HTTP param
WebUtil.init_logging = function (level) {
if (typeof level !== "undefined") {
Util._log_level = level;
} else {
if (typeof level === "undefined") {
var param = document.location.href.match(/logging=([A-Za-z0-9\._\-]*)/);
Util._log_level = (param || ['', Util._log_level])[1];
if (param !== undefined)
level = param;
}
Util.init_logging();
Util.init_logging(level);
};
@ -231,17 +221,18 @@ WebUtil.injectParamIfMissing = function (path, param, value) {
// Emulate Element.setCapture() when not supported
WebUtil._captureRecursion = false;
WebUtil._captureProxy = function (e) {
var _captureElem;
var _captureRecursion = false;
var _captureProxy = function (e) {
// Recursion protection as we'll see our own event
if (WebUtil._captureRecursion) return;
if (_captureRecursion) return;
// Clone the event as we cannot dispatch an already dispatched event
var newEv = new e.constructor(e.type, e);
WebUtil._captureRecursion = true;
WebUtil._captureElem.dispatchEvent(newEv);
WebUtil._captureRecursion = false;
_captureRecursion = true;
_captureElem.dispatchEvent(newEv);
_captureRecursion = false;
// Implicitly release the capture on button release
if ((e.type === "mouseup") || (e.type === "touchend")) {
@ -284,23 +275,23 @@ WebUtil.setCapture = function (elem) {
captureElem.style.display = "none";
document.body.appendChild(captureElem);
captureElem.addEventListener('mousemove', WebUtil._captureProxy);
captureElem.addEventListener('mouseup', WebUtil._captureProxy);
captureElem.addEventListener('mousemove', _captureProxy);
captureElem.addEventListener('mouseup', _captureProxy);
captureElem.addEventListener('touchmove', WebUtil._captureProxy);
captureElem.addEventListener('touchend', WebUtil._captureProxy);
captureElem.addEventListener('touchmove', _captureProxy);
captureElem.addEventListener('touchend', _captureProxy);
}
WebUtil._captureElem = elem;
_captureElem = elem;
captureElem.style.display = null;
// We listen to events on window in order to keep tracking if it
// happens to leave the viewport
window.addEventListener('mousemove', WebUtil._captureProxy);
window.addEventListener('mouseup', WebUtil._captureProxy);
window.addEventListener('mousemove', _captureProxy);
window.addEventListener('mouseup', _captureProxy);
window.addEventListener('touchmove', WebUtil._captureProxy);
window.addEventListener('touchend', WebUtil._captureProxy);
window.addEventListener('touchmove', _captureProxy);
window.addEventListener('touchend', _captureProxy);
}
};
@ -311,84 +302,16 @@ WebUtil.releaseCapture = function () {
} else {
var captureElem = document.getElementById("noVNC_mouse_capture_elem");
WebUtil._captureElem = null;
_captureElem = null;
captureElem.style.display = "none";
window.removeEventListener('mousemove', WebUtil._captureProxy);
window.removeEventListener('mouseup', WebUtil._captureProxy);
window.removeEventListener('mousemove', _captureProxy);
window.removeEventListener('mouseup', _captureProxy);
window.removeEventListener('touchmove', WebUtil._captureProxy);
window.removeEventListener('touchend', WebUtil._captureProxy);
window.removeEventListener('touchmove', _captureProxy);
window.removeEventListener('touchend', _captureProxy);
}
};
// Dynamically load scripts without using document.write()
// Reference: http://unixpapa.com/js/dyna.html
//
// Handles the case where load_scripts is invoked from a script that
// itself is loaded via load_scripts. Once all scripts are loaded the
// window.onscriptsloaded handler is called (if set).
WebUtil.get_include_uri = function (root_dir) {
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI + root_dir + '/' : root_dir + '/';
};
WebUtil._loading_scripts = [];
WebUtil._pending_scripts = [];
WebUtil.load_scripts = function (files_by_dir) {
var head = document.getElementsByTagName('head')[0], script,
ls = WebUtil._loading_scripts, ps = WebUtil._pending_scripts;
var loadFunc = function (e) {
while (ls.length > 0 && (ls[0].readyState === 'loaded' ||
ls[0].readyState === 'complete')) {
// For IE, append the script to trigger execution
var s = ls.shift();
//console.log("loaded script: " + s.src);
head.appendChild(s);
}
if (!this.readyState ||
(Util.Engine.presto && this.readyState === 'loaded') ||
this.readyState === 'complete') {
if (ps.indexOf(this) >= 0) {
this.onload = this.onreadystatechange = null;
//console.log("completed script: " + this.src);
ps.splice(ps.indexOf(this), 1);
// Call window.onscriptsload after last script loads
if (ps.length === 0 && window.onscriptsload) {
window.onscriptsload();
}
}
}
};
var root_dirs = Object.keys(files_by_dir);
for (var d = 0; d < root_dirs.length; d++) {
var root_dir = root_dirs[d];
var files = files_by_dir[root_dir];
for (var f = 0; f < files.length; f++) {
script = document.createElement('script');
script.type = 'text/javascript';
script.src = WebUtil.get_include_uri(root_dir) + files[f];
//console.log("loading script: " + script.src);
script.onload = script.onreadystatechange = loadFunc;
// In-order script execution tricks
if (Util.Engine.trident) {
// For IE wait until readyState is 'loaded' before
// appending it which will trigger execution
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
ls.push(script);
} else {
// For webkit and firefox set async=false and append now
// https://developer.mozilla.org/en-US/docs/HTML/Element/script
script.async = false;
head.appendChild(script);
}
ps.push(script);
}
}
};
/* [module] export default WebUtil; */
return WebUtil;
});

View File

@ -5,10 +5,10 @@
// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
/*jslint white: false */
/*global console */
"use strict";
define(function () {
var Base64 = {
/* Convert data (an array of integers) to a Base64 string. */
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
@ -112,6 +112,7 @@ var Base64 = {
return result;
}
}; /* End of Base64 namespace */
};
/* [module] export default Base64; */
return Base64;
});

View File

@ -79,8 +79,8 @@
"use strict";
/* [module] export default */ function DES(passwd) {
define(function () {
function DES(passwd) {
// Tables, permutations, S-boxes, etc.
// jshint -W013
var PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
@ -275,3 +275,6 @@
return {'encrypt': encrypt}; // Public interface
}; // function DES
return DES;
});

View File

@ -2,22 +2,27 @@
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2015 Samuel Mannehed for Cendio AB
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
/*jslint browser: true, white: false */
/*global Util, Base64, changeCursor */
/* [module]
* import Util from "./util";
* import Base64 from "./base64";
*/
"use strict";
/* [module] export default */ function Display(defaults) {
define(["core/util", "core/base64"],
function (Util, Base64) {
var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
try {
new ImageData(new Uint8ClampedArray(4), 1, 1);
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true;
} catch (ex) {
// ignore failure
}
function Display(defaults) {
this._drawCtx = null;
this._c_forceCanvas = false;
@ -100,17 +105,6 @@
Util.Debug("<< Display.constructor");
};
(function () {
var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
try {
new ImageData(new Uint8ClampedArray(4), 1, 1);
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true;
} catch (ex) {
// ignore failure
}
Display.prototype = {
// Public methods
viewportChangePos: function (deltaX, deltaY) {
@ -876,4 +870,6 @@
var url = 'data:image/x-icon;base64,' + Base64.encode(cur);
target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default';
};
})();
return { Display: Display };
});

File diff suppressed because one or more lines are too long

View File

@ -1,40 +0,0 @@
var zlib = require('pako/lib/zlib/inflate.js');
var ZStream = require('pako/lib/zlib/zstream.js');
function Inflate() {
this.strm = new ZStream();
this.chunkSize = 1024 * 10 * 10;
this.strm.output = new Uint8Array(this.chunkSize);
this.windowBits = 5;
zlib.inflateInit(this.strm, this.windowBits);
};
Inflate.prototype = {
inflate: function (data, flush, expected) {
this.strm.input = data;
this.strm.avail_in = this.strm.input.length;
this.strm.next_in = 0;
this.strm.next_out = 0;
// resize our output buffer if it's too small
// (we could just use multiple chunks, but that would cause an extra
// allocation each time to flatten the chunks)
if (expected > this.chunkSize) {
this.chunkSize = expected;
this.strm.output = new Uint8Array(this.chunkSize);
}
this.strm.avail_out = this.chunkSize;
zlib.inflate(this.strm, flush);
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
},
reset: function () {
zlib.inflateReset(this.strm);
}
};
module.exports = { Inflate: Inflate };

View File

@ -2,28 +2,21 @@
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
/*jslint browser: true, white: false */
/*global window, Util */
/* [module]
* import Util from "../util";
* import KeyboardUtil from "./util";
*/
"use strict";
/* [module] export */ var Keyboard;
(function () {
define(["core/util", "core/input/util"],
function (Util, KeyboardUtil) {
//
// Keyboard event handler
//
Keyboard = function (defaults) {
function Keyboard(defaults) {
this._keyDownList = []; // List of depressed keys
// (even if they are happy)
@ -159,12 +152,8 @@
['onKeyPress', 'rw', 'func'] // Handler for key press/release
]);
})();
/* [module] export */ var Mouse;
(function () {
Mouse = function (defaults) {
function Mouse(defaults) {
this._mouseCaptured = false;
this._doubleClickTimer = null;
@ -403,4 +392,7 @@
['onMouseMove', 'rw', 'func'], // Handler for mouse movement
['touchButton', 'rw', 'int'] // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
]);
})();
return { Keyboard: Keyboard,
Mouse: Mouse };
});

View File

@ -1,5 +1,6 @@
"use strict";
define(function () {
var KeyTable = {
XK_VoidSymbol: 0xffffff, /* Void symbol */
@ -381,4 +382,5 @@ var KeyTable = {
XK_ydiaeresis: 0x00ff, /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
};
/* [module] export default KeyTable; */
return KeyTable;
});

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,18 @@
/* [module]
* import KeyTable from "./keysym";
* import keysyms from "./keysymdef";
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
/*jslint browser: true, white: false */
"use strict";
define(["core/input/keysym", "core/input/keysymdef"],
function (KeyTable, keysyms) {
var KeyboardUtil = {};
(function() {
function substituteCodepoint(cp) {
// Any Unicode code points which do not have corresponding keysym entries
// can be swapped out for another code point by adding them to this table
@ -287,7 +291,6 @@ var KeyboardUtil = {};
KeyboardUtil.keysymFromKeyCode = keysymFromKeyCode;
KeyboardUtil.nonCharacterKey = nonCharacterKey;
KeyboardUtil.substituteCodepoint = substituteCodepoint;
})();
KeyboardUtil.QEMUKeyEventDecoder = function(modifierState, next) {
function sendAll(evts) {
@ -670,4 +673,5 @@ KeyboardUtil.EscapeModifiers = function(next) {
};
};
/* [module] export default KeyboardUtil; */
return KeyboardUtil;
});

View File

@ -1,5 +1,6 @@
"use strict";
define(function () {
var XtScancode = {
"Escape": 0x0001,
"Digit1": 0x0002,
@ -150,4 +151,5 @@ var XtScancode = {
"MediaSelect": 0xE06D,
};
/* [module] export default XtScancode */
return XtScancode;
});

View File

@ -2,6 +2,7 @@
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2016 Samuel Mannehed for Cendio AB
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
@ -10,23 +11,19 @@
* (c) 2012 Michael Tinglof, Joe Balaz, Les Piech (Mercuri.ca)
*/
/* [module]
* import Util from "./util";
* import Display from "./display";
* import { Keyboard, Mouse } from "./input/devices"
* import Websock from "./websock"
* import Base64 from "./base64";
* import DES from "./des";
* import KeyTable from "./input/keysym";
* import XtScancode from "./input/xtscancodes";
* import Inflator from "./inflator.mod";
*/
/*jslint white: false, browser: true */
/*global window, Util, Display, Keyboard, Mouse, Websock, Websock_native, Base64, DES, KeyTable, Inflator, XtScancode */
"use strict";
/* [module] export default */ function RFB(defaults) {
define(["core/util", "core/display", "core/websock",
"core/inflator", "core/des",
"core/input/devices", "core/input/keysym",
"core/input/xtscancodes"],
function (Util, display, websock, Inflator, DES, devices,
KeyTable, XtScancode) {
var _ = Util.Localisation.get;
function RFB(defaults) {
if (!defaults) {
defaults = {};
}
@ -191,22 +188,22 @@
// NB: nothing that needs explicit teardown should be done
// before this point, since this can throw an exception
try {
this._display = new Display({target: this._target,
this._display = new display.Display({target: this._target,
onFlush: this._onFlush.bind(this)});
} catch (exc) {
Util.Error("Display exception: " + exc);
throw exc;
}
this._keyboard = new Keyboard({target: this._focusContainer,
this._keyboard = new devices.Keyboard({target: this._focusContainer,
onKeyPress: this._handleKeyPress.bind(this)});
this._mouse = new Mouse({target: this._target,
this._mouse = new devices.Mouse({target: this._target,
onMouseButton: this._handleMouseButton.bind(this),
onMouseMove: this._handleMouseMove.bind(this),
notify: this._keyboard.sync.bind(this._keyboard)});
this._sock = new Websock();
this._sock = new websock.Websock();
this._sock.on('message', this._handle_message.bind(this));
this._sock.on('open', function () {
if ((this._rfb_connection_state === 'connecting') &&
@ -263,9 +260,6 @@
Util.Debug("<< RFB.constructor");
};
(function() {
var _ = Util.Localisation.get;
RFB.prototype = {
// Public methods
connect: function (host, port, password, path) {
@ -2443,4 +2437,6 @@
Util.Error("Server sent compress level pseudo-encoding");
}
};
})();
return { RFB: RFB };
});

View File

@ -1,34 +1,29 @@
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
/* jshint white: false, nonstandard: true */
/*global window, console, document, navigator, ActiveXObject, INCLUDE_URI */
"use strict";
define(function() {
var Util = {};
/*
* ------------------------------------------------------
* Namespaced in Util
* ------------------------------------------------------
*/
/*
* Logging/debug routines
*/
Util._log_level = 'warn';
var _log_level = 'warn';
Util.init_logging = function (level) {
if (typeof level === 'undefined') {
level = Util._log_level;
level = _log_level;
} else {
Util._log_level = level;
_log_level = level;
}
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
@ -52,7 +47,7 @@ Util.init_logging = function (level) {
}
};
Util.get_logging = function () {
return Util._log_level;
return _log_level;
};
// Initialize logging level
Util.init_logging();
@ -249,34 +244,33 @@ window.addEventListener('touchstart', function onFirstTouch() {
window.removeEventListener('touchstart', onFirstTouch, false);
}, false);
Util._cursor_uris_supported = null;
var _cursor_uris_supported = null;
Util.browserSupportsCursorURIs = function () {
if (Util._cursor_uris_supported === null) {
if (_cursor_uris_supported === null) {
try {
var target = document.createElement('canvas');
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
if (target.style.cursor) {
Util.Info("Data URI scheme cursor supported");
Util._cursor_uris_supported = true;
_cursor_uris_supported = true;
} else {
Util.Warn("Data URI scheme cursor not supported");
Util._cursor_uris_supported = false;
_cursor_uris_supported = false;
}
} catch (exc) {
Util.Error("Data URI scheme cursor test exception: " + exc);
Util._cursor_uris_supported = false;
_cursor_uris_supported = false;
}
}
return Util._cursor_uris_supported;
return _cursor_uris_supported;
};
// Set browser engine versions. Based on mootools.
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
(function () {
// 'presto': (function () { return (!window.opera) ? false : true; }()),
var detectPresto = function () {
return !!window.opera;
@ -343,7 +337,6 @@ Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !
// Extract actual webkit version if available
Util.Engine.webkit = detectActualWebkit(Util.Engine.webkit);
}
})();
Util.Flash = (function () {
var v, version;
@ -365,8 +358,37 @@ Util.Localisation = {
// Currently configured language
language: 'en',
// Configure suitable language based on user preferences
setup: function (supportedLanguages) {
// Translation data
_translations: null,
// Configure and load suitable language based on user preferences
setup: function (supportedLanguages, basedir, callback) {
Util.Localisation._setLanguageCode(supportedLanguages);
if (Util.Localisation.language === 'en') {
if (callback !== undefined) {
callback();
}
return;
}
if (basedir[basedir.length - 1] !== '/') {
basedir = basedir + '/';
}
require([basedir + Util.Localisation.language],
function(lang) {
Util.Localisation._translations = lang;
if (callback !== undefined) {
callback();
}
});
},
// Internal function to figure out the proper language code
_setLanguageCode: function (supportedLanguages) {
var userLanguages;
Util.Localisation.language = 'en'; // Default: US English
@ -429,11 +451,12 @@ Util.Localisation = {
// Retrieve localised text
get: function (id) {
if (typeof Language !== 'undefined' && Language[id]) {
return Language[id];
} else {
if ((Util.Localisation._translations === null) ||
(Util.Localisation._translations[id] === undefined)) {
return id;
}
return Util.Localisation._translations[id];
},
// Traverses the DOM and translates relevant fields
@ -498,7 +521,7 @@ Util.Localisation = {
}
for (var i = 0;i < elem.childNodes.length;i++) {
node = elem.childNodes[i];
var node = elem.childNodes[i];
if (node.nodeType === node.ELEMENT_NODE) {
process(node, enabled);
} else if (node.nodeType === node.TEXT_NODE && enabled) {
@ -511,4 +534,5 @@ Util.Localisation = {
},
};
/* [module] export default Util; */
return Util;
});

View File

@ -14,18 +14,14 @@
* read binary data off of the receive queue.
*/
/* [module]
* import Util from "./util";
* import Base64 from "./base64";
*/
/*jslint browser: true, bitwise: true */
/*global Util*/
"use strict";
/* [module] export default */ function Websock() {
define(["core/util"],
function (Util) {
function Websock() {
this._websocket = null; // WebSocket object
this._rQi = 0; // Receive queue index
@ -51,7 +47,6 @@
};
};
(function () {
// this has performance issues in some versions Chromium, and
// 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.
@ -423,4 +418,6 @@
}
}
};
})();
return { Websock: Websock };
});

View File

@ -1,5 +1,5 @@
Rebuilding inflator.js
- Download pako from npm
- Install browserify using npm
- browserify core/inflator.mod.js -o core/inflator.js -s Inflator
- Install requirejs using npm
- make -C inflator install

19
inflator/Makefile Normal file
View File

@ -0,0 +1,19 @@
.PHONY: all install clean
all: inflator-merged.js
RJS := r.js
inflator-merged.js: build.js inflator.js pako
r.js -o build.js
pako: ../node_modules/pako
$(RJS) -convert $< pako/
install: all
rm -f ../core/inflator.js
cp inflator-merged.js ../core/inflator.js
clean:
rm -f inflator.js
rm -rf pako

8
inflator/build.js Normal file
View File

@ -0,0 +1,8 @@
({
baseUrl: ".",
name: "core/inflator",
paths: {
"core": ".",
},
out: "inflator-merged.js"
})

52
inflator/inflator.js Normal file
View File

@ -0,0 +1,52 @@
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2017 Pierre Ossman for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
/*jslint browser: true, white: false */
"use strict";
define(["pako/lib/zlib/inflate.js", "pako/lib/zlib/zstream.js"],
function (zlib, ZStream) {
function Inflate() {
this.strm = new ZStream();
this.chunkSize = 1024 * 10 * 10;
this.strm.output = new Uint8Array(this.chunkSize);
this.windowBits = 5;
zlib.inflateInit(this.strm, this.windowBits);
};
Inflate.prototype = {
inflate: function (data, flush, expected) {
this.strm.input = data;
this.strm.avail_in = this.strm.input.length;
this.strm.next_in = 0;
this.strm.next_out = 0;
// resize our output buffer if it's too small
// (we could just use multiple chunks, but that would cause an extra
// allocation each time to flatten the chunks)
if (expected > this.chunkSize) {
this.chunkSize = expected;
this.strm.output = new Uint8Array(this.chunkSize);
}
this.strm.avail_out = this.chunkSize;
zlib.inflate(this.strm, flush);
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
},
reset: function () {
zlib.inflateReset(this.strm);
}
};
return { Inflate: Inflate };
});

View File

@ -108,34 +108,15 @@ module.exports = function(config) {
// list of files / patterns to load in the browser (loaded in order)
files: [
'node_modules/requirejs/require.js',
'tests/test-main.js',
'tests/fake.*.js',
'tests/assertions.js',
'core/util.js', // load first to avoid issues, since methods are called immediately
//'../core/*.js',
'core/base64.js',
'core/input/keysym.js',
'core/input/keysymdef.js',
'core/input/xtscancodes.js',
'core/input/util.js',
'core/input/devices.js',
'core/websock.js',
'core/rfb.js',
'core/des.js',
'core/display.js',
'core/inflator.js',
'tests/test.*.js'
],
client: {
mocha: {
'ui': 'bdd'
}
},
// list of files to exclude
exclude: [
'../tests/playback.js',
'../app/ui.js'
'tests/test.*.js',
// Only packaged, not included in browser as RequireJS will
// do the actual loading
{pattern: 'core/*.js', included: false},
{pattern: 'core/input/*.js', included: false},
],
customLaunchers: customLaunchers,

View File

@ -51,6 +51,7 @@
"open": "^0.0.5",
"phantomjs-prebuilt": "^2.1.13",
"po2json": "*",
"requirejs": "*",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
"spooky": "^0.2.5",

View File

@ -40,7 +40,10 @@ var output =
" * DO NOT EDIT!\n" +
" */\n" +
"\n" +
"Language = {\n";
"\"use strict\";\n" +
"\n" +
"define(function() {\n" +
"return {\n";
for (msgid in data) {
if (msgid === "")
@ -52,5 +55,6 @@ for (msgid in data) {
}
output += "};\n";
output += "});\n";
fs.writeFileSync(opt.argv[1], output);

View File

@ -99,6 +99,8 @@ if (program.autoInject) {
template.header += "\n" + template.script_tag(get_path('node_modules/mocha/mocha.js'));
template.header += "\n" + template.script_tag(get_path('node_modules/sinon/pkg/sinon.js'));
template.header += "\n" + template.script_tag(get_path('node_modules/sinon-chai/lib/sinon-chai.js'));
template.header += "\n" + template.script_tag(get_path('node_modules/requirejs/require.js'));
template.header += "\n<script>requirejs.config({ baseUrl: \"" + get_path('.') + "\" });</script>";
template.header += "\n<script>mocha.setup('bdd');</script>";

5
tests/test-main.js Normal file
View File

@ -0,0 +1,5 @@
requirejs.config({
// Karma serves files under /base
baseUrl: '/base'
});

View File

@ -1,10 +1,19 @@
// requires local modules: base64
var assert = chai.assert;
var expect = chai.expect;
describe('Base64 Tools', function() {
describe('Base64 Tools', function(done) {
"use strict";
var Base64;
before(function (done) {
requirejs(["core/base64"],
function (b) {
Base64 = b;
done();
});
});
var BIN_ARR = new Array(256);
for (var i = 0; i < 256; i++) {
BIN_ARR[i] = i;

View File

@ -1,9 +1,22 @@
// requires local modules: util, base64, display
// requires test modules: assertions
/* jshint expr: true */
var expect = chai.expect;
describe('Display/Canvas Helper', function () {
"use strict";
var Util, Base64, Display;
before(function (done) {
requirejs(["core/util", "core/base64", "core/display"],
function (u, b, d) {
Util = u;
Base64 = b;
Display = d.Display;
done();
});
});
var checked_data = [
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,

View File

@ -1,10 +1,20 @@
// requires local modules: input/keysym, input/keysymdef, input/util
var assert = chai.assert;
var expect = chai.expect;
describe('Helpers', function() {
"use strict";
var keysyms, KeyboardUtil;
before(function (done) {
requirejs(["core/input/keysymdef", "core/input/util"],
function (k, u) {
keysyms = k;
KeyboardUtil = u;
done();
});
});
describe('keysymFromKeyCode', function() {
it('should map known keycodes to keysyms', function() {
expect(KeyboardUtil.keysymFromKeyCode(0x41, false), 'a').to.be.equal(0x61);

View File

@ -1,10 +1,21 @@
// requires local modules: input/devices, input/util, input/keysymdef, input/keysym
var assert = chai.assert;
var expect = chai.expect;
/* jshint newcap: false, expr: true */
describe('Key Event Pipeline Stages', function() {
"use strict";
var keysyms, KeyboardUtil;
before(function (done) {
requirejs(["core/input/keysymdef", "core/input/util"],
function (k, u) {
keysyms = k;
KeyboardUtil = u;
done();
});
});
describe('Decode Keyboard Events', function() {
it('should pass events to the next stage', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {

View File

@ -1,9 +1,10 @@
// requires local modules: util, websock, rfb, input/util, input/keysym, input/keysymdef, input/devices, inflator, des, display
// requires test modules: fake.websocket, assertions
/* jshint expr: true */
var assert = chai.assert;
var expect = chai.expect;
var RFB;
function make_rfb (extra_opts) {
if (!extra_opts) {
extra_opts = {};
@ -34,9 +35,21 @@ var push32 = function (arr, num) {
describe('Remote Frame Buffer Protocol Client', function() {
"use strict";
before(FakeWebSocket.replace);
after(FakeWebSocket.restore);
var Websock;
before(function (done) {
requirejs(["core/rfb", "core/websock"],
function (r, w) {
RFB = r.RFB;
Websock = w.Websock;
done();
});
});
before(function () {
this.clock = sinon.useFakeTimers();
// Use a single set of buffers instead of reallocating to

View File

@ -1,4 +1,3 @@
// requires local modules: util
/* jshint expr: true */
var assert = chai.assert;
@ -7,6 +6,16 @@ var expect = chai.expect;
describe('Utils', function() {
"use strict";
var Util;
before(function (done) {
requirejs(["core/util"],
function (u) {
Util = u;
done();
});
});
describe('logging functions', function () {
beforeEach(function () {
sinon.spy(console, 'log');
@ -57,7 +66,7 @@ describe('Utils', function() {
});
describe('language selection', function () {
var origNavigator;
var origNavigator, origRequire;
beforeEach(function () {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
@ -77,8 +86,13 @@ describe('Utils', function() {
}
window.navigator.languages = [];
// Prevent the code from trying to actually load translations
origRequire = require;
require = function (mods, func) { func([]); };
});
afterEach(function () {
require = origRequire;
Object.defineProperty(window, "navigator", origNavigator);
});
@ -87,37 +101,37 @@ describe('Utils', function() {
});
it('should use English if no user language matches', function() {
window.navigator.languages = ["nl", "de"];
Util.Localisation.setup(["es", "fr"]);
Util.Localisation.setup(["es", "fr"], ".");
expect(Util.Localisation.language).to.equal('en');
});
it('should use the most preferred user language', function() {
window.navigator.languages = ["nl", "de", "fr"];
Util.Localisation.setup(["es", "fr", "de"]);
Util.Localisation.setup(["es", "fr", "de"], ".");
expect(Util.Localisation.language).to.equal('de');
});
it('should prefer sub-languages languages', function() {
window.navigator.languages = ["pt-BR"];
Util.Localisation.setup(["pt", "pt-BR"]);
Util.Localisation.setup(["pt", "pt-BR"], ".");
expect(Util.Localisation.language).to.equal('pt-BR');
});
it('should fall back to language "parents"', function() {
window.navigator.languages = ["pt-BR"];
Util.Localisation.setup(["fr", "pt", "de"]);
Util.Localisation.setup(["fr", "pt", "de"], ".");
expect(Util.Localisation.language).to.equal('pt');
});
it('should not use specific language when user asks for a generic language', function() {
window.navigator.languages = ["pt", "de"];
Util.Localisation.setup(["fr", "pt-BR", "de"]);
Util.Localisation.setup(["fr", "pt-BR", "de"], ".");
expect(Util.Localisation.language).to.equal('de');
});
it('should handle underscore as a separator', function() {
window.navigator.languages = ["pt-BR"];
Util.Localisation.setup(["pt_BR"]);
Util.Localisation.setup(["pt_BR"], ".");
expect(Util.Localisation.language).to.equal('pt_BR');
});
it('should handle difference in case', function() {
window.navigator.languages = ["pt-br"];
Util.Localisation.setup(["pt-BR"]);
Util.Localisation.setup(["pt-BR"], ".");
expect(Util.Localisation.language).to.equal('pt-BR');
});
});

View File

@ -1,4 +1,3 @@
// requires local modules: websock, util
// requires test modules: fake.websocket, assertions
/* jshint expr: true */
var assert = chai.assert;
@ -7,6 +6,16 @@ var expect = chai.expect;
describe('Websock', function() {
"use strict";
var Websock;
before(function (done) {
requirejs(["core/websock"],
function (w) {
Websock = w.Websock;
done();
});
});
describe('Queue methods', function () {
var sock;
var RQ_TEMPLATE = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);

View File

@ -80,12 +80,15 @@ var out = "// This file describes mappings from Unicode codepoints to the keysym
"// (and optionally, key names) expected by the RFB protocol\n" +
"// How this file was generated:\n" +
"// " + process.argv.join(" ") + "\n" +
"var keysyms = (function(){\n" +
"\n" +
"\"use strict\";\n" +
"\n" +
"define(function () {\n" +
" var keynames = {keysyms};\n" +
" var codepoints = {codepoints};\n" +
"\n" +
" function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }\n" +
"\n" +
" return {\n" +
" fromUnicode : function(u) {\n" +
" var keysym = codepoints[u];\n" +
@ -96,7 +99,7 @@ var out = "// This file describes mappings from Unicode codepoints to the keysym
" },\n" +
" lookup : lookup\n" +
" };\n" +
"})();\n";
"});\n";
out = out.replace('{keysyms}', use_keynames ? JSON.stringify(keysyms) : "null");
out = out.replace('{codepoints}', JSON.stringify(codepoints));

View File

@ -55,10 +55,7 @@
<!-- Stylesheets -->
<link rel="stylesheet" href="app/styles/base.css" />
<!--
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
-->
<script type='text/javascript' data-main='app/novnc.js' src='app/require.js'></script>
</head>
@ -314,12 +311,5 @@
<source src="app/sounds/bell.oga" type="audio/ogg">
<source src="app/sounds/bell.mp3" type="audio/mpeg">
</audio>
<!-- begin scripts -->
<script src="core/util.js"></script>
<script src="app/webutil.js"></script>
<script src="app/ui.js"></script>
<!-- end scripts -->
</body>
</html>

View File

@ -38,12 +38,7 @@
<!-- Stylesheets -->
<link rel="stylesheet" href="app/styles/auto.css">
<!--
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
-->
<script src="core/util.js"></script>
<script src="app/webutil.js"></script>
<script src="app/require.js"></script>
</head>
<body style="margin: 0px;">
@ -74,14 +69,10 @@
<script>
/*jslint white: false */
/*global window, $, Util, RFB, */
"use strict";
// Load supporting scripts
WebUtil.load_scripts({
'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js",
"input/xtscancodes.js", "input/util.js", "input/devices.js",
"display.js", "inflator.js", "rfb.js", "input/keysym.js"]});
require(["app/webutil", "core/rfb"],
function(WebUtil, rfbmod) {
var rfb;
var resizeTimeout;
@ -215,7 +206,6 @@
}
}
window.onscriptsload = function () {
var host, port, password, path, token;
document.getElementById('sendCtrlAltDelButton').style.display = "inline";
@ -261,7 +251,7 @@
}
try {
rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
rfb = new rfbmod.RFB({'target': document.getElementById('noVNC_canvas'),
'encrypt': WebUtil.getConfigVar('encrypt',
(window.location.protocol === "https:")),
'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
@ -282,7 +272,7 @@
}
rfb.connect(host, port, password, path);
};
});
</script>
</body>