2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2012 Joel Martin
4 * Copyright (C) 2016 Samuel Mannehed for Cendio AB
5 * Copyright (C) 2016 Pierre Ossman for Cendio AB
6 * Licensed under MPL 2.0 (see LICENSE.txt)
8 * See README.md for usage and integration instructions.
11 /* jslint white: false, browser: true */
12 /* global window, document.getElementById, Util, WebUtil, RFB, Display */
14 import * as Log
from '../core/util/logging.js';
15 import _
, { l10n
} from '../core/util/localization.js';
16 import { isTouchDevice
} from '../core/util/browsers.js';
17 import { setCapture
, getPointerEvent
} from '../core/util/events.js';
18 import KeyTable
from "../core/input/keysym.js";
19 import keysyms
from "../core/input/keysymdef.js";
20 import Keyboard
from "../core/input/keyboard.js";
21 import RFB
from "../core/rfb.js";
22 import Display
from "../core/display.js";
23 import * as WebUtil
from "./webutil.js";
32 hideKeyboardTimeout
: null,
33 idleControlbarTimeout
: null,
34 closeControlbarTimeout
: null,
36 controlbarGrabbed
: false,
37 controlbarDrag
: false,
38 controlbarMouseDownClientY
: 0,
39 controlbarMouseDownOffsetY
: 0,
42 lastKeyboardinput
: null,
43 defaultKeyboardinputLen
: 100,
45 inhibit_reconnect
: true,
46 reconnect_callback
: null,
47 reconnect_password
: null,
49 prime: function(callback
) {
50 if (document
.readyState
=== "interactive" || document
.readyState
=== "complete") {
53 document
.addEventListener('DOMContentLoaded', UI
.load
.bind(UI
, callback
));
57 // Setup rfb object, load settings from browser storage, then call
58 // UI.init to setup the UI/menus
59 load: function(callback
) {
60 WebUtil
.initSettings(UI
.start
, callback
);
63 // Render default UI and initialize settings menu
64 start: function(callback
) {
66 // Setup global variables first
67 UI
.isSafari
= (navigator
.userAgent
.indexOf('Safari') !== -1 &&
68 navigator
.userAgent
.indexOf('Chrome') === -1);
75 // Adapt the interface for touch screen devices
77 document
.documentElement
.classList
.add("noVNC_touch");
78 // Remove the address bar
79 setTimeout(function() { window
.scrollTo(0, 1); }, 100);
82 // Restore control bar position
83 if (WebUtil
.readSetting('controlbar_pos') === 'right') {
84 UI
.toggleControlbarSide();
89 // Setup event handlers
90 UI
.addResizeHandlers();
91 UI
.addControlbarHandlers();
92 UI
.addTouchSpecificHandlers();
93 UI
.addExtraKeysHandlers();
94 UI
.addMachineHandlers();
95 UI
.addConnectionControlHandlers();
96 UI
.addClipboardHandlers();
97 UI
.addSettingsHandlers();
98 document
.getElementById("noVNC_status")
99 .addEventListener('click', UI
.hideStatus
);
101 // Bootstrap fallback input handler
102 UI
.keyboardinputReset();
108 UI
.updateVisualState();
110 document
.documentElement
.classList
.remove("noVNC_loading");
112 var autoconnect
= WebUtil
.getConfigVar('autoconnect', false);
113 if (autoconnect
=== 'true' || autoconnect
== '1') {
118 // Show the connect panel on first load unless autoconnecting
119 UI
.openConnectPanel();
122 if (typeof callback
=== "function") {
127 initFullscreen: function() {
128 // Only show the button if fullscreen is properly supported
129 // * Safari doesn't support alphanumerical input while in fullscreen
131 (document
.documentElement
.requestFullscreen
||
132 document
.documentElement
.mozRequestFullScreen
||
133 document
.documentElement
.webkitRequestFullscreen
||
134 document
.body
.msRequestFullscreen
)) {
135 document
.getElementById('noVNC_fullscreen_button')
136 .classList
.remove("noVNC_hidden");
137 UI
.addFullscreenHandlers();
141 initSettings: function() {
144 // Logging selection dropdown
145 var llevels
= ['error', 'warn', 'info', 'debug'];
146 for (i
= 0; i
< llevels
.length
; i
+= 1) {
147 UI
.addOption(document
.getElementById('noVNC_setting_logging'),llevels
[i
], llevels
[i
]);
150 // Settings with immediate effects
151 UI
.initSetting('logging', 'warn');
154 // if port == 80 (or 443) then it won't be present and should be
156 var port
= window
.location
.port
;
158 if (window
.location
.protocol
.substring(0,5) == 'https') {
161 else if (window
.location
.protocol
.substring(0,4) == 'http') {
166 /* Populate the controls if defaults are provided in the URL */
167 UI
.initSetting('host', window
.location
.hostname
);
168 UI
.initSetting('port', port
);
169 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
170 UI
.initSetting('view_clip', false);
171 UI
.initSetting('resize', 'off');
172 UI
.initSetting('shared', true);
173 UI
.initSetting('view_only', false);
174 UI
.initSetting('path', 'websockify');
175 UI
.initSetting('repeaterID', '');
176 UI
.initSetting('reconnect', false);
177 UI
.initSetting('reconnect_delay', 5000);
179 UI
.setupSettingLabels();
181 // Adds a link to the label elements on the corresponding input elements
182 setupSettingLabels: function() {
183 var labels
= document
.getElementsByTagName('LABEL');
184 for (var i
= 0; i
< labels
.length
; i
++) {
185 var htmlFor
= labels
[i
].htmlFor
;
187 var elem
= document
.getElementById(htmlFor
);
188 if (elem
) elem
.label
= labels
[i
];
190 // If 'for' isn't set, use the first input element child
191 var children
= labels
[i
].children
;
192 for (var j
= 0; j
< children
.length
; j
++) {
193 if (children
[j
].form
!== undefined) {
194 children
[j
].label
= labels
[i
];
208 addResizeHandlers: function() {
209 window
.addEventListener('resize', UI
.applyResizeMode
);
210 window
.addEventListener('resize', UI
.updateViewClip
);
213 addControlbarHandlers: function() {
214 document
.getElementById("noVNC_control_bar")
215 .addEventListener('mousemove', UI
.activateControlbar
);
216 document
.getElementById("noVNC_control_bar")
217 .addEventListener('mouseup', UI
.activateControlbar
);
218 document
.getElementById("noVNC_control_bar")
219 .addEventListener('mousedown', UI
.activateControlbar
);
220 document
.getElementById("noVNC_control_bar")
221 .addEventListener('keydown', UI
.activateControlbar
);
223 document
.getElementById("noVNC_control_bar")
224 .addEventListener('mousedown', UI
.keepControlbar
);
225 document
.getElementById("noVNC_control_bar")
226 .addEventListener('keydown', UI
.keepControlbar
);
228 document
.getElementById("noVNC_view_drag_button")
229 .addEventListener('click', UI
.toggleViewDrag
);
231 document
.getElementById("noVNC_control_bar_handle")
232 .addEventListener('mousedown', UI
.controlbarHandleMouseDown
);
233 document
.getElementById("noVNC_control_bar_handle")
234 .addEventListener('mouseup', UI
.controlbarHandleMouseUp
);
235 document
.getElementById("noVNC_control_bar_handle")
236 .addEventListener('mousemove', UI
.dragControlbarHandle
);
237 // resize events aren't available for elements
238 window
.addEventListener('resize', UI
.updateControlbarHandle
);
240 var exps
= document
.getElementsByClassName("noVNC_expander");
241 for (var i
= 0;i
< exps
.length
;i
++) {
242 exps
[i
].addEventListener('click', UI
.toggleExpander
);
246 addTouchSpecificHandlers: function() {
247 document
.getElementById("noVNC_mouse_button0")
248 .addEventListener('click', function () { UI
.setMouseButton(1); });
249 document
.getElementById("noVNC_mouse_button1")
250 .addEventListener('click', function () { UI
.setMouseButton(2); });
251 document
.getElementById("noVNC_mouse_button2")
252 .addEventListener('click', function () { UI
.setMouseButton(4); });
253 document
.getElementById("noVNC_mouse_button4")
254 .addEventListener('click', function () { UI
.setMouseButton(0); });
255 document
.getElementById("noVNC_keyboard_button")
256 .addEventListener('click', UI
.toggleVirtualKeyboard
);
258 UI
.touchKeyboard
= new Keyboard(document
.getElementById('noVNC_keyboardinput'));
259 UI
.touchKeyboard
.onkeyevent
= UI
.keyEvent
;
260 UI
.touchKeyboard
.grab();
261 document
.getElementById("noVNC_keyboardinput")
262 .addEventListener('input', UI
.keyInput
);
263 document
.getElementById("noVNC_keyboardinput")
264 .addEventListener('focus', UI
.onfocusVirtualKeyboard
);
265 document
.getElementById("noVNC_keyboardinput")
266 .addEventListener('blur', UI
.onblurVirtualKeyboard
);
267 document
.getElementById("noVNC_keyboardinput")
268 .addEventListener('submit', function () { return false; });
270 document
.documentElement
271 .addEventListener('mousedown', UI
.keepVirtualKeyboard
, true);
273 document
.getElementById("noVNC_control_bar")
274 .addEventListener('touchstart', UI
.activateControlbar
);
275 document
.getElementById("noVNC_control_bar")
276 .addEventListener('touchmove', UI
.activateControlbar
);
277 document
.getElementById("noVNC_control_bar")
278 .addEventListener('touchend', UI
.activateControlbar
);
279 document
.getElementById("noVNC_control_bar")
280 .addEventListener('input', UI
.activateControlbar
);
282 document
.getElementById("noVNC_control_bar")
283 .addEventListener('touchstart', UI
.keepControlbar
);
284 document
.getElementById("noVNC_control_bar")
285 .addEventListener('input', UI
.keepControlbar
);
287 document
.getElementById("noVNC_control_bar_handle")
288 .addEventListener('touchstart', UI
.controlbarHandleMouseDown
);
289 document
.getElementById("noVNC_control_bar_handle")
290 .addEventListener('touchend', UI
.controlbarHandleMouseUp
);
291 document
.getElementById("noVNC_control_bar_handle")
292 .addEventListener('touchmove', UI
.dragControlbarHandle
);
295 addExtraKeysHandlers: function() {
296 document
.getElementById("noVNC_toggle_extra_keys_button")
297 .addEventListener('click', UI
.toggleExtraKeys
);
298 document
.getElementById("noVNC_toggle_ctrl_button")
299 .addEventListener('click', UI
.toggleCtrl
);
300 document
.getElementById("noVNC_toggle_alt_button")
301 .addEventListener('click', UI
.toggleAlt
);
302 document
.getElementById("noVNC_send_tab_button")
303 .addEventListener('click', UI
.sendTab
);
304 document
.getElementById("noVNC_send_esc_button")
305 .addEventListener('click', UI
.sendEsc
);
306 document
.getElementById("noVNC_send_ctrl_alt_del_button")
307 .addEventListener('click', UI
.sendCtrlAltDel
);
310 addMachineHandlers: function() {
311 document
.getElementById("noVNC_shutdown_button")
312 .addEventListener('click', function() { UI
.rfb
.machineShutdown(); });
313 document
.getElementById("noVNC_reboot_button")
314 .addEventListener('click', function() { UI
.rfb
.machineReboot(); });
315 document
.getElementById("noVNC_reset_button")
316 .addEventListener('click', function() { UI
.rfb
.machineReset(); });
317 document
.getElementById("noVNC_power_button")
318 .addEventListener('click', UI
.togglePowerPanel
);
321 addConnectionControlHandlers: function() {
322 document
.getElementById("noVNC_disconnect_button")
323 .addEventListener('click', UI
.disconnect
);
324 document
.getElementById("noVNC_connect_button")
325 .addEventListener('click', UI
.connect
);
326 document
.getElementById("noVNC_cancel_reconnect_button")
327 .addEventListener('click', UI
.cancelReconnect
);
329 document
.getElementById("noVNC_password_button")
330 .addEventListener('click', UI
.setPassword
);
333 addClipboardHandlers: function() {
334 document
.getElementById("noVNC_clipboard_button")
335 .addEventListener('click', UI
.toggleClipboardPanel
);
336 document
.getElementById("noVNC_clipboard_text")
337 .addEventListener('change', UI
.clipboardSend
);
338 document
.getElementById("noVNC_clipboard_clear_button")
339 .addEventListener('click', UI
.clipboardClear
);
342 // Add a call to save settings when the element changes,
343 // unless the optional parameter changeFunc is used instead.
344 addSettingChangeHandler: function(name
, changeFunc
) {
345 var settingElem
= document
.getElementById("noVNC_setting_" + name
);
346 if (changeFunc
=== undefined) {
347 changeFunc = function () { UI
.saveSetting(name
); };
349 settingElem
.addEventListener('change', changeFunc
);
352 addSettingsHandlers: function() {
353 document
.getElementById("noVNC_settings_button")
354 .addEventListener('click', UI
.toggleSettingsPanel
);
356 UI
.addSettingChangeHandler('encrypt');
357 UI
.addSettingChangeHandler('resize');
358 UI
.addSettingChangeHandler('resize', UI
.enableDisableViewClip
);
359 UI
.addSettingChangeHandler('resize', UI
.applyResizeMode
);
360 UI
.addSettingChangeHandler('view_clip');
361 UI
.addSettingChangeHandler('view_clip', UI
.updateViewClip
);
362 UI
.addSettingChangeHandler('shared');
363 UI
.addSettingChangeHandler('view_only');
364 UI
.addSettingChangeHandler('view_only', UI
.updateViewOnly
);
365 UI
.addSettingChangeHandler('host');
366 UI
.addSettingChangeHandler('port');
367 UI
.addSettingChangeHandler('path');
368 UI
.addSettingChangeHandler('repeaterID');
369 UI
.addSettingChangeHandler('logging');
370 UI
.addSettingChangeHandler('logging', UI
.updateLogging
);
371 UI
.addSettingChangeHandler('reconnect');
372 UI
.addSettingChangeHandler('reconnect_delay');
375 addFullscreenHandlers: function() {
376 document
.getElementById("noVNC_fullscreen_button")
377 .addEventListener('click', UI
.toggleFullscreen
);
379 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
380 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
381 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
382 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
391 updateState: function(event
) {
394 document
.documentElement
.classList
.remove("noVNC_connecting");
395 document
.documentElement
.classList
.remove("noVNC_connected");
396 document
.documentElement
.classList
.remove("noVNC_disconnecting");
397 document
.documentElement
.classList
.remove("noVNC_reconnecting");
399 switch (event
.detail
.state
) {
401 document
.getElementById("noVNC_transition_text").textContent
= _("Connecting...");
402 document
.documentElement
.classList
.add("noVNC_connecting");
406 UI
.inhibit_reconnect
= false;
407 UI
.doneInitialResize
= false;
408 document
.documentElement
.classList
.add("noVNC_connected");
409 if (UI
.getSetting('encrypt')) {
410 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
412 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
415 document
.getElementById('noVNC_canvas').focus();
417 case 'disconnecting':
418 UI
.connected
= false;
419 document
.getElementById("noVNC_transition_text").textContent
= _("Disconnecting...");
420 document
.documentElement
.classList
.add("noVNC_disconnecting");
423 UI
.showStatus(_("Disconnected"));
426 Log
.Error("Invalid visual state: " + event
.detail
.state
);
427 UI
.showStatus(_("Internal error"), 'error');
431 UI
.updateVisualState();
434 // Disable/enable controls depending on connection state
435 updateVisualState: function() {
436 //Log.Debug(">> updateVisualState");
438 UI
.enableDisableViewClip();
441 UI
.disableSetting('encrypt');
442 UI
.disableSetting('shared');
443 UI
.disableSetting('host');
444 UI
.disableSetting('port');
445 UI
.disableSetting('path');
446 UI
.disableSetting('repeaterID');
448 UI
.setMouseButton(1);
450 // Hide the controlbar after 2 seconds
451 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
453 UI
.enableSetting('encrypt');
454 UI
.enableSetting('shared');
455 UI
.enableSetting('host');
456 UI
.enableSetting('port');
457 UI
.enableSetting('path');
458 UI
.enableSetting('repeaterID');
459 UI
.updatePowerButton();
463 // Hide input related buttons in view only mode
464 if (UI
.rfb
&& UI
.rfb
.viewOnly
) {
465 document
.getElementById('noVNC_keyboard_button')
466 .classList
.add('noVNC_hidden');
467 document
.getElementById('noVNC_toggle_extra_keys_button')
468 .classList
.add('noVNC_hidden');
470 document
.getElementById('noVNC_keyboard_button')
471 .classList
.remove('noVNC_hidden');
472 document
.getElementById('noVNC_toggle_extra_keys_button')
473 .classList
.remove('noVNC_hidden');
476 // State change disables viewport dragging.
477 // It is enabled (toggled) by direct click on the button
478 UI
.setViewDrag(false);
480 // State change also closes the password dialog
481 document
.getElementById('noVNC_password_dlg')
482 .classList
.remove('noVNC_open');
484 //Log.Debug("<< updateVisualState");
487 showStatus: function(text
, status_type
, time
) {
488 var statusElem
= document
.getElementById('noVNC_status');
490 clearTimeout(UI
.statusTimeout
);
492 if (typeof status_type
=== 'undefined') {
493 status_type
= 'normal';
496 statusElem
.classList
.remove("noVNC_status_normal");
497 statusElem
.classList
.remove("noVNC_status_warn");
498 statusElem
.classList
.remove("noVNC_status_error");
500 switch (status_type
) {
503 statusElem
.classList
.add("noVNC_status_warn");
506 statusElem
.classList
.add("noVNC_status_error");
511 statusElem
.classList
.add("noVNC_status_normal");
515 statusElem
.textContent
= text
;
516 statusElem
.classList
.add("noVNC_open");
518 // If no time was specified, show the status for 1.5 seconds
519 if (typeof time
=== 'undefined') {
523 // Error messages do not timeout
524 if (status_type
!== 'error') {
525 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
529 hideStatus: function() {
530 clearTimeout(UI
.statusTimeout
);
531 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
534 activateControlbar: function(event
) {
535 clearTimeout(UI
.idleControlbarTimeout
);
536 // We manipulate the anchor instead of the actual control
537 // bar in order to avoid creating new a stacking group
538 document
.getElementById('noVNC_control_bar_anchor')
539 .classList
.remove("noVNC_idle");
540 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
543 idleControlbar: function() {
544 document
.getElementById('noVNC_control_bar_anchor')
545 .classList
.add("noVNC_idle");
548 keepControlbar: function() {
549 clearTimeout(UI
.closeControlbarTimeout
);
552 openControlbar: function() {
553 document
.getElementById('noVNC_control_bar')
554 .classList
.add("noVNC_open");
557 closeControlbar: function() {
559 document
.getElementById('noVNC_control_bar')
560 .classList
.remove("noVNC_open");
563 toggleControlbar: function() {
564 if (document
.getElementById('noVNC_control_bar')
565 .classList
.contains("noVNC_open")) {
566 UI
.closeControlbar();
572 toggleControlbarSide: function () {
573 // Temporarily disable animation to avoid weird movement
574 var bar
= document
.getElementById('noVNC_control_bar');
575 bar
.style
.transitionDuration
= '0s';
576 bar
.addEventListener('transitionend', function () { this.style
.transitionDuration
= ""; });
578 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
579 if (anchor
.classList
.contains("noVNC_right")) {
580 WebUtil
.writeSetting('controlbar_pos', 'left');
581 anchor
.classList
.remove("noVNC_right");
583 WebUtil
.writeSetting('controlbar_pos', 'right');
584 anchor
.classList
.add("noVNC_right");
587 // Consider this a movement of the handle
588 UI
.controlbarDrag
= true;
591 showControlbarHint: function (show
) {
592 var hint
= document
.getElementById('noVNC_control_bar_hint');
594 hint
.classList
.add("noVNC_active");
596 hint
.classList
.remove("noVNC_active");
600 dragControlbarHandle: function (e
) {
601 if (!UI
.controlbarGrabbed
) return;
603 var ptr
= getPointerEvent(e
);
605 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
606 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
607 if (anchor
.classList
.contains("noVNC_right")) {
608 UI
.toggleControlbarSide();
610 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
611 if (!anchor
.classList
.contains("noVNC_right")) {
612 UI
.toggleControlbarSide();
616 if (!UI
.controlbarDrag
) {
617 // The goal is to trigger on a certain physical width, the
618 // devicePixelRatio brings us a bit closer but is not optimal.
619 var dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
620 var dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
622 if (dragDistance
< dragThreshold
) return;
624 UI
.controlbarDrag
= true;
627 var eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
629 UI
.moveControlbarHandle(eventY
);
634 UI
.activateControlbar();
637 // Move the handle but don't allow any position outside the bounds
638 moveControlbarHandle: function (viewportRelativeY
) {
639 var handle
= document
.getElementById("noVNC_control_bar_handle");
640 var handleHeight
= handle
.getBoundingClientRect().height
;
641 var controlbarBounds
= document
.getElementById("noVNC_control_bar")
642 .getBoundingClientRect();
645 // These heights need to be non-zero for the below logic to work
646 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
650 var newY
= viewportRelativeY
;
652 // Check if the coordinates are outside the control bar
653 if (newY
< controlbarBounds
.top
+ margin
) {
654 // Force coordinates to be below the top of the control bar
655 newY
= controlbarBounds
.top
+ margin
;
657 } else if (newY
> controlbarBounds
.top
+
658 controlbarBounds
.height
- handleHeight
- margin
) {
659 // Force coordinates to be above the bottom of the control bar
660 newY
= controlbarBounds
.top
+
661 controlbarBounds
.height
- handleHeight
- margin
;
664 // Corner case: control bar too small for stable position
665 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
666 newY
= controlbarBounds
.top
+
667 (controlbarBounds
.height
- handleHeight
) / 2;
670 // The transform needs coordinates that are relative to the parent
671 var parentRelativeY
= newY
- controlbarBounds
.top
;
672 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
675 updateControlbarHandle: function () {
676 // Since the control bar is fixed on the viewport and not the page,
677 // the move function expects coordinates relative the the viewport.
678 var handle
= document
.getElementById("noVNC_control_bar_handle");
679 var handleBounds
= handle
.getBoundingClientRect();
680 UI
.moveControlbarHandle(handleBounds
.top
);
683 controlbarHandleMouseUp: function(e
) {
684 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
686 // mouseup and mousedown on the same place toggles the controlbar
687 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
688 UI
.toggleControlbar();
692 UI
.activateControlbar();
694 UI
.controlbarGrabbed
= false;
695 UI
.showControlbarHint(false);
698 controlbarHandleMouseDown: function(e
) {
699 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
701 var ptr
= getPointerEvent(e
);
703 var handle
= document
.getElementById("noVNC_control_bar_handle");
704 var bounds
= handle
.getBoundingClientRect();
706 // Touch events have implicit capture
707 if (e
.type
=== "mousedown") {
711 UI
.controlbarGrabbed
= true;
712 UI
.controlbarDrag
= false;
714 UI
.showControlbarHint(true);
716 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
717 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
721 UI
.activateControlbar();
724 toggleExpander: function(e
) {
725 if (this.classList
.contains("noVNC_open")) {
726 this.classList
.remove("noVNC_open");
728 this.classList
.add("noVNC_open");
738 // Initial page load read/initialization of settings
739 initSetting: function(name
, defVal
) {
740 // Check Query string followed by cookie
741 var val
= WebUtil
.getConfigVar(name
);
743 val
= WebUtil
.readSetting(name
, defVal
);
745 UI
.updateSetting(name
, val
);
749 // Update cookie and form control setting. If value is not set, then
750 // updates from control to current cookie setting.
751 updateSetting: function(name
, value
) {
753 // Save the cookie for this session
754 if (typeof value
!== 'undefined') {
755 WebUtil
.writeSetting(name
, value
);
758 // Update the settings control
759 value
= UI
.getSetting(name
);
761 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
762 if (ctrl
.type
=== 'checkbox') {
763 ctrl
.checked
= value
;
765 } else if (typeof ctrl
.options
!== 'undefined') {
766 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
767 if (ctrl
.options
[i
].value
=== value
) {
768 ctrl
.selectedIndex
= i
;
773 /*Weird IE9 error leads to 'null' appearring
774 in textboxes instead of ''.*/
775 if (value
=== null) {
782 // Save control setting to cookie
783 saveSetting: function(name
) {
784 var val
, ctrl
= document
.getElementById('noVNC_setting_' + name
);
785 if (ctrl
.type
=== 'checkbox') {
787 } else if (typeof ctrl
.options
!== 'undefined') {
788 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
792 WebUtil
.writeSetting(name
, val
);
793 //Log.Debug("Setting saved '" + name + "=" + val + "'");
797 // Read form control compatible setting from cookie
798 getSetting: function(name
) {
799 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
800 var val
= WebUtil
.readSetting(name
);
801 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
802 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
811 // These helpers compensate for the lack of parent-selectors and
812 // previous-sibling-selectors in CSS which are needed when we want to
813 // disable the labels that belong to disabled input elements.
814 disableSetting: function(name
) {
815 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
816 ctrl
.disabled
= true;
817 ctrl
.label
.classList
.add('noVNC_disabled');
820 enableSetting: function(name
) {
821 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
822 ctrl
.disabled
= false;
823 ctrl
.label
.classList
.remove('noVNC_disabled');
832 closeAllPanels: function() {
833 UI
.closeSettingsPanel();
834 UI
.closePowerPanel();
835 UI
.closeClipboardPanel();
845 openSettingsPanel: function() {
849 // Refresh UI elements from saved cookies
850 UI
.updateSetting('encrypt');
851 UI
.updateSetting('view_clip');
852 UI
.updateSetting('resize');
853 UI
.updateSetting('shared');
854 UI
.updateSetting('view_only');
855 UI
.updateSetting('path');
856 UI
.updateSetting('repeaterID');
857 UI
.updateSetting('logging');
858 UI
.updateSetting('reconnect');
859 UI
.updateSetting('reconnect_delay');
861 document
.getElementById('noVNC_settings')
862 .classList
.add("noVNC_open");
863 document
.getElementById('noVNC_settings_button')
864 .classList
.add("noVNC_selected");
867 closeSettingsPanel: function() {
868 document
.getElementById('noVNC_settings')
869 .classList
.remove("noVNC_open");
870 document
.getElementById('noVNC_settings_button')
871 .classList
.remove("noVNC_selected");
874 toggleSettingsPanel: function() {
875 if (document
.getElementById('noVNC_settings')
876 .classList
.contains("noVNC_open")) {
877 UI
.closeSettingsPanel();
879 UI
.openSettingsPanel();
889 openPowerPanel: function() {
893 document
.getElementById('noVNC_power')
894 .classList
.add("noVNC_open");
895 document
.getElementById('noVNC_power_button')
896 .classList
.add("noVNC_selected");
899 closePowerPanel: function() {
900 document
.getElementById('noVNC_power')
901 .classList
.remove("noVNC_open");
902 document
.getElementById('noVNC_power_button')
903 .classList
.remove("noVNC_selected");
906 togglePowerPanel: function() {
907 if (document
.getElementById('noVNC_power')
908 .classList
.contains("noVNC_open")) {
909 UI
.closePowerPanel();
915 // Disable/enable power button
916 updatePowerButton: function() {
918 UI
.rfb
.capabilities
.power
&&
920 document
.getElementById('noVNC_power_button')
921 .classList
.remove("noVNC_hidden");
923 document
.getElementById('noVNC_power_button')
924 .classList
.add("noVNC_hidden");
925 // Close power panel if open
926 UI
.closePowerPanel();
936 openClipboardPanel: function() {
940 document
.getElementById('noVNC_clipboard')
941 .classList
.add("noVNC_open");
942 document
.getElementById('noVNC_clipboard_button')
943 .classList
.add("noVNC_selected");
946 closeClipboardPanel: function() {
947 document
.getElementById('noVNC_clipboard')
948 .classList
.remove("noVNC_open");
949 document
.getElementById('noVNC_clipboard_button')
950 .classList
.remove("noVNC_selected");
953 toggleClipboardPanel: function() {
954 if (document
.getElementById('noVNC_clipboard')
955 .classList
.contains("noVNC_open")) {
956 UI
.closeClipboardPanel();
958 UI
.openClipboardPanel();
962 clipboardReceive: function(e
) {
963 Log
.Debug(">> UI.clipboardReceive: " + e
.detail
.text
.substr(0,40) + "...");
964 document
.getElementById('noVNC_clipboard_text').value
= e
.detail
.text
;
965 Log
.Debug("<< UI.clipboardReceive");
968 clipboardClear: function() {
969 document
.getElementById('noVNC_clipboard_text').value
= "";
970 UI
.rfb
.clipboardPasteFrom("");
973 clipboardSend: function() {
974 var text
= document
.getElementById('noVNC_clipboard_text').value
;
975 Log
.Debug(">> UI.clipboardSend: " + text
.substr(0,40) + "...");
976 UI
.rfb
.clipboardPasteFrom(text
);
977 Log
.Debug("<< UI.clipboardSend");
986 openConnectPanel: function() {
987 document
.getElementById('noVNC_connect_dlg')
988 .classList
.add("noVNC_open");
991 closeConnectPanel: function() {
992 document
.getElementById('noVNC_connect_dlg')
993 .classList
.remove("noVNC_open");
996 connect: function(event
, password
) {
997 var host
= UI
.getSetting('host');
998 var port
= UI
.getSetting('port');
999 var path
= UI
.getSetting('path');
1001 if (typeof password
=== 'undefined') {
1002 password
= WebUtil
.getConfigVar('password');
1003 UI
.reconnect_password
= password
;
1006 if (password
=== null) {
1007 password
= undefined;
1011 var msg
= _("Must set host");
1013 UI
.showStatus(msg
, 'error');
1017 UI
.closeAllPanels();
1018 UI
.closeConnectPanel();
1020 UI
.updateViewOnly();
1024 url
= UI
.getSetting('encrypt') ? 'wss' : 'ws';
1026 url
+= '://' + host
;
1032 UI
.rfb
= new RFB(document
.getElementById('noVNC_canvas'), url
,
1033 { shared
: UI
.getSetting('shared'),
1034 repeaterID
: UI
.getSetting('repeaterID'),
1035 credentials
: { password
: password
} });
1036 UI
.rfb
.addEventListener("updatestate", UI
.updateState
);
1037 UI
.rfb
.addEventListener("disconnect", UI
.disconnectFinished
);
1038 UI
.rfb
.addEventListener("credentialsrequired", UI
.credentials
);
1039 UI
.rfb
.addEventListener("capabilities", function () { UI
.updatePowerButton(); UI
.initialResize(); });
1040 UI
.rfb
.addEventListener("clipboard", UI
.clipboardReceive
);
1041 UI
.rfb
.addEventListener("bell", UI
.bell
);
1042 UI
.rfb
.addEventListener("fbresize", UI
.updateSessionSize
);
1043 UI
.rfb
.addEventListener("desktopname", UI
.updateDesktopName
);
1046 disconnect: function() {
1047 UI
.closeAllPanels();
1048 UI
.rfb
.disconnect();
1050 // Disable automatic reconnecting
1051 UI
.inhibit_reconnect
= true;
1053 // Don't display the connection settings until we're actually disconnected
1056 reconnect: function() {
1057 UI
.reconnect_callback
= null;
1059 // if reconnect has been disabled in the meantime, do nothing.
1060 if (UI
.inhibit_reconnect
) {
1064 UI
.connect(null, UI
.reconnect_password
);
1067 disconnectFinished: function (e
) {
1068 if (typeof e
.detail
.reason
!== 'undefined') {
1069 UI
.showStatus(e
.detail
.reason
, 'error');
1070 } else if (UI
.getSetting('reconnect', false) === true && !UI
.inhibit_reconnect
) {
1071 document
.getElementById("noVNC_transition_text").textContent
= _("Reconnecting...");
1072 document
.documentElement
.classList
.add("noVNC_reconnecting");
1074 var delay
= parseInt(UI
.getSetting('reconnect_delay'));
1075 UI
.reconnect_callback
= setTimeout(UI
.reconnect
, delay
);
1079 UI
.openControlbar();
1080 UI
.openConnectPanel();
1083 cancelReconnect: function() {
1084 if (UI
.reconnect_callback
!== null) {
1085 clearTimeout(UI
.reconnect_callback
);
1086 UI
.reconnect_callback
= null;
1089 document
.documentElement
.classList
.remove("noVNC_reconnecting");
1090 UI
.openControlbar();
1091 UI
.openConnectPanel();
1100 credentials: function(e
) {
1101 // FIXME: handle more types
1102 document
.getElementById('noVNC_password_dlg')
1103 .classList
.add('noVNC_open');
1105 setTimeout(function () {
1106 document
.getElementById('noVNC_password_input').focus();
1109 var msg
= _("Password is required");
1111 UI
.showStatus(msg
, "warning");
1114 setPassword: function(e
) {
1115 // Prevent actually submitting the form
1118 var inputElem
= document
.getElementById('noVNC_password_input');
1119 var password
= inputElem
.value
;
1120 // Clear the input after reading the password
1121 inputElem
.value
= "";
1122 UI
.rfb
.sendCredentials({ password
: password
});
1123 UI
.reconnect_password
= password
;
1124 document
.getElementById('noVNC_password_dlg')
1125 .classList
.remove('noVNC_open');
1134 toggleFullscreen: function() {
1135 if (document
.fullscreenElement
|| // alternative standard method
1136 document
.mozFullScreenElement
|| // currently working methods
1137 document
.webkitFullscreenElement
||
1138 document
.msFullscreenElement
) {
1139 if (document
.exitFullscreen
) {
1140 document
.exitFullscreen();
1141 } else if (document
.mozCancelFullScreen
) {
1142 document
.mozCancelFullScreen();
1143 } else if (document
.webkitExitFullscreen
) {
1144 document
.webkitExitFullscreen();
1145 } else if (document
.msExitFullscreen
) {
1146 document
.msExitFullscreen();
1149 if (document
.documentElement
.requestFullscreen
) {
1150 document
.documentElement
.requestFullscreen();
1151 } else if (document
.documentElement
.mozRequestFullScreen
) {
1152 document
.documentElement
.mozRequestFullScreen();
1153 } else if (document
.documentElement
.webkitRequestFullscreen
) {
1154 document
.documentElement
.webkitRequestFullscreen(Element
.ALLOW_KEYBOARD_INPUT
);
1155 } else if (document
.body
.msRequestFullscreen
) {
1156 document
.body
.msRequestFullscreen();
1159 UI
.enableDisableViewClip();
1160 UI
.updateFullscreenButton();
1163 updateFullscreenButton: function() {
1164 if (document
.fullscreenElement
|| // alternative standard method
1165 document
.mozFullScreenElement
|| // currently working methods
1166 document
.webkitFullscreenElement
||
1167 document
.msFullscreenElement
) {
1168 document
.getElementById('noVNC_fullscreen_button')
1169 .classList
.add("noVNC_selected");
1171 document
.getElementById('noVNC_fullscreen_button')
1172 .classList
.remove("noVNC_selected");
1182 // Apply remote resizing or local scaling
1183 applyResizeMode: function() {
1184 if (!UI
.rfb
) return;
1186 var screen
= UI
.screenSize();
1188 if (screen
&& UI
.connected
) {
1190 var resizeMode
= UI
.getSetting('resize');
1191 UI
.rfb
.viewportScale
= 1.0;
1193 // Make sure the viewport is adjusted first
1194 UI
.updateViewClip();
1196 if (resizeMode
=== 'remote') {
1198 // Request changing the resolution of the remote display to
1199 // the size of the local browser viewport.
1201 // In order to not send multiple requests before the browser-resize
1202 // is finished we wait 0.5 seconds before sending the request.
1203 clearTimeout(UI
.resizeTimeout
);
1204 UI
.resizeTimeout
= setTimeout(function(){
1205 // Request a remote size covering the viewport
1206 if (UI
.rfb
.requestDesktopSize(screen
.w
, screen
.h
)) {
1207 Log
.Debug('Requested new desktop size: ' +
1208 screen
.w
+ 'x' + screen
.h
);
1218 // Re-calculate local scaling
1219 updateScaling: function() {
1220 if (!UI
.rfb
) return;
1222 var resizeMode
= UI
.getSetting('resize');
1223 if (resizeMode
!== 'scale') {
1227 var screen
= UI
.screenSize();
1229 if (!screen
|| !UI
.connected
) {
1233 UI
.rfb
.autoscale(screen
.w
, screen
.h
);
1237 // Gets the the size of the available viewport in the browser window
1238 screenSize: function() {
1239 var screen
= document
.getElementById('noVNC_screen');
1240 return {w
: screen
.offsetWidth
, h
: screen
.offsetHeight
};
1243 // Normally we only apply the current resize mode after a window resize
1244 // event. This means that when a new connection is opened, there is no
1245 // resize mode active.
1246 // We have to wait until we know the capabilities of the server as
1247 // some calls later in the chain is dependant on knowing the
1248 // server-capabilities.
1249 initialResize: function() {
1250 if (UI
.doneInitialResize
) return;
1252 UI
.applyResizeMode();
1253 UI
.doneInitialResize
= true;
1262 // Set and configure viewport clipping
1263 setViewClip: function(clip
) {
1264 UI
.updateSetting('view_clip', clip
);
1265 UI
.updateViewClip();
1268 // Update parameters that depend on the viewport clip setting
1269 updateViewClip: function() {
1270 if (!UI
.rfb
) return;
1272 var cur_clip
= UI
.rfb
.clipViewport
;
1273 var new_clip
= UI
.getSetting('view_clip');
1275 var resizeSetting
= UI
.getSetting('resize');
1276 if (resizeSetting
=== 'scale') {
1277 // Disable viewport clipping if we are scaling
1279 } else if (isTouchDevice
) {
1280 // Touch devices usually have shit scrollbars
1284 if (cur_clip
!== new_clip
) {
1285 UI
.rfb
.clipViewport
= new_clip
;
1288 var size
= UI
.screenSize();
1290 if (new_clip
&& size
) {
1291 // When clipping is enabled, the screen is limited to
1292 // the size of the browser window.
1293 UI
.rfb
.viewportChangeSize(size
.w
, size
.h
);
1297 // Changing the viewport may change the state of
1298 // the dragging button
1299 UI
.updateViewDrag();
1302 // Handle special cases where viewport clipping is forced on/off or locked
1303 enableDisableViewClip: function() {
1304 var resizeSetting
= UI
.getSetting('resize');
1305 // Disable clipping if we are scaling, connected or on touch
1306 if (resizeSetting
=== 'scale' ||
1308 UI
.disableSetting('view_clip');
1310 UI
.enableSetting('view_clip');
1320 toggleViewDrag: function() {
1321 if (!UI
.rfb
) return;
1323 var drag
= UI
.rfb
.dragViewport
;
1324 UI
.setViewDrag(!drag
);
1327 // Set the view drag mode which moves the viewport on mouse drags
1328 setViewDrag: function(drag
) {
1329 if (!UI
.rfb
) return;
1331 UI
.rfb
.dragViewport
= drag
;
1333 UI
.updateViewDrag();
1336 updateViewDrag: function() {
1337 var clipping
= false;
1339 if (!UI
.connected
) return;
1341 // Check if viewport drag is possible. It is only possible
1342 // if the remote display is clipping the client display.
1343 if (UI
.rfb
.clipViewport
&& UI
.rfb
.isClipped
) {
1347 var viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1350 UI
.rfb
.dragViewport
) {
1351 // The size of the remote display is the same or smaller
1352 // than the client display. Make sure viewport drag isn't
1353 // active when it can't be used.
1354 UI
.rfb
.dragViewport
= false;
1357 if (UI
.rfb
.dragViewport
) {
1358 viewDragButton
.classList
.add("noVNC_selected");
1360 viewDragButton
.classList
.remove("noVNC_selected");
1363 // Different behaviour for touch vs non-touch
1364 // The button is disabled instead of hidden on touch devices
1365 if (isTouchDevice
) {
1366 viewDragButton
.classList
.remove("noVNC_hidden");
1369 viewDragButton
.disabled
= false;
1371 viewDragButton
.disabled
= true;
1374 viewDragButton
.disabled
= false;
1377 viewDragButton
.classList
.remove("noVNC_hidden");
1379 viewDragButton
.classList
.add("noVNC_hidden");
1390 showVirtualKeyboard: function() {
1391 if (!isTouchDevice
) return;
1393 var input
= document
.getElementById('noVNC_keyboardinput');
1395 if (document
.activeElement
== input
) return;
1400 var l
= input
.value
.length
;
1401 // Move the caret to the end
1402 input
.setSelectionRange(l
, l
);
1403 } catch (err
) {} // setSelectionRange is undefined in Google Chrome
1406 hideVirtualKeyboard: function() {
1407 if (!isTouchDevice
) return;
1409 var input
= document
.getElementById('noVNC_keyboardinput');
1411 if (document
.activeElement
!= input
) return;
1416 toggleVirtualKeyboard: function () {
1417 if (document
.getElementById('noVNC_keyboard_button')
1418 .classList
.contains("noVNC_selected")) {
1419 UI
.hideVirtualKeyboard();
1421 UI
.showVirtualKeyboard();
1425 onfocusVirtualKeyboard: function(event
) {
1426 document
.getElementById('noVNC_keyboard_button')
1427 .classList
.add("noVNC_selected");
1429 UI
.rfb
.set_focus_on_click(false);
1433 onblurVirtualKeyboard: function(event
) {
1434 document
.getElementById('noVNC_keyboard_button')
1435 .classList
.remove("noVNC_selected");
1437 UI
.rfb
.set_focus_on_click(true);
1441 keepVirtualKeyboard: function(event
) {
1442 var input
= document
.getElementById('noVNC_keyboardinput');
1444 // Only prevent focus change if the virtual keyboard is active
1445 if (document
.activeElement
!= input
) {
1449 // Only allow focus to move to other elements that need
1450 // focus to function properly
1451 if (event
.target
.form
!== undefined) {
1452 switch (event
.target
.type
) {
1461 case 'select-multiple':
1466 event
.preventDefault();
1469 keyboardinputReset: function() {
1470 var kbi
= document
.getElementById('noVNC_keyboardinput');
1471 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1472 UI
.lastKeyboardinput
= kbi
.value
;
1475 keyEvent: function (keysym
, code
, down
) {
1476 if (!UI
.rfb
) return;
1478 UI
.rfb
.sendKey(keysym
, code
, down
);
1481 // When normal keyboard events are left uncought, use the input events from
1482 // the keyboardinput element instead and generate the corresponding key events.
1483 // This code is required since some browsers on Android are inconsistent in
1484 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1485 keyInput: function(event
) {
1487 if (!UI
.rfb
) return;
1489 var newValue
= event
.target
.value
;
1491 if (!UI
.lastKeyboardinput
) {
1492 UI
.keyboardinputReset();
1494 var oldValue
= UI
.lastKeyboardinput
;
1498 // Try to check caret position since whitespace at the end
1499 // will not be considered by value.length in some browsers
1500 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1502 // selectionStart is undefined in Google Chrome
1503 newLen
= newValue
.length
;
1505 var oldLen
= oldValue
.length
;
1508 var inputs
= newLen
- oldLen
;
1510 backspaces
= -inputs
;
1515 // Compare the old string with the new to account for
1516 // text-corrections or other input that modify existing text
1518 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1519 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1520 inputs
= newLen
- i
;
1521 backspaces
= oldLen
- i
;
1526 // Send the key events
1527 for (i
= 0; i
< backspaces
; i
++) {
1528 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
, "Backspace");
1530 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1531 UI
.rfb
.sendKey(keysyms
.lookup(newValue
.charCodeAt(i
)));
1534 // Control the text content length in the keyboardinput element
1535 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1536 UI
.keyboardinputReset();
1537 } else if (newLen
< 1) {
1538 // There always have to be some text in the keyboardinput
1539 // element with which backspace can interact.
1540 UI
.keyboardinputReset();
1541 // This sometimes causes the keyboard to disappear for a second
1542 // but it is required for the android keyboard to recognize that
1543 // text has been added to the field
1544 event
.target
.blur();
1545 // This has to be ran outside of the input handler in order to work
1546 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1548 UI
.lastKeyboardinput
= newValue
;
1558 openExtraKeys: function() {
1559 UI
.closeAllPanels();
1560 UI
.openControlbar();
1562 document
.getElementById('noVNC_modifiers')
1563 .classList
.add("noVNC_open");
1564 document
.getElementById('noVNC_toggle_extra_keys_button')
1565 .classList
.add("noVNC_selected");
1568 closeExtraKeys: function() {
1569 document
.getElementById('noVNC_modifiers')
1570 .classList
.remove("noVNC_open");
1571 document
.getElementById('noVNC_toggle_extra_keys_button')
1572 .classList
.remove("noVNC_selected");
1575 toggleExtraKeys: function() {
1576 if(document
.getElementById('noVNC_modifiers')
1577 .classList
.contains("noVNC_open")) {
1578 UI
.closeExtraKeys();
1584 sendEsc: function() {
1585 UI
.rfb
.sendKey(KeyTable
.XK_Escape
, "Escape");
1588 sendTab: function() {
1589 UI
.rfb
.sendKey(KeyTable
.XK_Tab
);
1592 toggleCtrl: function() {
1593 var btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1594 if (btn
.classList
.contains("noVNC_selected")) {
1595 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", false);
1596 btn
.classList
.remove("noVNC_selected");
1598 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", true);
1599 btn
.classList
.add("noVNC_selected");
1603 toggleAlt: function() {
1604 var btn
= document
.getElementById('noVNC_toggle_alt_button');
1605 if (btn
.classList
.contains("noVNC_selected")) {
1606 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", false);
1607 btn
.classList
.remove("noVNC_selected");
1609 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", true);
1610 btn
.classList
.add("noVNC_selected");
1614 sendCtrlAltDel: function() {
1615 UI
.rfb
.sendCtrlAltDel();
1624 setMouseButton: function(num
) {
1625 var view_only
= UI
.rfb
.viewOnly
;
1626 if (UI
.rfb
&& !view_only
) {
1627 UI
.rfb
.touchButton
= num
;
1630 var blist
= [0, 1,2,4];
1631 for (var b
= 0; b
< blist
.length
; b
++) {
1632 var button
= document
.getElementById('noVNC_mouse_button' +
1634 if (blist
[b
] === num
&& !view_only
) {
1635 button
.classList
.remove("noVNC_hidden");
1637 button
.classList
.add("noVNC_hidden");
1642 updateViewOnly: function() {
1643 if (!UI
.rfb
) return;
1644 UI
.rfb
.viewOnly
= UI
.getSetting('view_only');
1647 updateLogging: function() {
1648 WebUtil
.init_logging(UI
.getSetting('logging'));
1651 updateSessionSize: function(e
) {
1652 UI
.updateViewClip();
1657 fixScrollbars: function() {
1658 // This is a hack because Chrome screws up the calculation
1659 // for when scrollbars are needed. So to fix it we temporarily
1660 // toggle them off and on.
1661 var screen
= document
.getElementById('noVNC_screen');
1662 screen
.style
.overflow
= 'hidden';
1663 // Force Chrome to recalculate the layout by asking for
1664 // an element's dimensions
1665 screen
.getBoundingClientRect();
1666 screen
.style
.overflow
= "";
1669 updateDesktopName: function(e
) {
1670 UI
.desktopName
= e
.detail
.name
;
1671 // Display the desktop name in the document title
1672 document
.title
= e
.detail
.name
+ " - noVNC";
1676 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1677 var promise
= document
.getElementById('noVNC_bell').play();
1678 // The standards disagree on the return value here
1680 promise
.catch(function(e
) {
1681 if (e
.name
=== "NotAllowedError") {
1682 // Ignore when the browser doesn't let us play audio.
1683 // It is common that the browsers require audio to be
1684 // initiated from a user action.
1686 Log
.Error("Unable to play bell: " + e
);
1693 //Helper to add options to dropdown.
1694 addOption: function(selectbox
, text
, value
) {
1695 var optn
= document
.createElement("OPTION");
1698 selectbox
.options
.add(optn
);
1707 // Set up translations
1708 var LINGUAS
= ["de", "el", "nl", "pl", "sv"];
1709 l10n
.setup(LINGUAS
);
1710 if (l10n
.language
!== "en" && l10n
.dictionary
=== undefined) {
1711 WebUtil
.fetchJSON('app/locale/' + l10n
.language
+ '.json', function (translations
) {
1712 l10n
.dictionary
= translations
;
1714 // wait for translations to load before loading the UI