This commit is contained in:
Pierre Ossman
2017-11-10 14:19:05 +01:00
19 changed files with 1675 additions and 1871 deletions
+5 -5
View File
@@ -591,17 +591,17 @@ select:active {
padding: 0 10px;
}
/* XVP Shutdown/Reboot */
:root:not(.noVNC_connected) #noVNC_xvp_button {
/* Shutdown/Reboot */
:root:not(.noVNC_connected) #noVNC_power_button {
display: none;
}
#noVNC_xvp {
#noVNC_power {
}
#noVNC_xvp_buttons {
#noVNC_power_buttons {
display: none;
}
#noVNC_xvp input[type=button] {
#noVNC_power input[type=button] {
width: 100%;
}
+110 -142
View File
@@ -13,7 +13,7 @@
import * as Log from '../core/util/logging.js';
import _, { l10n } from '../core/util/localization.js';
import { isTouchDevice, browserSupportsCursorURIs as cursorURIsSupported } from '../core/util/browsers.js';
import { isTouchDevice } from '../core/util/browsers.js';
import { setCapture, getPointerEvent } from '../core/util/events.js';
import KeyTable from "../core/input/keysym.js";
import keysyms from "../core/input/keysymdef.js";
@@ -91,7 +91,7 @@ var UI = {
UI.addControlbarHandlers();
UI.addTouchSpecificHandlers();
UI.addExtraKeysHandlers();
UI.addXvpHandlers();
UI.addMachineHandlers();
UI.addConnectionControlHandlers();
UI.addClipboardHandlers();
UI.addSettingsHandlers();
@@ -167,7 +167,6 @@ var UI = {
UI.initSetting('host', window.location.hostname);
UI.initSetting('port', port);
UI.initSetting('encrypt', (window.location.protocol === "https:"));
UI.initSetting('cursor', !isTouchDevice);
UI.initSetting('view_clip', false);
UI.initSetting('resize', 'off');
UI.initSetting('shared', true);
@@ -200,28 +199,6 @@ var UI = {
}
},
initRFB: function() {
try {
UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
'onNotification': UI.notification,
'onUpdateState': UI.updateState,
'onDisconnected': UI.disconnectFinished,
'onPasswordRequired': UI.passwordRequired,
'onXvpInit': UI.updateXvpButton,
'onClipboard': UI.clipboardReceive,
'onBell': UI.bell,
'onFBUComplete': UI.initialResize,
'onFBResize': UI.updateSessionSize,
'onDesktopName': UI.updateDesktopName});
return true;
} catch (exc) {
var msg = "Unable to create RFB client -- " + exc;
Log.Error(msg);
UI.showStatus(msg, 'error');
return false;
}
},
/* ------^-------
* /INIT
* ==============
@@ -278,8 +255,8 @@ var UI = {
document.getElementById("noVNC_keyboard_button")
.addEventListener('click', UI.toggleVirtualKeyboard);
UI.touchKeyboard = new Keyboard({target: document.getElementById('noVNC_keyboardinput'),
onKeyEvent: UI.keyEvent});
UI.touchKeyboard = new Keyboard(document.getElementById('noVNC_keyboardinput'));
UI.touchKeyboard.onkeyevent = UI.keyEvent;
UI.touchKeyboard.grab();
document.getElementById("noVNC_keyboardinput")
.addEventListener('input', UI.keyInput);
@@ -330,15 +307,15 @@ var UI = {
.addEventListener('click', UI.sendCtrlAltDel);
},
addXvpHandlers: function() {
document.getElementById("noVNC_xvp_shutdown_button")
.addEventListener('click', function() { UI.rfb.xvpShutdown(); });
document.getElementById("noVNC_xvp_reboot_button")
.addEventListener('click', function() { UI.rfb.xvpReboot(); });
document.getElementById("noVNC_xvp_reset_button")
.addEventListener('click', function() { UI.rfb.xvpReset(); });
document.getElementById("noVNC_xvp_button")
.addEventListener('click', UI.toggleXvpPanel);
addMachineHandlers: function() {
document.getElementById("noVNC_shutdown_button")
.addEventListener('click', function() { UI.rfb.machineShutdown(); });
document.getElementById("noVNC_reboot_button")
.addEventListener('click', function() { UI.rfb.machineReboot(); });
document.getElementById("noVNC_reset_button")
.addEventListener('click', function() { UI.rfb.machineReset(); });
document.getElementById("noVNC_power_button")
.addEventListener('click', UI.togglePowerPanel);
},
addConnectionControlHandlers: function() {
@@ -377,8 +354,6 @@ var UI = {
.addEventListener('click', UI.toggleSettingsPanel);
UI.addSettingChangeHandler('encrypt');
UI.addSettingChangeHandler('cursor');
UI.addSettingChangeHandler('cursor', UI.updateLocalCursor);
UI.addSettingChangeHandler('resize');
UI.addSettingChangeHandler('resize', UI.enableDisableViewClip);
UI.addSettingChangeHandler('resize', UI.applyResizeMode);
@@ -413,7 +388,7 @@ var UI = {
* VISUAL
* ------v------*/
updateState: function(rfb, state, oldstate) {
updateState: function(event) {
var msg;
document.documentElement.classList.remove("noVNC_connecting");
@@ -421,7 +396,7 @@ var UI = {
document.documentElement.classList.remove("noVNC_disconnecting");
document.documentElement.classList.remove("noVNC_reconnecting");
switch (state) {
switch (event.detail.state) {
case 'connecting':
document.getElementById("noVNC_transition_text").textContent = _("Connecting...");
document.documentElement.classList.add("noVNC_connecting");
@@ -429,8 +404,9 @@ var UI = {
case 'connected':
UI.connected = true;
UI.inhibit_reconnect = false;
UI.doneInitialResize = false;
document.documentElement.classList.add("noVNC_connected");
if (rfb && rfb.get_encrypt()) {
if (UI.getSetting('encrypt')) {
msg = _("Connected (encrypted) to ") + UI.desktopName;
} else {
msg = _("Connected (unencrypted) to ") + UI.desktopName;
@@ -462,12 +438,6 @@ var UI = {
UI.enableDisableViewClip();
if (cursorURIsSupported() && !isTouchDevice) {
UI.enableSetting('cursor');
} else {
UI.disableSetting('cursor');
}
if (UI.connected) {
UI.disableSetting('encrypt');
UI.disableSetting('shared');
@@ -487,12 +457,12 @@ var UI = {
UI.enableSetting('port');
UI.enableSetting('path');
UI.enableSetting('repeaterID');
UI.updateXvpButton(0);
UI.updatePowerButton();
UI.keepControlbar();
}
// Hide input related buttons in view only mode
if (UI.rfb && UI.rfb.get_view_only()) {
if (UI.rfb && UI.rfb.viewOnly) {
document.getElementById('noVNC_keyboard_button')
.classList.add('noVNC_hidden');
document.getElementById('noVNC_toggle_extra_keys_button')
@@ -562,8 +532,8 @@ var UI = {
document.getElementById('noVNC_status').classList.remove("noVNC_open");
},
notification: function (rfb, msg, level, options) {
UI.showStatus(msg, level);
notification: function (e) {
UI.showStatus(e.detail.message, e.detail.level);
},
activateControlbar: function(event) {
@@ -866,7 +836,7 @@ var UI = {
closeAllPanels: function() {
UI.closeSettingsPanel();
UI.closeXvpPanel();
UI.closePowerPanel();
UI.closeClipboardPanel();
UI.closeExtraKeys();
},
@@ -883,12 +853,6 @@ var UI = {
// Refresh UI elements from saved cookies
UI.updateSetting('encrypt');
if (cursorURIsSupported()) {
UI.updateSetting('cursor');
} else {
UI.updateSetting('cursor', !isTouchDevice);
UI.disableSetting('cursor');
}
UI.updateSetting('view_clip');
UI.updateSetting('resize');
UI.updateSetting('shared');
@@ -924,50 +888,52 @@ var UI = {
/* ------^-------
* /SETTINGS
* ==============
* XVP
* POWER
* ------v------*/
openXvpPanel: function() {
openPowerPanel: function() {
UI.closeAllPanels();
UI.openControlbar();
document.getElementById('noVNC_xvp')
document.getElementById('noVNC_power')
.classList.add("noVNC_open");
document.getElementById('noVNC_xvp_button')
document.getElementById('noVNC_power_button')
.classList.add("noVNC_selected");
},
closeXvpPanel: function() {
document.getElementById('noVNC_xvp')
closePowerPanel: function() {
document.getElementById('noVNC_power')
.classList.remove("noVNC_open");
document.getElementById('noVNC_xvp_button')
document.getElementById('noVNC_power_button')
.classList.remove("noVNC_selected");
},
toggleXvpPanel: function() {
if (document.getElementById('noVNC_xvp')
togglePowerPanel: function() {
if (document.getElementById('noVNC_power')
.classList.contains("noVNC_open")) {
UI.closeXvpPanel();
UI.closePowerPanel();
} else {
UI.openXvpPanel();
UI.openPowerPanel();
}
},
// Disable/enable XVP button
updateXvpButton: function(ver) {
if (ver >= 1 && !UI.rfb.get_view_only()) {
document.getElementById('noVNC_xvp_button')
// Disable/enable power button
updatePowerButton: function() {
if (UI.connected &&
UI.rfb.capabilities.power &&
!UI.rfb.viewOnly) {
document.getElementById('noVNC_power_button')
.classList.remove("noVNC_hidden");
} else {
document.getElementById('noVNC_xvp_button')
document.getElementById('noVNC_power_button')
.classList.add("noVNC_hidden");
// Close XVP panel if open
UI.closeXvpPanel();
// Close power panel if open
UI.closePowerPanel();
}
},
/* ------^-------
* /XVP
* /POWER
* ==============
* CLIPBOARD
* ------v------*/
@@ -998,9 +964,9 @@ var UI = {
}
},
clipboardReceive: function(rfb, text) {
Log.Debug(">> UI.clipboardReceive: " + text.substr(0,40) + "...");
document.getElementById('noVNC_clipboard_text').value = text;
clipboardReceive: function(e) {
Log.Debug(">> UI.clipboardReceive: " + e.detail.text.substr(0,40) + "...");
document.getElementById('noVNC_clipboard_text').value = e.detail.text;
Log.Debug("<< UI.clipboardReceive");
},
@@ -1053,19 +1019,34 @@ var UI = {
return;
}
if (!UI.initRFB()) return;
UI.closeAllPanels();
UI.closeConnectPanel();
UI.rfb.set_encrypt(UI.getSetting('encrypt'));
UI.rfb.set_shared(UI.getSetting('shared'));
UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
UI.updateLocalCursor();
UI.updateViewOnly();
UI.rfb.connect(host, port, password, path);
var url;
url = UI.getSetting('encrypt') ? 'wss' : 'ws';
url += '://' + host;
if(port) {
url += ':' + port;
}
url += '/' + path;
UI.rfb = new RFB(document.getElementById('noVNC_canvas'), url,
{ shared: UI.getSetting('shared'),
repeaterID: UI.getSetting('repeaterID'),
credentials: { password: password } });
UI.rfb.addEventListener("notification", UI.notification);
UI.rfb.addEventListener("updatestate", UI.updateState);
UI.rfb.addEventListener("disconnect", UI.disconnectFinished);
UI.rfb.addEventListener("credentialsrequired", UI.credentials);
UI.rfb.addEventListener("capabilities", function () { UI.updatePowerButton(); UI.initialResize(); });
UI.rfb.addEventListener("clipboard", UI.clipboardReceive);
UI.rfb.addEventListener("bell", UI.bell);
UI.rfb.addEventListener("fbresize", UI.updateSessionSize);
UI.rfb.addEventListener("desktopname", UI.updateDesktopName);
},
disconnect: function() {
@@ -1075,9 +1056,6 @@ var UI = {
// Disable automatic reconnecting
UI.inhibit_reconnect = true;
// Restore the callback used for initial resize
UI.rfb.set_onFBUComplete(UI.initialResize);
// Don't display the connection settings until we're actually disconnected
},
@@ -1092,9 +1070,9 @@ var UI = {
UI.connect(null, UI.reconnect_password);
},
disconnectFinished: function (rfb, reason) {
if (typeof reason !== 'undefined') {
UI.showStatus(reason, 'error');
disconnectFinished: function (e) {
if (typeof e.detail.reason !== 'undefined') {
UI.showStatus(e.detail.reason, 'error');
} else if (UI.getSetting('reconnect', false) === true && !UI.inhibit_reconnect) {
document.getElementById("noVNC_transition_text").textContent = _("Reconnecting...");
document.documentElement.classList.add("noVNC_reconnecting");
@@ -1125,8 +1103,8 @@ var UI = {
* PASSWORD
* ------v------*/
passwordRequired: function(rfb, msg) {
credentials: function(e) {
// FIXME: handle more types
document.getElementById('noVNC_password_dlg')
.classList.add('noVNC_open');
@@ -1134,24 +1112,23 @@ var UI = {
document.getElementById('noVNC_password_input').focus();
}, 100);
if (typeof msg === 'undefined') {
msg = _("Password is required");
}
var msg = _("Password is required");
Log.Warn(msg);
UI.showStatus(msg, "warning");
},
setPassword: function(e) {
// Prevent actually submitting the form
e.preventDefault();
var inputElem = document.getElementById('noVNC_password_input');
var password = inputElem.value;
// Clear the input after reading the password
inputElem.value = "";
UI.rfb.sendPassword(password);
UI.rfb.sendCredentials({ password: password });
UI.reconnect_password = password;
document.getElementById('noVNC_password_dlg')
.classList.remove('noVNC_open');
// Prevent actually submitting the form
e.preventDefault();
},
/* ------^-------
@@ -1214,11 +1191,10 @@ var UI = {
var screen = UI.screenSize();
if (screen && UI.connected && UI.rfb.get_display()) {
if (screen && UI.connected) {
var display = UI.rfb.get_display();
var resizeMode = UI.getSetting('resize');
display.set_scale(1);
UI.rfb.viewportScale = 1.0;
// Make sure the viewport is adjusted first
UI.updateViewClip();
@@ -1250,19 +1226,17 @@ var UI = {
if (!UI.rfb) return;
var resizeMode = UI.getSetting('resize');
if (resizeMode !== 'scale' && resizeMode !== 'downscale') {
if (resizeMode !== 'scale') {
return;
}
var screen = UI.screenSize();
if (!screen || !UI.connected || !UI.rfb.get_display()) {
if (!screen || !UI.connected) {
return;
}
var display = UI.rfb.get_display();
var downscaleOnly = resizeMode === 'downscale';
display.autoscale(screen.w, screen.h, downscaleOnly);
UI.rfb.autoscale(screen.w, screen.h);
UI.fixScrollbars();
},
@@ -1275,13 +1249,14 @@ var UI = {
// Normally we only apply the current resize mode after a window resize
// event. This means that when a new connection is opened, there is no
// resize mode active.
// We have to wait until the first FBU because this is where the client
// will find the supported encodings of the server. Some calls later in
// the chain is dependant on knowing the server-capabilities.
initialResize: function(rfb, fbu) {
// We have to wait until we know the capabilities of the server as
// some calls later in the chain is dependant on knowing the
// server-capabilities.
initialResize: function() {
if (UI.doneInitialResize) return;
UI.applyResizeMode();
// After doing this once, we remove the callback.
UI.rfb.set_onFBUComplete(function() { });
UI.doneInitialResize = true;
},
/* ------^-------
@@ -1300,12 +1275,11 @@ var UI = {
updateViewClip: function() {
if (!UI.rfb) return;
var display = UI.rfb.get_display();
var cur_clip = display.get_viewport();
var cur_clip = UI.rfb.clipViewport;
var new_clip = UI.getSetting('view_clip');
var resizeSetting = UI.getSetting('resize');
if (resizeSetting === 'downscale' || resizeSetting === 'scale') {
if (resizeSetting === 'scale') {
// Disable viewport clipping if we are scaling
new_clip = false;
} else if (isTouchDevice) {
@@ -1314,7 +1288,7 @@ var UI = {
}
if (cur_clip !== new_clip) {
display.set_viewport(new_clip);
UI.rfb.clipViewport = new_clip;
}
var size = UI.screenSize();
@@ -1322,7 +1296,7 @@ var UI = {
if (new_clip && size) {
// When clipping is enabled, the screen is limited to
// the size of the browser window.
display.viewportChangeSize(size.w, size.h);
UI.rfb.viewportChangeSize(size.w, size.h);
UI.fixScrollbars();
}
@@ -1335,7 +1309,7 @@ var UI = {
enableDisableViewClip: function() {
var resizeSetting = UI.getSetting('resize');
// Disable clipping if we are scaling, connected or on touch
if (resizeSetting === 'downscale' || resizeSetting === 'scale' ||
if (resizeSetting === 'scale' ||
isTouchDevice) {
UI.disableSetting('view_clip');
} else {
@@ -1352,7 +1326,7 @@ var UI = {
toggleViewDrag: function() {
if (!UI.rfb) return;
var drag = UI.rfb.get_viewportDrag();
var drag = UI.rfb.dragViewport;
UI.setViewDrag(!drag);
},
@@ -1360,7 +1334,7 @@ var UI = {
setViewDrag: function(drag) {
if (!UI.rfb) return;
UI.rfb.set_viewportDrag(drag);
UI.rfb.dragViewport = drag;
UI.updateViewDrag();
},
@@ -1372,22 +1346,21 @@ var UI = {
// Check if viewport drag is possible. It is only possible
// if the remote display is clipping the client display.
if (UI.rfb.get_display().get_viewport() &&
UI.rfb.get_display().clippingDisplay()) {
if (UI.rfb.clipViewport && UI.rfb.isClipped) {
clipping = true;
}
var viewDragButton = document.getElementById('noVNC_view_drag_button');
if (!clipping &&
UI.rfb.get_viewportDrag()) {
UI.rfb.dragViewport) {
// The size of the remote display is the same or smaller
// than the client display. Make sure viewport drag isn't
// active when it can't be used.
UI.rfb.set_viewportDrag(false);
UI.rfb.dragViewport = false;
}
if (UI.rfb.get_viewportDrag()) {
if (UI.rfb.dragViewport) {
viewDragButton.classList.add("noVNC_selected");
} else {
viewDragButton.classList.remove("noVNC_selected");
@@ -1655,9 +1628,9 @@ var UI = {
* ------v------*/
setMouseButton: function(num) {
var view_only = UI.rfb.get_view_only();
var view_only = UI.rfb.viewOnly;
if (UI.rfb && !view_only) {
UI.rfb.get_mouse().set_touchButton(num);
UI.rfb.touchButton = num;
}
var blist = [0, 1,2,4];
@@ -1672,21 +1645,16 @@ var UI = {
}
},
updateLocalCursor: function() {
if (!UI.rfb) return;
UI.rfb.set_local_cursor(UI.getSetting('cursor'));
},
updateViewOnly: function() {
if (!UI.rfb) return;
UI.rfb.set_view_only(UI.getSetting('view_only'));
UI.rfb.viewOnly = UI.getSetting('view_only');
},
updateLogging: function() {
WebUtil.init_logging(UI.getSetting('logging'));
},
updateSessionSize: function(rfb, width, height) {
updateSessionSize: function(e) {
UI.updateViewClip();
UI.updateScaling();
UI.fixScrollbars();
@@ -1704,13 +1672,13 @@ var UI = {
screen.style.overflow = "";
},
updateDesktopName: function(rfb, name) {
UI.desktopName = name;
updateDesktopName: function(e) {
UI.desktopName = e.detail.name;
// Display the desktop name in the document title
document.title = name + " - noVNC";
document.title = e.detail.name + " - noVNC";
},
bell: function(rfb) {
bell: function(e) {
if (WebUtil.getConfigVar('bell', 'on') === 'on') {
var promise = document.getElementById('noVNC_bell').play();
// The standards disagree on the return value here