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 import * as Log
from '../core/util/logging.js';
12 import _
, { l10n
} from './localization.js';
13 import { isTouchDevice
} from '../core/util/browser.js';
14 import { setCapture
, getPointerEvent
} from '../core/util/events.js';
15 import KeyTable
from "../core/input/keysym.js";
16 import keysyms
from "../core/input/keysymdef.js";
17 import Keyboard
from "../core/input/keyboard.js";
18 import RFB
from "../core/rfb.js";
19 import Display
from "../core/display.js";
20 import * as WebUtil
from "./webutil.js";
28 hideKeyboardTimeout
: null,
29 idleControlbarTimeout
: null,
30 closeControlbarTimeout
: null,
32 controlbarGrabbed
: false,
33 controlbarDrag
: false,
34 controlbarMouseDownClientY
: 0,
35 controlbarMouseDownOffsetY
: 0,
38 lastKeyboardinput
: null,
39 defaultKeyboardinputLen
: 100,
41 inhibit_reconnect
: true,
42 reconnect_callback
: null,
43 reconnect_password
: null,
45 prime: function(callback
) {
46 if (document
.readyState
=== "interactive" || document
.readyState
=== "complete") {
49 document
.addEventListener('DOMContentLoaded', UI
.load
.bind(UI
, callback
));
53 // Setup rfb object, load settings from browser storage, then call
54 // UI.init to setup the UI/menus
55 load: function(callback
) {
56 WebUtil
.initSettings(UI
.start
, callback
);
59 // Render default UI and initialize settings menu
60 start: function(callback
) {
62 // Setup global variables first
63 UI
.isSafari
= (navigator
.userAgent
.indexOf('Safari') !== -1 &&
64 navigator
.userAgent
.indexOf('Chrome') === -1);
71 // Adapt the interface for touch screen devices
73 document
.documentElement
.classList
.add("noVNC_touch");
74 // Remove the address bar
75 setTimeout(function() { window
.scrollTo(0, 1); }, 100);
78 // Restore control bar position
79 if (WebUtil
.readSetting('controlbar_pos') === 'right') {
80 UI
.toggleControlbarSide();
85 // Setup event handlers
86 UI
.addControlbarHandlers();
87 UI
.addTouchSpecificHandlers();
88 UI
.addExtraKeysHandlers();
89 UI
.addMachineHandlers();
90 UI
.addConnectionControlHandlers();
91 UI
.addClipboardHandlers();
92 UI
.addSettingsHandlers();
93 document
.getElementById("noVNC_status")
94 .addEventListener('click', UI
.hideStatus
);
96 // Bootstrap fallback input handler
97 UI
.keyboardinputReset();
101 UI
.updateVisualState('init');
103 document
.documentElement
.classList
.remove("noVNC_loading");
105 var autoconnect
= WebUtil
.getConfigVar('autoconnect', false);
106 if (autoconnect
=== 'true' || autoconnect
== '1') {
111 // Show the connect panel on first load unless autoconnecting
112 UI
.openConnectPanel();
115 if (typeof callback
=== "function") {
120 initFullscreen: function() {
121 // Only show the button if fullscreen is properly supported
122 // * Safari doesn't support alphanumerical input while in fullscreen
124 (document
.documentElement
.requestFullscreen
||
125 document
.documentElement
.mozRequestFullScreen
||
126 document
.documentElement
.webkitRequestFullscreen
||
127 document
.body
.msRequestFullscreen
)) {
128 document
.getElementById('noVNC_fullscreen_button')
129 .classList
.remove("noVNC_hidden");
130 UI
.addFullscreenHandlers();
134 initSettings: function() {
137 // Logging selection dropdown
138 var llevels
= ['error', 'warn', 'info', 'debug'];
139 for (i
= 0; i
< llevels
.length
; i
+= 1) {
140 UI
.addOption(document
.getElementById('noVNC_setting_logging'),llevels
[i
], llevels
[i
]);
143 // Settings with immediate effects
144 UI
.initSetting('logging', 'warn');
147 // if port == 80 (or 443) then it won't be present and should be
149 var port
= window
.location
.port
;
151 if (window
.location
.protocol
.substring(0,5) == 'https') {
154 else if (window
.location
.protocol
.substring(0,4) == 'http') {
159 /* Populate the controls if defaults are provided in the URL */
160 UI
.initSetting('host', window
.location
.hostname
);
161 UI
.initSetting('port', port
);
162 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
163 UI
.initSetting('view_clip', false);
164 UI
.initSetting('resize', 'off');
165 UI
.initSetting('shared', true);
166 UI
.initSetting('view_only', false);
167 UI
.initSetting('path', 'websockify');
168 UI
.initSetting('repeaterID', '');
169 UI
.initSetting('reconnect', false);
170 UI
.initSetting('reconnect_delay', 5000);
172 UI
.setupSettingLabels();
174 // Adds a link to the label elements on the corresponding input elements
175 setupSettingLabels: function() {
176 var labels
= document
.getElementsByTagName('LABEL');
177 for (var i
= 0; i
< labels
.length
; i
++) {
178 var htmlFor
= labels
[i
].htmlFor
;
180 var elem
= document
.getElementById(htmlFor
);
181 if (elem
) elem
.label
= labels
[i
];
183 // If 'for' isn't set, use the first input element child
184 var children
= labels
[i
].children
;
185 for (var j
= 0; j
< children
.length
; j
++) {
186 if (children
[j
].form
!== undefined) {
187 children
[j
].label
= labels
[i
];
201 addControlbarHandlers: function() {
202 document
.getElementById("noVNC_control_bar")
203 .addEventListener('mousemove', UI
.activateControlbar
);
204 document
.getElementById("noVNC_control_bar")
205 .addEventListener('mouseup', UI
.activateControlbar
);
206 document
.getElementById("noVNC_control_bar")
207 .addEventListener('mousedown', UI
.activateControlbar
);
208 document
.getElementById("noVNC_control_bar")
209 .addEventListener('keydown', UI
.activateControlbar
);
211 document
.getElementById("noVNC_control_bar")
212 .addEventListener('mousedown', UI
.keepControlbar
);
213 document
.getElementById("noVNC_control_bar")
214 .addEventListener('keydown', UI
.keepControlbar
);
216 document
.getElementById("noVNC_view_drag_button")
217 .addEventListener('click', UI
.toggleViewDrag
);
219 document
.getElementById("noVNC_control_bar_handle")
220 .addEventListener('mousedown', UI
.controlbarHandleMouseDown
);
221 document
.getElementById("noVNC_control_bar_handle")
222 .addEventListener('mouseup', UI
.controlbarHandleMouseUp
);
223 document
.getElementById("noVNC_control_bar_handle")
224 .addEventListener('mousemove', UI
.dragControlbarHandle
);
225 // resize events aren't available for elements
226 window
.addEventListener('resize', UI
.updateControlbarHandle
);
228 var exps
= document
.getElementsByClassName("noVNC_expander");
229 for (var i
= 0;i
< exps
.length
;i
++) {
230 exps
[i
].addEventListener('click', UI
.toggleExpander
);
234 addTouchSpecificHandlers: function() {
235 document
.getElementById("noVNC_mouse_button0")
236 .addEventListener('click', function () { UI
.setMouseButton(1); });
237 document
.getElementById("noVNC_mouse_button1")
238 .addEventListener('click', function () { UI
.setMouseButton(2); });
239 document
.getElementById("noVNC_mouse_button2")
240 .addEventListener('click', function () { UI
.setMouseButton(4); });
241 document
.getElementById("noVNC_mouse_button4")
242 .addEventListener('click', function () { UI
.setMouseButton(0); });
243 document
.getElementById("noVNC_keyboard_button")
244 .addEventListener('click', UI
.toggleVirtualKeyboard
);
246 UI
.touchKeyboard
= new Keyboard(document
.getElementById('noVNC_keyboardinput'));
247 UI
.touchKeyboard
.onkeyevent
= UI
.keyEvent
;
248 UI
.touchKeyboard
.grab();
249 document
.getElementById("noVNC_keyboardinput")
250 .addEventListener('input', UI
.keyInput
);
251 document
.getElementById("noVNC_keyboardinput")
252 .addEventListener('focus', UI
.onfocusVirtualKeyboard
);
253 document
.getElementById("noVNC_keyboardinput")
254 .addEventListener('blur', UI
.onblurVirtualKeyboard
);
255 document
.getElementById("noVNC_keyboardinput")
256 .addEventListener('submit', function () { return false; });
258 document
.documentElement
259 .addEventListener('mousedown', UI
.keepVirtualKeyboard
, true);
261 document
.getElementById("noVNC_control_bar")
262 .addEventListener('touchstart', UI
.activateControlbar
);
263 document
.getElementById("noVNC_control_bar")
264 .addEventListener('touchmove', UI
.activateControlbar
);
265 document
.getElementById("noVNC_control_bar")
266 .addEventListener('touchend', UI
.activateControlbar
);
267 document
.getElementById("noVNC_control_bar")
268 .addEventListener('input', UI
.activateControlbar
);
270 document
.getElementById("noVNC_control_bar")
271 .addEventListener('touchstart', UI
.keepControlbar
);
272 document
.getElementById("noVNC_control_bar")
273 .addEventListener('input', UI
.keepControlbar
);
275 document
.getElementById("noVNC_control_bar_handle")
276 .addEventListener('touchstart', UI
.controlbarHandleMouseDown
);
277 document
.getElementById("noVNC_control_bar_handle")
278 .addEventListener('touchend', UI
.controlbarHandleMouseUp
);
279 document
.getElementById("noVNC_control_bar_handle")
280 .addEventListener('touchmove', UI
.dragControlbarHandle
);
283 addExtraKeysHandlers: function() {
284 document
.getElementById("noVNC_toggle_extra_keys_button")
285 .addEventListener('click', UI
.toggleExtraKeys
);
286 document
.getElementById("noVNC_toggle_ctrl_button")
287 .addEventListener('click', UI
.toggleCtrl
);
288 document
.getElementById("noVNC_toggle_alt_button")
289 .addEventListener('click', UI
.toggleAlt
);
290 document
.getElementById("noVNC_send_tab_button")
291 .addEventListener('click', UI
.sendTab
);
292 document
.getElementById("noVNC_send_esc_button")
293 .addEventListener('click', UI
.sendEsc
);
294 document
.getElementById("noVNC_send_ctrl_alt_del_button")
295 .addEventListener('click', UI
.sendCtrlAltDel
);
298 addMachineHandlers: function() {
299 document
.getElementById("noVNC_shutdown_button")
300 .addEventListener('click', function() { UI
.rfb
.machineShutdown(); });
301 document
.getElementById("noVNC_reboot_button")
302 .addEventListener('click', function() { UI
.rfb
.machineReboot(); });
303 document
.getElementById("noVNC_reset_button")
304 .addEventListener('click', function() { UI
.rfb
.machineReset(); });
305 document
.getElementById("noVNC_power_button")
306 .addEventListener('click', UI
.togglePowerPanel
);
309 addConnectionControlHandlers: function() {
310 document
.getElementById("noVNC_disconnect_button")
311 .addEventListener('click', UI
.disconnect
);
312 document
.getElementById("noVNC_connect_button")
313 .addEventListener('click', UI
.connect
);
314 document
.getElementById("noVNC_cancel_reconnect_button")
315 .addEventListener('click', UI
.cancelReconnect
);
317 document
.getElementById("noVNC_password_button")
318 .addEventListener('click', UI
.setPassword
);
321 addClipboardHandlers: function() {
322 document
.getElementById("noVNC_clipboard_button")
323 .addEventListener('click', UI
.toggleClipboardPanel
);
324 document
.getElementById("noVNC_clipboard_text")
325 .addEventListener('change', UI
.clipboardSend
);
326 document
.getElementById("noVNC_clipboard_clear_button")
327 .addEventListener('click', UI
.clipboardClear
);
330 // Add a call to save settings when the element changes,
331 // unless the optional parameter changeFunc is used instead.
332 addSettingChangeHandler: function(name
, changeFunc
) {
333 var settingElem
= document
.getElementById("noVNC_setting_" + name
);
334 if (changeFunc
=== undefined) {
335 changeFunc = function () { UI
.saveSetting(name
); };
337 settingElem
.addEventListener('change', changeFunc
);
340 addSettingsHandlers: function() {
341 document
.getElementById("noVNC_settings_button")
342 .addEventListener('click', UI
.toggleSettingsPanel
);
344 UI
.addSettingChangeHandler('encrypt');
345 UI
.addSettingChangeHandler('resize');
346 UI
.addSettingChangeHandler('resize', UI
.enableDisableViewClip
);
347 UI
.addSettingChangeHandler('resize', UI
.applyResizeMode
);
348 UI
.addSettingChangeHandler('view_clip');
349 UI
.addSettingChangeHandler('view_clip', UI
.updateViewClip
);
350 UI
.addSettingChangeHandler('shared');
351 UI
.addSettingChangeHandler('view_only');
352 UI
.addSettingChangeHandler('view_only', UI
.updateViewOnly
);
353 UI
.addSettingChangeHandler('host');
354 UI
.addSettingChangeHandler('port');
355 UI
.addSettingChangeHandler('path');
356 UI
.addSettingChangeHandler('repeaterID');
357 UI
.addSettingChangeHandler('logging');
358 UI
.addSettingChangeHandler('logging', UI
.updateLogging
);
359 UI
.addSettingChangeHandler('reconnect');
360 UI
.addSettingChangeHandler('reconnect_delay');
363 addFullscreenHandlers: function() {
364 document
.getElementById("noVNC_fullscreen_button")
365 .addEventListener('click', UI
.toggleFullscreen
);
367 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
368 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
369 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
370 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
379 // Disable/enable controls depending on connection state
380 updateVisualState: function(state
) {
382 document
.documentElement
.classList
.remove("noVNC_connecting");
383 document
.documentElement
.classList
.remove("noVNC_connected");
384 document
.documentElement
.classList
.remove("noVNC_disconnecting");
385 document
.documentElement
.classList
.remove("noVNC_reconnecting");
387 let transition_elem
= document
.getElementById("noVNC_transition_text");
392 transition_elem
.textContent
= _("Connecting...");
393 document
.documentElement
.classList
.add("noVNC_connecting");
396 document
.documentElement
.classList
.add("noVNC_connected");
398 case 'disconnecting':
399 transition_elem
.textContent
= _("Disconnecting...");
400 document
.documentElement
.classList
.add("noVNC_disconnecting");
405 transition_elem
.textContent
= _("Reconnecting...");
406 document
.documentElement
.classList
.add("noVNC_reconnecting");
409 Log
.Error("Invalid visual state: " + state
);
410 UI
.showStatus(_("Internal error"), 'error');
414 UI
.enableDisableViewClip();
417 UI
.disableSetting('encrypt');
418 UI
.disableSetting('shared');
419 UI
.disableSetting('host');
420 UI
.disableSetting('port');
421 UI
.disableSetting('path');
422 UI
.disableSetting('repeaterID');
423 UI
.setMouseButton(1);
425 // Hide the controlbar after 2 seconds
426 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
428 UI
.enableSetting('encrypt');
429 UI
.enableSetting('shared');
430 UI
.enableSetting('host');
431 UI
.enableSetting('port');
432 UI
.enableSetting('path');
433 UI
.enableSetting('repeaterID');
434 UI
.updatePowerButton();
438 // State change disables viewport dragging.
439 // It is enabled (toggled) by direct click on the button
440 UI
.setViewDrag(false);
442 // State change also closes the password dialog
443 document
.getElementById('noVNC_password_dlg')
444 .classList
.remove('noVNC_open');
447 showStatus: function(text
, status_type
, time
) {
448 var statusElem
= document
.getElementById('noVNC_status');
450 clearTimeout(UI
.statusTimeout
);
452 if (typeof status_type
=== 'undefined') {
453 status_type
= 'normal';
456 // Don't overwrite more severe visible statuses and never
457 // errors. Only shows the first error.
458 let visible_status_type
= 'none';
459 if (statusElem
.classList
.contains("noVNC_open")) {
460 if (statusElem
.classList
.contains("noVNC_status_error")) {
461 visible_status_type
= 'error';
462 } else if (statusElem
.classList
.contains("noVNC_status_warn")) {
463 visible_status_type
= 'warn';
465 visible_status_type
= 'normal';
468 if (visible_status_type
=== 'error' ||
469 (visible_status_type
=== 'warn' && status_type
=== 'normal')) {
473 switch (status_type
) {
475 statusElem
.classList
.remove("noVNC_status_warn");
476 statusElem
.classList
.remove("noVNC_status_normal");
477 statusElem
.classList
.add("noVNC_status_error");
481 statusElem
.classList
.remove("noVNC_status_error");
482 statusElem
.classList
.remove("noVNC_status_normal");
483 statusElem
.classList
.add("noVNC_status_warn");
488 statusElem
.classList
.remove("noVNC_status_error");
489 statusElem
.classList
.remove("noVNC_status_warn");
490 statusElem
.classList
.add("noVNC_status_normal");
494 statusElem
.textContent
= text
;
495 statusElem
.classList
.add("noVNC_open");
497 // If no time was specified, show the status for 1.5 seconds
498 if (typeof time
=== 'undefined') {
502 // Error messages do not timeout
503 if (status_type
!== 'error') {
504 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
508 hideStatus: function() {
509 clearTimeout(UI
.statusTimeout
);
510 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
513 activateControlbar: function(event
) {
514 clearTimeout(UI
.idleControlbarTimeout
);
515 // We manipulate the anchor instead of the actual control
516 // bar in order to avoid creating new a stacking group
517 document
.getElementById('noVNC_control_bar_anchor')
518 .classList
.remove("noVNC_idle");
519 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
522 idleControlbar: function() {
523 document
.getElementById('noVNC_control_bar_anchor')
524 .classList
.add("noVNC_idle");
527 keepControlbar: function() {
528 clearTimeout(UI
.closeControlbarTimeout
);
531 openControlbar: function() {
532 document
.getElementById('noVNC_control_bar')
533 .classList
.add("noVNC_open");
536 closeControlbar: function() {
538 document
.getElementById('noVNC_control_bar')
539 .classList
.remove("noVNC_open");
542 toggleControlbar: function() {
543 if (document
.getElementById('noVNC_control_bar')
544 .classList
.contains("noVNC_open")) {
545 UI
.closeControlbar();
551 toggleControlbarSide: function () {
552 // Temporarily disable animation to avoid weird movement
553 var bar
= document
.getElementById('noVNC_control_bar');
554 bar
.style
.transitionDuration
= '0s';
555 bar
.addEventListener('transitionend', function () { this.style
.transitionDuration
= ""; });
557 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
558 if (anchor
.classList
.contains("noVNC_right")) {
559 WebUtil
.writeSetting('controlbar_pos', 'left');
560 anchor
.classList
.remove("noVNC_right");
562 WebUtil
.writeSetting('controlbar_pos', 'right');
563 anchor
.classList
.add("noVNC_right");
566 // Consider this a movement of the handle
567 UI
.controlbarDrag
= true;
570 showControlbarHint: function (show
) {
571 var hint
= document
.getElementById('noVNC_control_bar_hint');
573 hint
.classList
.add("noVNC_active");
575 hint
.classList
.remove("noVNC_active");
579 dragControlbarHandle: function (e
) {
580 if (!UI
.controlbarGrabbed
) return;
582 var ptr
= getPointerEvent(e
);
584 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
585 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
586 if (anchor
.classList
.contains("noVNC_right")) {
587 UI
.toggleControlbarSide();
589 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
590 if (!anchor
.classList
.contains("noVNC_right")) {
591 UI
.toggleControlbarSide();
595 if (!UI
.controlbarDrag
) {
596 // The goal is to trigger on a certain physical width, the
597 // devicePixelRatio brings us a bit closer but is not optimal.
598 var dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
599 var dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
601 if (dragDistance
< dragThreshold
) return;
603 UI
.controlbarDrag
= true;
606 var eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
608 UI
.moveControlbarHandle(eventY
);
613 UI
.activateControlbar();
616 // Move the handle but don't allow any position outside the bounds
617 moveControlbarHandle: function (viewportRelativeY
) {
618 var handle
= document
.getElementById("noVNC_control_bar_handle");
619 var handleHeight
= handle
.getBoundingClientRect().height
;
620 var controlbarBounds
= document
.getElementById("noVNC_control_bar")
621 .getBoundingClientRect();
624 // These heights need to be non-zero for the below logic to work
625 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
629 var newY
= viewportRelativeY
;
631 // Check if the coordinates are outside the control bar
632 if (newY
< controlbarBounds
.top
+ margin
) {
633 // Force coordinates to be below the top of the control bar
634 newY
= controlbarBounds
.top
+ margin
;
636 } else if (newY
> controlbarBounds
.top
+
637 controlbarBounds
.height
- handleHeight
- margin
) {
638 // Force coordinates to be above the bottom of the control bar
639 newY
= controlbarBounds
.top
+
640 controlbarBounds
.height
- handleHeight
- margin
;
643 // Corner case: control bar too small for stable position
644 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
645 newY
= controlbarBounds
.top
+
646 (controlbarBounds
.height
- handleHeight
) / 2;
649 // The transform needs coordinates that are relative to the parent
650 var parentRelativeY
= newY
- controlbarBounds
.top
;
651 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
654 updateControlbarHandle: function () {
655 // Since the control bar is fixed on the viewport and not the page,
656 // the move function expects coordinates relative the the viewport.
657 var handle
= document
.getElementById("noVNC_control_bar_handle");
658 var handleBounds
= handle
.getBoundingClientRect();
659 UI
.moveControlbarHandle(handleBounds
.top
);
662 controlbarHandleMouseUp: function(e
) {
663 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
665 // mouseup and mousedown on the same place toggles the controlbar
666 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
667 UI
.toggleControlbar();
671 UI
.activateControlbar();
673 UI
.controlbarGrabbed
= false;
674 UI
.showControlbarHint(false);
677 controlbarHandleMouseDown: function(e
) {
678 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
680 var ptr
= getPointerEvent(e
);
682 var handle
= document
.getElementById("noVNC_control_bar_handle");
683 var bounds
= handle
.getBoundingClientRect();
685 // Touch events have implicit capture
686 if (e
.type
=== "mousedown") {
690 UI
.controlbarGrabbed
= true;
691 UI
.controlbarDrag
= false;
693 UI
.showControlbarHint(true);
695 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
696 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
700 UI
.activateControlbar();
703 toggleExpander: function(e
) {
704 if (this.classList
.contains("noVNC_open")) {
705 this.classList
.remove("noVNC_open");
707 this.classList
.add("noVNC_open");
717 // Initial page load read/initialization of settings
718 initSetting: function(name
, defVal
) {
719 // Check Query string followed by cookie
720 var val
= WebUtil
.getConfigVar(name
);
722 val
= WebUtil
.readSetting(name
, defVal
);
724 UI
.updateSetting(name
, val
);
728 // Update cookie and form control setting. If value is not set, then
729 // updates from control to current cookie setting.
730 updateSetting: function(name
, value
) {
732 // Save the cookie for this session
733 if (typeof value
!== 'undefined') {
734 WebUtil
.writeSetting(name
, value
);
737 // Update the settings control
738 value
= UI
.getSetting(name
);
740 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
741 if (ctrl
.type
=== 'checkbox') {
742 ctrl
.checked
= value
;
744 } else if (typeof ctrl
.options
!== 'undefined') {
745 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
746 if (ctrl
.options
[i
].value
=== value
) {
747 ctrl
.selectedIndex
= i
;
752 /*Weird IE9 error leads to 'null' appearring
753 in textboxes instead of ''.*/
754 if (value
=== null) {
761 // Save control setting to cookie
762 saveSetting: function(name
) {
763 var val
, ctrl
= document
.getElementById('noVNC_setting_' + name
);
764 if (ctrl
.type
=== 'checkbox') {
766 } else if (typeof ctrl
.options
!== 'undefined') {
767 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
771 WebUtil
.writeSetting(name
, val
);
772 //Log.Debug("Setting saved '" + name + "=" + val + "'");
776 // Read form control compatible setting from cookie
777 getSetting: function(name
) {
778 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
779 var val
= WebUtil
.readSetting(name
);
780 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
781 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
790 // These helpers compensate for the lack of parent-selectors and
791 // previous-sibling-selectors in CSS which are needed when we want to
792 // disable the labels that belong to disabled input elements.
793 disableSetting: function(name
) {
794 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
795 ctrl
.disabled
= true;
796 ctrl
.label
.classList
.add('noVNC_disabled');
799 enableSetting: function(name
) {
800 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
801 ctrl
.disabled
= false;
802 ctrl
.label
.classList
.remove('noVNC_disabled');
811 closeAllPanels: function() {
812 UI
.closeSettingsPanel();
813 UI
.closePowerPanel();
814 UI
.closeClipboardPanel();
824 openSettingsPanel: function() {
828 // Refresh UI elements from saved cookies
829 UI
.updateSetting('encrypt');
830 UI
.updateSetting('view_clip');
831 UI
.updateSetting('resize');
832 UI
.updateSetting('shared');
833 UI
.updateSetting('view_only');
834 UI
.updateSetting('path');
835 UI
.updateSetting('repeaterID');
836 UI
.updateSetting('logging');
837 UI
.updateSetting('reconnect');
838 UI
.updateSetting('reconnect_delay');
840 document
.getElementById('noVNC_settings')
841 .classList
.add("noVNC_open");
842 document
.getElementById('noVNC_settings_button')
843 .classList
.add("noVNC_selected");
846 closeSettingsPanel: function() {
847 document
.getElementById('noVNC_settings')
848 .classList
.remove("noVNC_open");
849 document
.getElementById('noVNC_settings_button')
850 .classList
.remove("noVNC_selected");
853 toggleSettingsPanel: function() {
854 if (document
.getElementById('noVNC_settings')
855 .classList
.contains("noVNC_open")) {
856 UI
.closeSettingsPanel();
858 UI
.openSettingsPanel();
868 openPowerPanel: function() {
872 document
.getElementById('noVNC_power')
873 .classList
.add("noVNC_open");
874 document
.getElementById('noVNC_power_button')
875 .classList
.add("noVNC_selected");
878 closePowerPanel: function() {
879 document
.getElementById('noVNC_power')
880 .classList
.remove("noVNC_open");
881 document
.getElementById('noVNC_power_button')
882 .classList
.remove("noVNC_selected");
885 togglePowerPanel: function() {
886 if (document
.getElementById('noVNC_power')
887 .classList
.contains("noVNC_open")) {
888 UI
.closePowerPanel();
894 // Disable/enable power button
895 updatePowerButton: function() {
897 UI
.rfb
.capabilities
.power
&&
899 document
.getElementById('noVNC_power_button')
900 .classList
.remove("noVNC_hidden");
902 document
.getElementById('noVNC_power_button')
903 .classList
.add("noVNC_hidden");
904 // Close power panel if open
905 UI
.closePowerPanel();
915 openClipboardPanel: function() {
919 document
.getElementById('noVNC_clipboard')
920 .classList
.add("noVNC_open");
921 document
.getElementById('noVNC_clipboard_button')
922 .classList
.add("noVNC_selected");
925 closeClipboardPanel: function() {
926 document
.getElementById('noVNC_clipboard')
927 .classList
.remove("noVNC_open");
928 document
.getElementById('noVNC_clipboard_button')
929 .classList
.remove("noVNC_selected");
932 toggleClipboardPanel: function() {
933 if (document
.getElementById('noVNC_clipboard')
934 .classList
.contains("noVNC_open")) {
935 UI
.closeClipboardPanel();
937 UI
.openClipboardPanel();
941 clipboardReceive: function(e
) {
942 Log
.Debug(">> UI.clipboardReceive: " + e
.detail
.text
.substr(0,40) + "...");
943 document
.getElementById('noVNC_clipboard_text').value
= e
.detail
.text
;
944 Log
.Debug("<< UI.clipboardReceive");
947 clipboardClear: function() {
948 document
.getElementById('noVNC_clipboard_text').value
= "";
949 UI
.rfb
.clipboardPasteFrom("");
952 clipboardSend: function() {
953 var text
= document
.getElementById('noVNC_clipboard_text').value
;
954 Log
.Debug(">> UI.clipboardSend: " + text
.substr(0,40) + "...");
955 UI
.rfb
.clipboardPasteFrom(text
);
956 Log
.Debug("<< UI.clipboardSend");
965 openConnectPanel: function() {
966 document
.getElementById('noVNC_connect_dlg')
967 .classList
.add("noVNC_open");
970 closeConnectPanel: function() {
971 document
.getElementById('noVNC_connect_dlg')
972 .classList
.remove("noVNC_open");
975 connect: function(event
, password
) {
977 // Ignore when rfb already exists
978 if (typeof UI
.rfb
!== 'undefined') {
982 var host
= UI
.getSetting('host');
983 var port
= UI
.getSetting('port');
984 var path
= UI
.getSetting('path');
986 if (typeof password
=== 'undefined') {
987 password
= WebUtil
.getConfigVar('password');
988 UI
.reconnect_password
= password
;
991 if (password
=== null) {
992 password
= undefined;
998 Log
.Error("Can't connect when host is: " + host
);
999 UI
.showStatus(_("Must set host"), 'error');
1003 UI
.closeAllPanels();
1004 UI
.closeConnectPanel();
1006 UI
.updateVisualState('connecting');
1010 url
= UI
.getSetting('encrypt') ? 'wss' : 'ws';
1012 url
+= '://' + host
;
1018 UI
.rfb
= new RFB(document
.getElementById('noVNC_container'), url
,
1019 { shared
: UI
.getSetting('shared'),
1020 repeaterID
: UI
.getSetting('repeaterID'),
1021 credentials
: { password
: password
} });
1022 UI
.rfb
.addEventListener("connect", UI
.connectFinished
);
1023 UI
.rfb
.addEventListener("disconnect", UI
.disconnectFinished
);
1024 UI
.rfb
.addEventListener("credentialsrequired", UI
.credentials
);
1025 UI
.rfb
.addEventListener("securityfailure", UI
.securityFailed
);
1026 UI
.rfb
.addEventListener("capabilities", function () { UI
.updatePowerButton(); });
1027 UI
.rfb
.addEventListener("clipboard", UI
.clipboardReceive
);
1028 UI
.rfb
.addEventListener("bell", UI
.bell
);
1029 UI
.rfb
.addEventListener("desktopname", UI
.updateDesktopName
);
1030 UI
.rfb
.clipViewport
= UI
.getSetting('view_clip');
1031 UI
.rfb
.scaleViewport
= UI
.getSetting('resize') === 'scale';
1032 UI
.rfb
.resizeSession
= UI
.getSetting('resize') === 'remote';
1034 UI
.updateViewOnly(); // requires UI.rfb
1037 disconnect: function() {
1038 UI
.closeAllPanels();
1039 UI
.rfb
.disconnect();
1041 UI
.connected
= false;
1043 // Disable automatic reconnecting
1044 UI
.inhibit_reconnect
= true;
1046 UI
.updateVisualState('disconnecting');
1048 // Don't display the connection settings until we're actually disconnected
1051 reconnect: function() {
1052 UI
.reconnect_callback
= null;
1054 // if reconnect has been disabled in the meantime, do nothing.
1055 if (UI
.inhibit_reconnect
) {
1059 UI
.connect(null, UI
.reconnect_password
);
1062 cancelReconnect: function() {
1063 if (UI
.reconnect_callback
!== null) {
1064 clearTimeout(UI
.reconnect_callback
);
1065 UI
.reconnect_callback
= null;
1068 UI
.updateVisualState('disconnected');
1070 UI
.openControlbar();
1071 UI
.openConnectPanel();
1074 connectFinished: function (e
) {
1075 UI
.connected
= true;
1076 UI
.inhibit_reconnect
= false;
1079 if (UI
.getSetting('encrypt')) {
1080 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
1082 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
1085 UI
.updateVisualState('connected');
1087 // Do this last because it can only be used on rendered elements
1091 disconnectFinished: function (e
) {
1092 let wasConnected
= UI
.connected
;
1094 // This variable is ideally set when disconnection starts, but
1095 // when the disconnection isn't clean or if it is initiated by
1096 // the server, we need to do it here as well since
1097 // UI.disconnect() won't be used in those cases.
1098 UI
.connected
= false;
1102 if (!e
.detail
.clean
) {
1103 UI
.updateVisualState('disconnected');
1105 UI
.showStatus(_("Something went wrong, connection is closed"),
1108 UI
.showStatus(_("Failed to connect to server"), 'error');
1110 } else if (UI
.getSetting('reconnect', false) === true && !UI
.inhibit_reconnect
) {
1111 UI
.updateVisualState('reconnecting');
1113 var delay
= parseInt(UI
.getSetting('reconnect_delay'));
1114 UI
.reconnect_callback
= setTimeout(UI
.reconnect
, delay
);
1117 UI
.updateVisualState('disconnected');
1118 UI
.showStatus(_("Disconnected"), 'normal');
1121 UI
.openControlbar();
1122 UI
.openConnectPanel();
1125 securityFailed: function (e
) {
1127 // On security failures we might get a string with a reason
1128 // directly from the server. Note that we can't control if
1129 // this string is translated or not.
1130 if ('reason' in e
.detail
) {
1131 msg
= _("New connection has been rejected with reason: ") +
1134 msg
= _("New connection has been rejected");
1136 UI
.showStatus(msg
, 'error');
1145 credentials: function(e
) {
1146 // FIXME: handle more types
1147 document
.getElementById('noVNC_password_dlg')
1148 .classList
.add('noVNC_open');
1150 setTimeout(function () {
1151 document
.getElementById('noVNC_password_input').focus();
1154 Log
.Warn("Server asked for a password");
1155 UI
.showStatus(_("Password is required"), "warning");
1158 setPassword: function(e
) {
1159 // Prevent actually submitting the form
1162 var inputElem
= document
.getElementById('noVNC_password_input');
1163 var password
= inputElem
.value
;
1164 // Clear the input after reading the password
1165 inputElem
.value
= "";
1166 UI
.rfb
.sendCredentials({ password
: password
});
1167 UI
.reconnect_password
= password
;
1168 document
.getElementById('noVNC_password_dlg')
1169 .classList
.remove('noVNC_open');
1178 toggleFullscreen: function() {
1179 if (document
.fullscreenElement
|| // alternative standard method
1180 document
.mozFullScreenElement
|| // currently working methods
1181 document
.webkitFullscreenElement
||
1182 document
.msFullscreenElement
) {
1183 if (document
.exitFullscreen
) {
1184 document
.exitFullscreen();
1185 } else if (document
.mozCancelFullScreen
) {
1186 document
.mozCancelFullScreen();
1187 } else if (document
.webkitExitFullscreen
) {
1188 document
.webkitExitFullscreen();
1189 } else if (document
.msExitFullscreen
) {
1190 document
.msExitFullscreen();
1193 if (document
.documentElement
.requestFullscreen
) {
1194 document
.documentElement
.requestFullscreen();
1195 } else if (document
.documentElement
.mozRequestFullScreen
) {
1196 document
.documentElement
.mozRequestFullScreen();
1197 } else if (document
.documentElement
.webkitRequestFullscreen
) {
1198 document
.documentElement
.webkitRequestFullscreen(Element
.ALLOW_KEYBOARD_INPUT
);
1199 } else if (document
.body
.msRequestFullscreen
) {
1200 document
.body
.msRequestFullscreen();
1203 UI
.enableDisableViewClip();
1204 UI
.updateFullscreenButton();
1207 updateFullscreenButton: function() {
1208 if (document
.fullscreenElement
|| // alternative standard method
1209 document
.mozFullScreenElement
|| // currently working methods
1210 document
.webkitFullscreenElement
||
1211 document
.msFullscreenElement
) {
1212 document
.getElementById('noVNC_fullscreen_button')
1213 .classList
.add("noVNC_selected");
1215 document
.getElementById('noVNC_fullscreen_button')
1216 .classList
.remove("noVNC_selected");
1226 // Apply remote resizing or local scaling
1227 applyResizeMode: function() {
1228 if (!UI
.rfb
) return;
1230 UI
.rfb
.scaleViewport
= UI
.getSetting('resize') === 'scale';
1231 UI
.rfb
.resizeSession
= UI
.getSetting('resize') === 'remote';
1240 // Update parameters that depend on the viewport clip setting
1241 updateViewClip: function() {
1242 if (!UI
.rfb
) return;
1244 var cur_clip
= UI
.rfb
.clipViewport
;
1245 var new_clip
= UI
.getSetting('view_clip');
1247 if (isTouchDevice
) {
1248 // Touch devices usually have shit scrollbars
1252 if (cur_clip
!== new_clip
) {
1253 UI
.rfb
.clipViewport
= new_clip
;
1256 // Changing the viewport may change the state of
1257 // the dragging button
1258 UI
.updateViewDrag();
1261 // Handle special cases where viewport clipping is forced on/off or locked
1262 enableDisableViewClip: function() {
1263 var resizeSetting
= UI
.getSetting('resize');
1264 // Disable clipping if we are scaling, connected or on touch
1265 if (resizeSetting
=== 'scale' ||
1267 UI
.disableSetting('view_clip');
1269 UI
.enableSetting('view_clip');
1279 toggleViewDrag: function() {
1280 if (!UI
.rfb
) return;
1282 var drag
= UI
.rfb
.dragViewport
;
1283 UI
.setViewDrag(!drag
);
1286 // Set the view drag mode which moves the viewport on mouse drags
1287 setViewDrag: function(drag
) {
1288 if (!UI
.rfb
) return;
1290 UI
.rfb
.dragViewport
= drag
;
1292 UI
.updateViewDrag();
1295 updateViewDrag: function() {
1296 if (!UI
.connected
) return;
1298 var viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1300 if (!UI
.rfb
.clipViewport
&& UI
.rfb
.dragViewport
) {
1301 // We are no longer clipping the viewport. Make sure
1302 // viewport drag isn't active when it can't be used.
1303 UI
.rfb
.dragViewport
= false;
1306 if (UI
.rfb
.dragViewport
) {
1307 viewDragButton
.classList
.add("noVNC_selected");
1309 viewDragButton
.classList
.remove("noVNC_selected");
1312 // Different behaviour for touch vs non-touch
1313 // The button is disabled instead of hidden on touch devices
1314 if (isTouchDevice
) {
1315 viewDragButton
.classList
.remove("noVNC_hidden");
1317 if (UI
.rfb
.clipViewport
) {
1318 viewDragButton
.disabled
= false;
1320 viewDragButton
.disabled
= true;
1323 viewDragButton
.disabled
= false;
1325 if (UI
.rfb
.clipViewport
) {
1326 viewDragButton
.classList
.remove("noVNC_hidden");
1328 viewDragButton
.classList
.add("noVNC_hidden");
1339 showVirtualKeyboard: function() {
1340 if (!isTouchDevice
) return;
1342 var input
= document
.getElementById('noVNC_keyboardinput');
1344 if (document
.activeElement
== input
) return;
1349 var l
= input
.value
.length
;
1350 // Move the caret to the end
1351 input
.setSelectionRange(l
, l
);
1352 } catch (err
) {} // setSelectionRange is undefined in Google Chrome
1355 hideVirtualKeyboard: function() {
1356 if (!isTouchDevice
) return;
1358 var input
= document
.getElementById('noVNC_keyboardinput');
1360 if (document
.activeElement
!= input
) return;
1365 toggleVirtualKeyboard: function () {
1366 if (document
.getElementById('noVNC_keyboard_button')
1367 .classList
.contains("noVNC_selected")) {
1368 UI
.hideVirtualKeyboard();
1370 UI
.showVirtualKeyboard();
1374 onfocusVirtualKeyboard: function(event
) {
1375 document
.getElementById('noVNC_keyboard_button')
1376 .classList
.add("noVNC_selected");
1378 UI
.rfb
.focusOnClick
= false;
1382 onblurVirtualKeyboard: function(event
) {
1383 document
.getElementById('noVNC_keyboard_button')
1384 .classList
.remove("noVNC_selected");
1386 UI
.rfb
.focusOnClick
= true;
1390 keepVirtualKeyboard: function(event
) {
1391 var input
= document
.getElementById('noVNC_keyboardinput');
1393 // Only prevent focus change if the virtual keyboard is active
1394 if (document
.activeElement
!= input
) {
1398 // Only allow focus to move to other elements that need
1399 // focus to function properly
1400 if (event
.target
.form
!== undefined) {
1401 switch (event
.target
.type
) {
1410 case 'select-multiple':
1415 event
.preventDefault();
1418 keyboardinputReset: function() {
1419 var kbi
= document
.getElementById('noVNC_keyboardinput');
1420 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1421 UI
.lastKeyboardinput
= kbi
.value
;
1424 keyEvent: function (keysym
, code
, down
) {
1425 if (!UI
.rfb
) return;
1427 UI
.rfb
.sendKey(keysym
, code
, down
);
1430 // When normal keyboard events are left uncought, use the input events from
1431 // the keyboardinput element instead and generate the corresponding key events.
1432 // This code is required since some browsers on Android are inconsistent in
1433 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1434 keyInput: function(event
) {
1436 if (!UI
.rfb
) return;
1438 var newValue
= event
.target
.value
;
1440 if (!UI
.lastKeyboardinput
) {
1441 UI
.keyboardinputReset();
1443 var oldValue
= UI
.lastKeyboardinput
;
1447 // Try to check caret position since whitespace at the end
1448 // will not be considered by value.length in some browsers
1449 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1451 // selectionStart is undefined in Google Chrome
1452 newLen
= newValue
.length
;
1454 var oldLen
= oldValue
.length
;
1457 var inputs
= newLen
- oldLen
;
1459 backspaces
= -inputs
;
1464 // Compare the old string with the new to account for
1465 // text-corrections or other input that modify existing text
1467 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1468 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1469 inputs
= newLen
- i
;
1470 backspaces
= oldLen
- i
;
1475 // Send the key events
1476 for (i
= 0; i
< backspaces
; i
++) {
1477 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
, "Backspace");
1479 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1480 UI
.rfb
.sendKey(keysyms
.lookup(newValue
.charCodeAt(i
)));
1483 // Control the text content length in the keyboardinput element
1484 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1485 UI
.keyboardinputReset();
1486 } else if (newLen
< 1) {
1487 // There always have to be some text in the keyboardinput
1488 // element with which backspace can interact.
1489 UI
.keyboardinputReset();
1490 // This sometimes causes the keyboard to disappear for a second
1491 // but it is required for the android keyboard to recognize that
1492 // text has been added to the field
1493 event
.target
.blur();
1494 // This has to be ran outside of the input handler in order to work
1495 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1497 UI
.lastKeyboardinput
= newValue
;
1507 openExtraKeys: function() {
1508 UI
.closeAllPanels();
1509 UI
.openControlbar();
1511 document
.getElementById('noVNC_modifiers')
1512 .classList
.add("noVNC_open");
1513 document
.getElementById('noVNC_toggle_extra_keys_button')
1514 .classList
.add("noVNC_selected");
1517 closeExtraKeys: function() {
1518 document
.getElementById('noVNC_modifiers')
1519 .classList
.remove("noVNC_open");
1520 document
.getElementById('noVNC_toggle_extra_keys_button')
1521 .classList
.remove("noVNC_selected");
1524 toggleExtraKeys: function() {
1525 if(document
.getElementById('noVNC_modifiers')
1526 .classList
.contains("noVNC_open")) {
1527 UI
.closeExtraKeys();
1533 sendEsc: function() {
1534 UI
.rfb
.sendKey(KeyTable
.XK_Escape
, "Escape");
1537 sendTab: function() {
1538 UI
.rfb
.sendKey(KeyTable
.XK_Tab
);
1541 toggleCtrl: function() {
1542 var btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1543 if (btn
.classList
.contains("noVNC_selected")) {
1544 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", false);
1545 btn
.classList
.remove("noVNC_selected");
1547 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", true);
1548 btn
.classList
.add("noVNC_selected");
1552 toggleAlt: function() {
1553 var btn
= document
.getElementById('noVNC_toggle_alt_button');
1554 if (btn
.classList
.contains("noVNC_selected")) {
1555 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", false);
1556 btn
.classList
.remove("noVNC_selected");
1558 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", true);
1559 btn
.classList
.add("noVNC_selected");
1563 sendCtrlAltDel: function() {
1564 UI
.rfb
.sendCtrlAltDel();
1573 setMouseButton: function(num
) {
1574 var view_only
= UI
.rfb
.viewOnly
;
1575 if (UI
.rfb
&& !view_only
) {
1576 UI
.rfb
.touchButton
= num
;
1579 var blist
= [0, 1,2,4];
1580 for (var b
= 0; b
< blist
.length
; b
++) {
1581 var button
= document
.getElementById('noVNC_mouse_button' +
1583 if (blist
[b
] === num
&& !view_only
) {
1584 button
.classList
.remove("noVNC_hidden");
1586 button
.classList
.add("noVNC_hidden");
1591 updateViewOnly: function() {
1592 if (!UI
.rfb
) return;
1593 UI
.rfb
.viewOnly
= UI
.getSetting('view_only');
1595 // Hide input related buttons in view only mode
1596 if (UI
.rfb
.viewOnly
) {
1597 document
.getElementById('noVNC_keyboard_button')
1598 .classList
.add('noVNC_hidden');
1599 document
.getElementById('noVNC_toggle_extra_keys_button')
1600 .classList
.add('noVNC_hidden');
1602 document
.getElementById('noVNC_keyboard_button')
1603 .classList
.remove('noVNC_hidden');
1604 document
.getElementById('noVNC_toggle_extra_keys_button')
1605 .classList
.remove('noVNC_hidden');
1607 UI
.setMouseButton(1); //has it's own logic for hiding/showing
1610 updateLogging: function() {
1611 WebUtil
.init_logging(UI
.getSetting('logging'));
1614 updateDesktopName: function(e
) {
1615 UI
.desktopName
= e
.detail
.name
;
1616 // Display the desktop name in the document title
1617 document
.title
= e
.detail
.name
+ " - noVNC";
1621 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1622 var promise
= document
.getElementById('noVNC_bell').play();
1623 // The standards disagree on the return value here
1625 promise
.catch(function(e
) {
1626 if (e
.name
=== "NotAllowedError") {
1627 // Ignore when the browser doesn't let us play audio.
1628 // It is common that the browsers require audio to be
1629 // initiated from a user action.
1631 Log
.Error("Unable to play bell: " + e
);
1638 //Helper to add options to dropdown.
1639 addOption: function(selectbox
, text
, value
) {
1640 var optn
= document
.createElement("OPTION");
1643 selectbox
.options
.add(optn
);
1652 // Set up translations
1653 var LINGUAS
= ["de", "el", "es", "nl", "pl", "sv", "tr", "zh"];
1654 l10n
.setup(LINGUAS
);
1655 if (l10n
.language
!== "en" && l10n
.dictionary
=== undefined) {
1656 WebUtil
.fetchJSON('app/locale/' + l10n
.language
+ '.json', function (translations
) {
1657 l10n
.dictionary
= translations
;
1659 // wait for translations to load before loading the UI