scripts' initialization control.
- Initalize scripts in register order. - Fire a NoVnc.onload event when all scripts are loaded and initialized. - noVNC starts its service when catching a NoVnc.onload event.
This commit is contained in:
parent
8dfd916946
commit
d7dbc42372
|
|
@ -1 +1 @@
|
||||||
window.onload = UI.load;
|
NoVnc.onload = UI.load;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,12 @@
|
||||||
/*jslint evil: true */
|
/*jslint evil: true */
|
||||||
/*global window, document, INCLUDE_URI */
|
/*global window, document, INCLUDE_URI */
|
||||||
|
|
||||||
|
var NoVnc = {};
|
||||||
|
NoVnc.onload = null;
|
||||||
|
NoVnc.init_scripts = [];
|
||||||
|
NoVnc.loading = 0;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load supporting scripts
|
* Load supporting scripts
|
||||||
*/
|
*/
|
||||||
|
|
@ -21,11 +27,48 @@ function get_INCLUDE_URI() {
|
||||||
*/
|
*/
|
||||||
function load_scripts(base, files) {
|
function load_scripts(base, files) {
|
||||||
var head = document.getElementsByTagName('head')[0];
|
var head = document.getElementsByTagName('head')[0];
|
||||||
|
|
||||||
|
function onloadhook () {
|
||||||
|
if (this.initState) //Already initialized
|
||||||
|
return;
|
||||||
|
this.initState = true;
|
||||||
|
NoVnc.loading--;
|
||||||
|
initscripts();
|
||||||
|
if (NoVnc.loading === 0 && !!NoVnc.onload) {
|
||||||
|
NoVnc.onload();
|
||||||
|
NoVnc.onload = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function initscripts() {
|
||||||
|
// Call the initialization routines in register order when all
|
||||||
|
// the scripts have been loaded.
|
||||||
|
// Notice: These routines may also call load_scripts to start
|
||||||
|
// loading other scripts.
|
||||||
|
while (NoVnc.loading === 0 && NoVnc.init_scripts.length > 0) {
|
||||||
|
var script = NoVnc.init_scripts[0];
|
||||||
|
NoVnc.init_scripts.splice(0, 1);
|
||||||
|
// It is assumed that ABC.js should have _init_ABC() to
|
||||||
|
// initialize itself.
|
||||||
|
var f = script.src.split("/");
|
||||||
|
f = "_init_" + f[f.length -1].split(".")[0].replace(/[\-\+]/,"_");
|
||||||
|
eval("if (typeof " + f + " !== 'undefined') " + f + "()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var i=0; i<files.length; i++) {
|
for (var i=0; i<files.length; i++) {
|
||||||
var script = document.createElement('script');
|
var script = document.createElement('script');
|
||||||
script.type = 'text/javascript';
|
script.type = 'text/javascript';
|
||||||
|
NoVnc.loading++;
|
||||||
|
script.onload = onloadhook;
|
||||||
|
script.onreadystatechange = function () {
|
||||||
|
if (this.readyState == 'complete' || this.readyState == 'loaded')
|
||||||
|
this.onload();
|
||||||
|
}
|
||||||
|
script.initState = false;
|
||||||
script.src = base + files[i];
|
script.src = base + files[i];
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
|
NoVnc.init_scripts = NoVnc.init_scripts.concat([script]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// Reference: http://dev.w3.org/html5/websockets/
|
// Reference: http://dev.w3.org/html5/websockets/
|
||||||
// Reference: http://tools.ietf.org/html/rfc6455
|
// Reference: http://tools.ietf.org/html/rfc6455
|
||||||
|
|
||||||
(function() {
|
function _init_web_socket() {
|
||||||
|
|
||||||
if (window.WEB_SOCKET_FORCE_FLASH) {
|
if (window.WEB_SOCKET_FORCE_FLASH) {
|
||||||
// Keeps going.
|
// Keeps going.
|
||||||
|
|
@ -388,4 +388,4 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,34 +25,27 @@
|
||||||
// To enable WebSocket emulator debug:
|
// To enable WebSocket emulator debug:
|
||||||
//window.WEB_SOCKET_DEBUG=1;
|
//window.WEB_SOCKET_DEBUG=1;
|
||||||
|
|
||||||
if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
function _init_websock() {
|
||||||
|
if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||||
Websock_native = true;
|
Websock_native = true;
|
||||||
} else if (window.MozWebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
} else if (window.MozWebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||||
Websock_native = true;
|
Websock_native = true;
|
||||||
window.WebSocket = window.MozWebSocket;
|
window.WebSocket = window.MozWebSocket;
|
||||||
} else {
|
} else {
|
||||||
/* no builtin WebSocket so load web_socket.js */
|
/* no builtin WebSocket so load web_socket.js */
|
||||||
|
|
||||||
Websock_native = false;
|
Websock_native = false;
|
||||||
(function () {
|
(function () {
|
||||||
function get_INCLUDE_URI() {
|
|
||||||
return (typeof INCLUDE_URI !== "undefined") ?
|
|
||||||
INCLUDE_URI : "include/";
|
|
||||||
}
|
|
||||||
|
|
||||||
var start = "<script src='" + get_INCLUDE_URI(),
|
|
||||||
end = "'><\/script>", extra = "";
|
|
||||||
|
|
||||||
window.WEB_SOCKET_SWF_LOCATION = get_INCLUDE_URI() +
|
window.WEB_SOCKET_SWF_LOCATION = get_INCLUDE_URI() +
|
||||||
"web-socket-js/WebSocketMain.swf";
|
"web-socket-js/WebSocketMain.swf";
|
||||||
if (Util.Engine.trident) {
|
if (Util.Engine.trident) {
|
||||||
Util.Debug("Forcing uncached load of WebSocketMain.swf");
|
Util.Debug("Forcing uncached load of WebSocketMain.swf");
|
||||||
window.WEB_SOCKET_SWF_LOCATION += "?" + Math.random();
|
window.WEB_SOCKET_SWF_LOCATION += "?" + Math.random();
|
||||||
}
|
}
|
||||||
extra += start + "web-socket-js/swfobject.js" + end;
|
load_scripts(get_INCLUDE_URI() + "web-socket-js/",
|
||||||
extra += start + "web-socket-js/web_socket.js" + end;
|
["swfobject.js", "web_socket.js"]);
|
||||||
document.write(extra);
|
|
||||||
}());
|
}());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function () {
|
NoVnc.onload = function () {
|
||||||
var host, port, password, path, token;
|
var host, port, password, path, token;
|
||||||
|
|
||||||
$D('sendCtrlAltDelButton').style.display = "inline";
|
$D('sendCtrlAltDelButton').style.display = "inline";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue