1
0
mirror of https://github.com/fcwu/docker-ubuntu-vnc-desktop synced 2026-08-05 16:12:41 +02:00

feat: upgrade noVNC

This commit is contained in:
Doro Wu
2017-02-25 12:55:24 +08:00
parent 394c340688
commit 0c04c5ec3b
489 changed files with 18241 additions and 54521 deletions
+124 -344
View File
@@ -11,6 +11,8 @@
Connect parameters are provided in query string:
http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
or the fragment:
http://example.com/#host=HOST&port=PORT&encrypt=1&true_color=1
-->
<title>noVNC</title>
@@ -25,28 +27,28 @@
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<!-- App Start Icon -->
<link rel="apple-touch-startup-image" href="images/screen_320x460.png" />
<link rel="apple-touch-startup-image" href="app/images/screen_320x460.png" />
<!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
<link rel="apple-touch-icon" href="images/screen_57x57.png">
<link rel="apple-touch-icon" href="app/images/screen_57x57.png">
<!--
<link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
<link rel="apple-touch-icon-precomposed" href="app/images/screen_57x57.png" />
-->
<!-- Stylesheets -->
<link rel="stylesheet" href="include/base.css" title="plain">
<link rel="stylesheet" href="custom.css" title="plain">
<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="include/util.js"></script>
<script src="core/util.js"></script>
<script src="app/webutil.js"></script>
</head>
<body style="margin: 0px;">
<div id="noVNC_screen">
<div id="noVNC_status_bar" class="noVNC_status_bar" style="display: none;margin-top: 0px; height: 0px;">
<div id="noVNC_container">
<div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;">
<table border=0 width="100%"><tr>
<td><div id="noVNC_status" style="position: relative; height: auto;">
Loading
@@ -68,269 +70,58 @@
<canvas id="noVNC_canvas" width="640px" height="20px">
Canvas not supported.
</canvas>
<div id="custom_toolbar" class="custom_toolbar">
<div id="custom_toolbar_clicker" class="custom_toolbar_clicker"></div>
<div class="custom_toolbar_divider1"></div>
<div id="custom_toolbar_autoconnect_btn" class="custom_toolbar_btn"></div>
<div class="custom_toolbar_divider1"></div>
<div id="custom_toolbar_autoscale_btn" class="custom_toolbar_btn"></div>
<div class="custom_toolbar_divider1"></div>
<div id="custom_toolbar_quality_1_btn" class="custom_toolbar_btn"><div class="custom_quality_icon">L</div></div>
<div class="custom_toolbar_divider2"></div>
<div id="custom_toolbar_quality_2_btn" class="custom_toolbar_btn"><div class="custom_quality_icon">M</div></div>
<div class="custom_toolbar_divider2"></div>
<div id="custom_toolbar_quality_3_btn" class="custom_toolbar_btn"><div class="custom_quality_icon">H</div></div>
<div class="custom_toolbar_divider1"></div>
</div>
<div id="custom_mask" class="custom_mask"></div>
</div>
</body>
<script src="media/js/jquery.js"></script>
<script>
<script>
/*jslint white: false */
/*global window, $, Util, RFB, */
"use strict";
// Load supporting scripts
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
"keysymdef.js", "keyboard.js", "input.js", "display.js",
"jsunzip.js", "rfb.js", "keysym.js"]);
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"]});
var rfb;
var resizeTimeout;
var desktopName;
// Custom noVNC share varaibles.
var Scale = {x: 1.0, y: 1.0}; // share with "./include/util.js".
var jpeg_quality = 4; // Share with "./include.rfb.js".
// Custom noVNC query parameters.
var autoconnect = 1;
var autoscale = 0;
var quality = 2;
var enablelog = 0;
// Custom toolbar click events.
$("#custom_toolbar_clicker").click(function(){
if (!$("#custom_toolbar").is(':animated')) {
if ($("#custom_toolbar" ).position().left < -10) {
$("#custom_toolbar" ).animate({ left: "+=65", }, 500, function() {
$("#custom_toolbar_clicker").css({"background-image": "url(images/pop_less.png)"});
});
}
else {
$("#custom_toolbar" ).animate({ left: "-=65", }, 500, function () {
$("#custom_toolbar_clicker").css({"background-image": "url(images/pop_more.png)"});
});
}
}
});
$("#custom_toolbar_autoconnect_btn").click(function(){
autoconnect = (autoconnect == 1) ? 0 : 1;
window.location = render_redirect_url();
});
$("#custom_toolbar_autoscale_btn").click(function(){
autoscale = (autoscale == 1) ? 0 : 1;
window.location = render_redirect_url();
});
$("#custom_toolbar_quality_1_btn").click(function(){
// low jpeg
quality = 1;
window.location = render_redirect_url();
});
$("#custom_toolbar_quality_2_btn").click(function(){
// mid jpeg
quality = 2;
window.location = render_redirect_url();
});
$("#custom_toolbar_quality_3_btn").click(function(){
// high jpeg
quality = 3;
window.location = render_redirect_url();
});
$(".custom_toolbar_btn").hover(
function() {
if (!$(this).hasClass("custom_toolbar_btn_hover_selected"))
$(this).addClass("custom_toolbar_btn_hover");
}, function() {
$(this).removeClass("custom_toolbar_btn_hover");
}
);
// Custom functions
function mask_fadein () {
var width = window.innerWidth;
var height = window.innerHeight;
$("#custom_mask").css({"width": width.toString() + "px", "height": height.toString() + "px"});
$("#custom_mask").fadeIn();
}
function mask_fadeout () {
$("#custom_mask").fadeOut();
}
function render_redirect_url() {
var new_url = (window.location.href).toString().split("?")[0] + "?";
// noVNC orign query parameter
if (WebUtil.getQueryVar('resize', false)) {
new_url += "resize=" + WebUtil.getQueryVar('resize', "") + "&";
}
if (WebUtil.getQueryVar('logging', false)) {
new_url += "logging=" + WebUtil.getQueryVar('logging', "") + "&";
}
if (WebUtil.getQueryVar('title', false)) {
new_url += "title=" + WebUtil.getQueryVar('title', "") + "&";
}
if (WebUtil.getQueryVar('host', false)) {
new_url += "host=" + WebUtil.getQueryVar('host', "") + "&";
}
if (WebUtil.getQueryVar('port', false)) {
new_url += "port=" + WebUtil.getQueryVar('port', "") + "&";
}
if (WebUtil.getQueryVar('token', false)) {
new_url += "token=" + WebUtil.getQueryVar('token', "") + "&";
}
if (WebUtil.getQueryVar('password', false)) {
new_url += "password=" + WebUtil.getQueryVar('password', "") + "&";
}
if (WebUtil.getQueryVar('path', false)) {
new_url += "path=" + WebUtil.getQueryVar('path', "") + "&";
}
if (WebUtil.getQueryVar('encrypt', false)) {
new_url += "encrypt=" + WebUtil.getQueryVar('encrypt', "") + "&";
}
if (WebUtil.getQueryVar('repeaterID', false)) {
new_url += "repeaterID=" + WebUtil.getQueryVar('repeaterID', "") + "&";
}
if (WebUtil.getQueryVar('true_color', false)) {
new_url += "true_color=" + WebUtil.getQueryVar('true_color', "") + "&";
}
if (WebUtil.getQueryVar('cursor', false)) {
new_url += "cursor=" + WebUtil.getQueryVar('cursor', "") + "&";
}
if (WebUtil.getQueryVar('shared', false)) {
new_url += "shared=" + WebUtil.getQueryVar('shared', "") + "&";
}
if (WebUtil.getQueryVar('view_only', false)) {
new_url += "view_only=" + WebUtil.getQueryVar('view_only', "") + "&";
}
// custom query parameter
new_url += "autoconnect=" + autoconnect + "&";
new_url += "autoscale=" + autoscale + "&";
new_url += "quality=" + quality + "&";
if (WebUtil.getQueryVar('enablelog', false)) {
new_url += "enablelog=" + WebUtil.getQueryVar('enablelog', "") + "&";
}
return new_url;
}
function render_custom_toolbar() {
$("#custom_toolbar_autoconnect_btn").removeClass("custom_pause_icon");
$("#custom_toolbar_autoconnect_btn").removeClass("custom_resume_icon");
if (autoconnect == 1){
$("#custom_toolbar_autoconnect_btn").addClass("custom_pause_icon");
}
else {
$("#custom_toolbar_autoconnect_btn").addClass("custom_resume_icon");
}
$("#custom_toolbar_autoscale_btn").removeClass("custom_scale_icon");
$("#custom_toolbar_autoscale_btn").removeClass("custom_not_scale_icon");
if (autoscale == 1)
$("#custom_toolbar_autoscale_btn").addClass("custom_not_scale_icon");
else
$("#custom_toolbar_autoscale_btn").addClass("custom_scale_icon");
$("#custom_toolbar_quality_1_btn").removeClass("custom_toolbar_btn_selected");
$("#custom_toolbar_quality_2_btn").removeClass("custom_toolbar_btn_selected");
$("#custom_toolbar_quality_3_btn").removeClass("custom_toolbar_btn_selected");
if (quality == 1)
$("#custom_toolbar_quality_1_btn").addClass("custom_toolbar_btn_selected");
if (quality == 2)
$("#custom_toolbar_quality_2_btn").addClass("custom_toolbar_btn_selected");
if (quality == 3)
$("#custom_toolbar_quality_3_btn").addClass("custom_toolbar_btn_selected");
if (enablelog == 1) {
console.log("------------- Custom Toolbar Settings -------------");
console.log("autoconnect: " + autoconnect);
console.log("autoscale: " + autoscale);
console.log("quality: " + quality);
console.log("enablelog: " + enablelog);
}
}
function noVNC_autoscale() {
var scaleWidth = window.innerWidth;
var scaleHeight = window.innerHeight;
var originWidth = $("#noVNC_canvas").attr("width");
var originHeight = $("#noVNC_canvas").attr("height");
$("#noVNC_canvas").css({"width": scaleWidth.toString() + "px", "height": scaleHeight.toString() + "px"})
Scale.x = scaleWidth / originWidth;
Scale.y = scaleHeight / originHeight;
if (enablelog == 1) {
console.info("-------------- Resize Canvas --------------");
console.log("Origin Width: " + originWidth);
console.log("Origin Height: " + originHeight);
console.log("Scale Width: " + scaleWidth);
console.log("Scale Height: " + scaleHeight);
console.log("Scale.x: " + Scale.x);
console.log("Scale.y: " + Scale.y);
}
}
function UIresize() {
// Enable autoscale if set 1.
if (autoscale == 1) {
noVNC_autoscale();
}
if (WebUtil.getQueryVar('resize', false)) {
if (WebUtil.getConfigVar('resize', false)) {
var innerW = window.innerWidth;
var innerH = window.innerHeight;
var controlbarH = $D('noVNC_status_bar').offsetHeight;
var padding = 5;
var controlbarH = document.getElementById('noVNC_status_bar').offsetHeight;
if (innerW !== undefined && innerH !== undefined)
rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
rfb.requestDesktopSize(innerW, innerH - controlbarH);
}
}
function FBUComplete(rfb, fbu) {
UIresize();
rfb.set_onFBUComplete(function() { });
}
function passwordRequired(rfb) {
var msg;
msg = '<form onsubmit="return setPassword();"';
msg += ' style="margin-bottom: 0px">';
msg += 'Password Required: ';
msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
msg += '<\/form>';
$D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
$D('noVNC_status').innerHTML = msg;
function updateDesktopName(rfb, name) {
desktopName = name;
}
function passwordRequired(rfb, msg) {
if (typeof msg === 'undefined') {
msg = 'Password Required: ';
}
var html;
html = '<form onsubmit="return setPassword();"';
html += ' style="margin-bottom: 0px">';
html += '<label></label>'
html += '<input type=password size=10 id="password_input" class="noVNC_status">';
html += '<\/form>';
// bypass status() because it sets text content
document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
document.getElementById('noVNC_status').innerHTML = html;
document.getElementById('noVNC_status').querySelector('label').textContent = msg;
}
function setPassword() {
rfb.sendPassword($D('password_input').value);
rfb.sendPassword(document.getElementById('password_input').value);
return false;
}
function sendCtrlAltDel() {
@@ -349,58 +140,95 @@
rfb.xvpReset();
return false;
}
function updateState(rfb, state, oldstate, msg) {
var s, sb, cad, level;
s = $D('noVNC_status');
sb = $D('noVNC_status_bar');
cad = $D('sendCtrlAltDelButton');
function status(text, level) {
switch (level) {
case 'normal':
case 'warn':
case 'error':
break;
default:
level = "warn";
}
document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_" + level);
document.getElementById('noVNC_status').textContent = text;
}
function updateState(rfb, state, oldstate) {
var cad = document.getElementById('sendCtrlAltDelButton');
switch (state) {
case 'failed': level = "error"; break;
case 'fatal': level = "error"; break;
case 'normal': level = "normal"; break;
case 'disconnected': level = "normal"; break;
case 'loaded': level = "normal"; break;
default: level = "warn"; break;
case 'connecting':
status("Connecting", "normal");
break;
case 'connected':
if (rfb && rfb.get_encrypt()) {
status("Connected (encrypted) to " +
desktopName, "normal");
} else {
status("Connected (unencrypted) to " +
desktopName, "normal");
}
break;
case 'disconnecting':
status("Disconnecting", "normal");
break;
case 'disconnected':
status("Disconnected", "normal");
break;
default:
status(state, "warn");
break;
}
if (state === "normal") {
if (state === 'connected') {
cad.disabled = false;
} else {
cad.disabled = true;
xvpInit(0);
}
if (typeof(msg) !== 'undefined') {
sb.setAttribute("class", "noVNC_status_" + level);
s.innerHTML = msg;
}
function disconnected(rfb, reason) {
if (typeof(reason) !== 'undefined') {
status(reason, "error");
}
}
function notification(rfb, msg, level, options) {
status(msg, level);
}
window.onresize = function () {
// When the window has been resized, wait until the size remains
// the same for 0.5 seconds before sending the request for changing
// the resolution of the session
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function(){
UIresize();
}, 500);
};
function xvpInit(ver) {
var xvpbuttons;
xvpbuttons = $D('noVNC_xvp_buttons');
xvpbuttons = document.getElementById('noVNC_xvp_buttons');
if (ver >= 1) {
xvpbuttons.style.display = 'inline';
} else {
xvpbuttons.style.display = 'none';
}
}
function connect_vnc() {
window.onscriptsload = function () {
var host, port, password, path, token;
$D('sendCtrlAltDelButton').style.display = "inline";
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
$D('xvpShutdownButton').onclick = xvpShutdown;
$D('xvpRebootButton').onclick = xvpReboot;
$D('xvpResetButton').onclick = xvpReset;
document.getElementById('sendCtrlAltDelButton').style.display = "inline";
document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
document.getElementById('xvpShutdownButton').onclick = xvpShutdown;
document.getElementById('xvpRebootButton').onclick = xvpReboot;
document.getElementById('xvpResetButton').onclick = xvpReset;
WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
document.title = unescape(WebUtil.getConfigVar('title', 'noVNC'));
// By default, use the host and port of server that served this file
host = WebUtil.getQueryVar('host', window.location.hostname);
port = WebUtil.getQueryVar('port', window.location.port);
host = WebUtil.getConfigVar('host', window.location.hostname);
port = WebUtil.getConfigVar('port', window.location.port);
// if port == 80 (or 443) then it won't be present and should be
// set manually
@@ -413,97 +241,49 @@
}
}
password = WebUtil.getConfigVar('password', '');
path = WebUtil.getConfigVar('path', 'websockify');
// If a token variable is passed in, set the parameter in a cookie.
// This is used by nova-novncproxy.
token = WebUtil.getQueryVar('token', null);
token = WebUtil.getConfigVar('token', null);
if (token) {
// if token is already present in the path we should use it
path = WebUtil.injectParamIfMissing(path, "token", token);
WebUtil.createCookie('token', token, 1)
}
password = WebUtil.getQueryVar('password', '');
path = WebUtil.getQueryVar('path', 'websockify');
if ((!host) || (!port)) {
updateState('failed',
"Must specify host and port in URL");
status('Must specify host and port in URL', 'error');
return;
}
try {
rfb = new RFB({'target': $D('noVNC_canvas'),
'encrypt': WebUtil.getQueryVar('encrypt',
rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
'encrypt': WebUtil.getConfigVar('encrypt',
(window.location.protocol === "https:")),
'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
'true_color': WebUtil.getQueryVar('true_color', true),
'local_cursor': WebUtil.getQueryVar('cursor', true),
'shared': WebUtil.getQueryVar('shared', true),
'view_only': WebUtil.getQueryVar('view_only', false),
'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
'true_color': WebUtil.getConfigVar('true_color', true),
'local_cursor': WebUtil.getConfigVar('cursor', true),
'shared': WebUtil.getConfigVar('shared', true),
'view_only': WebUtil.getConfigVar('view_only', false),
'onNotification': notification,
'onUpdateState': updateState,
'onDisconnected': disconnected,
'onXvpInit': xvpInit,
'onPasswordRequired': passwordRequired,
'onFBUComplete': FBUComplete});
'onFBUComplete': FBUComplete,
'onDesktopName': updateDesktopName});
} catch (exc) {
UI.updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
status('Unable to create RFB client -- ' + exc, 'error');
return; // don't continue trying to connect
}
if (enablelog == 1) {
console.log('------------- noVnc Connect info -------------');
console.log('Host: ' + (host).toString());
console.log('Port: ' + (port).toString());
console.log('Password: ' + (password).toString());
console.log('Path: ' + (path).toString());
console.log('Url: ' + (window.location.href).toString());
}
// Connect
rfb.connect(host, port, password, path);
if (enablelog == 1) {
console.log('------------- noVnc RFB Stats -------------');
rfb._print_stats();
}
if (enablelog == 1) {
console.log('------------- noVnc RFB Encoding -------------');
console.log(rfb._encodings);
}
}
// Window events
window.onresize = function () {
// When the window has been resized, wait until the size remains
// the same for 0.5 seconds before sending the request for changing
// the resolution of the session
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function(){
UIresize();
}, 100);
};
</script>
window.onload = function () {
autoconnect = WebUtil.getQueryVar('autoconnect', 0);
autoscale = WebUtil.getQueryVar('autoscale', 0);
quality = WebUtil.getQueryVar('quality', 2);
enablelog = WebUtil.getQueryVar('enablelog', 0);
// Change quality will set image level to different level (0 ~ 9)
if (quality == 1)
jpeg_quality = 0;
if (quality == 2)
jpeg_quality = 4;
if (quality == 3)
jpeg_quality = 9;
// Render the toolbar when loaded.
render_custom_toolbar();
// Connect to VNC.
if (autoconnect == 1)
connect_vnc();
}
</script>
</body>
</html>