2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
6 * See README.md for usage and integration instructions.
9 import * as Log
from '../core/util/logging.js';
10 import _
, { l10n
} from './localization.js';
11 import { isTouchDevice
, isSafari
, isIOS
, isAndroid
, dragThreshold
}
12 from '../core/util/browser.js';
13 import { setCapture
, getPointerEvent
} from '../core/util/events.js';
14 import KeyTable
from "../core/input/keysym.js";
15 import keysyms
from "../core/input/keysymdef.js";
16 import Keyboard
from "../core/input/keyboard.js";
17 import RFB
from "../core/rfb.js";
18 import * as WebUtil
from "./webutil.js";
20 const PAGE_TITLE
= "noVNC";
28 hideKeyboardTimeout
: null,
29 idleControlbarTimeout
: null,
30 closeControlbarTimeout
: null,
32 controlbarGrabbed
: false,
33 controlbarDrag
: false,
34 controlbarMouseDownClientY
: 0,
35 controlbarMouseDownOffsetY
: 0,
37 lastKeyboardinput
: null,
38 defaultKeyboardinputLen
: 100,
40 inhibit_reconnect
: true,
41 reconnect_callback
: null,
42 reconnect_password
: null,
45 return WebUtil
.initSettings().then(() => {
46 if (document
.readyState
=== "interactive" || document
.readyState
=== "complete") {
50 return new Promise((resolve
, reject
) => {
51 document
.addEventListener('DOMContentLoaded', () => UI
.start().then(resolve
).catch(reject
));
56 // Render default UI and initialize settings menu
64 WebUtil
.fetchJSON('../package.json')
65 .then((packageInfo
) => {
66 Array
.from(document
.getElementsByClassName('noVNC_version')).forEach(el
=> el
.innerText
= packageInfo
.version
);
69 Log
.Error("Couldn't fetch package.json: " + err
);
70 Array
.from(document
.getElementsByClassName('noVNC_version_wrapper'))
71 .concat(Array
.from(document
.getElementsByClassName('noVNC_version_separator')))
72 .forEach(el
=> el
.style
.display
= 'none');
75 // Adapt the interface for touch screen devices
77 document
.documentElement
.classList
.add("noVNC_touch");
78 // Remove the address bar
79 setTimeout(() => 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
.addControlbarHandlers();
91 UI
.addTouchSpecificHandlers();
92 UI
.addExtraKeysHandlers();
93 UI
.addMachineHandlers();
94 UI
.addConnectionControlHandlers();
95 UI
.addClipboardHandlers();
96 UI
.addSettingsHandlers();
97 document
.getElementById("noVNC_status")
98 .addEventListener('click', UI
.hideStatus
);
100 // Bootstrap fallback input handler
101 UI
.keyboardinputReset();
105 UI
.updateVisualState('init');
107 document
.documentElement
.classList
.remove("noVNC_loading");
109 let autoconnect
= WebUtil
.getConfigVar('autoconnect', false);
110 if (autoconnect
=== 'true' || autoconnect
== '1') {
115 // Show the connect panel on first load unless autoconnecting
116 UI
.openConnectPanel();
119 return Promise
.resolve(UI
.rfb
);
123 // Only show the button if fullscreen is properly supported
124 // * Safari doesn't support alphanumerical input while in fullscreen
126 (document
.documentElement
.requestFullscreen
||
127 document
.documentElement
.mozRequestFullScreen
||
128 document
.documentElement
.webkitRequestFullscreen
||
129 document
.body
.msRequestFullscreen
)) {
130 document
.getElementById('noVNC_fullscreen_button')
131 .classList
.remove("noVNC_hidden");
132 UI
.addFullscreenHandlers();
137 // Logging selection dropdown
138 const llevels
= ['error', 'warn', 'info', 'debug'];
139 for (let 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 let port
= window
.location
.port
;
151 if (window
.location
.protocol
.substring(0, 5) == 'https') {
153 } else if (window
.location
.protocol
.substring(0, 4) == 'http') {
158 /* Populate the controls if defaults are provided in the URL */
159 UI
.initSetting('host', window
.location
.hostname
);
160 UI
.initSetting('port', port
);
161 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
162 UI
.initSetting('view_clip', false);
163 UI
.initSetting('resize', 'off');
164 UI
.initSetting('shared', true);
165 UI
.initSetting('view_only', false);
166 UI
.initSetting('show_dot', 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() {
176 const labels
= document
.getElementsByTagName('LABEL');
177 for (let i
= 0; i
< labels
.length
; i
++) {
178 const htmlFor
= labels
[i
].htmlFor
;
180 const elem
= document
.getElementById(htmlFor
);
181 if (elem
) elem
.label
= labels
[i
];
183 // If 'for' isn't set, use the first input element child
184 const children
= labels
[i
].children
;
185 for (let j
= 0; j
< children
.length
; j
++) {
186 if (children
[j
].form
!== undefined) {
187 children
[j
].label
= labels
[i
];
201 addControlbarHandlers() {
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 const exps
= document
.getElementsByClassName("noVNC_expander");
229 for (let i
= 0;i
< exps
.length
;i
++) {
230 exps
[i
].addEventListener('click', UI
.toggleExpander
);
234 addTouchSpecificHandlers() {
235 document
.getElementById("noVNC_mouse_button0")
236 .addEventListener('click', () => UI
.setMouseButton(1));
237 document
.getElementById("noVNC_mouse_button1")
238 .addEventListener('click', () => UI
.setMouseButton(2));
239 document
.getElementById("noVNC_mouse_button2")
240 .addEventListener('click', () => UI
.setMouseButton(4));
241 document
.getElementById("noVNC_mouse_button4")
242 .addEventListener('click', () => 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', () => 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() {
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_windows_button")
289 .addEventListener('click', UI
.toggleWindows
);
290 document
.getElementById("noVNC_toggle_alt_button")
291 .addEventListener('click', UI
.toggleAlt
);
292 document
.getElementById("noVNC_send_tab_button")
293 .addEventListener('click', UI
.sendTab
);
294 document
.getElementById("noVNC_send_esc_button")
295 .addEventListener('click', UI
.sendEsc
);
296 document
.getElementById("noVNC_send_ctrl_alt_del_button")
297 .addEventListener('click', UI
.sendCtrlAltDel
);
300 addMachineHandlers() {
301 document
.getElementById("noVNC_shutdown_button")
302 .addEventListener('click', () => UI
.rfb
.machineShutdown());
303 document
.getElementById("noVNC_reboot_button")
304 .addEventListener('click', () => UI
.rfb
.machineReboot());
305 document
.getElementById("noVNC_reset_button")
306 .addEventListener('click', () => UI
.rfb
.machineReset());
307 document
.getElementById("noVNC_power_button")
308 .addEventListener('click', UI
.togglePowerPanel
);
311 addConnectionControlHandlers() {
312 document
.getElementById("noVNC_disconnect_button")
313 .addEventListener('click', UI
.disconnect
);
314 document
.getElementById("noVNC_connect_button")
315 .addEventListener('click', UI
.connect
);
316 document
.getElementById("noVNC_cancel_reconnect_button")
317 .addEventListener('click', UI
.cancelReconnect
);
319 document
.getElementById("noVNC_credentials_button")
320 .addEventListener('click', UI
.setCredentials
);
323 addClipboardHandlers() {
324 document
.getElementById("noVNC_clipboard_button")
325 .addEventListener('click', UI
.toggleClipboardPanel
);
326 document
.getElementById("noVNC_clipboard_text")
327 .addEventListener('change', UI
.clipboardSend
);
328 document
.getElementById("noVNC_clipboard_clear_button")
329 .addEventListener('click', UI
.clipboardClear
);
332 // Add a call to save settings when the element changes,
333 // unless the optional parameter changeFunc is used instead.
334 addSettingChangeHandler(name
, changeFunc
) {
335 const settingElem
= document
.getElementById("noVNC_setting_" + name
);
336 if (changeFunc
=== undefined) {
337 changeFunc
= () => UI
.saveSetting(name
);
339 settingElem
.addEventListener('change', changeFunc
);
342 addSettingsHandlers() {
343 document
.getElementById("noVNC_settings_button")
344 .addEventListener('click', UI
.toggleSettingsPanel
);
346 UI
.addSettingChangeHandler('encrypt');
347 UI
.addSettingChangeHandler('resize');
348 UI
.addSettingChangeHandler('resize', UI
.applyResizeMode
);
349 UI
.addSettingChangeHandler('resize', UI
.updateViewClip
);
350 UI
.addSettingChangeHandler('view_clip');
351 UI
.addSettingChangeHandler('view_clip', UI
.updateViewClip
);
352 UI
.addSettingChangeHandler('shared');
353 UI
.addSettingChangeHandler('view_only');
354 UI
.addSettingChangeHandler('view_only', UI
.updateViewOnly
);
355 UI
.addSettingChangeHandler('show_dot');
356 UI
.addSettingChangeHandler('show_dot', UI
.updateShowDotCursor
);
357 UI
.addSettingChangeHandler('host');
358 UI
.addSettingChangeHandler('port');
359 UI
.addSettingChangeHandler('path');
360 UI
.addSettingChangeHandler('repeaterID');
361 UI
.addSettingChangeHandler('logging');
362 UI
.addSettingChangeHandler('logging', UI
.updateLogging
);
363 UI
.addSettingChangeHandler('reconnect');
364 UI
.addSettingChangeHandler('reconnect_delay');
367 addFullscreenHandlers() {
368 document
.getElementById("noVNC_fullscreen_button")
369 .addEventListener('click', UI
.toggleFullscreen
);
371 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
372 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
373 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
374 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
383 // Disable/enable controls depending on connection state
384 updateVisualState(state
) {
386 document
.documentElement
.classList
.remove("noVNC_connecting");
387 document
.documentElement
.classList
.remove("noVNC_connected");
388 document
.documentElement
.classList
.remove("noVNC_disconnecting");
389 document
.documentElement
.classList
.remove("noVNC_reconnecting");
391 const transition_elem
= document
.getElementById("noVNC_transition_text");
396 transition_elem
.textContent
= _("Connecting...");
397 document
.documentElement
.classList
.add("noVNC_connecting");
400 document
.documentElement
.classList
.add("noVNC_connected");
402 case 'disconnecting':
403 transition_elem
.textContent
= _("Disconnecting...");
404 document
.documentElement
.classList
.add("noVNC_disconnecting");
409 transition_elem
.textContent
= _("Reconnecting...");
410 document
.documentElement
.classList
.add("noVNC_reconnecting");
413 Log
.Error("Invalid visual state: " + state
);
414 UI
.showStatus(_("Internal error"), 'error');
421 UI
.disableSetting('encrypt');
422 UI
.disableSetting('shared');
423 UI
.disableSetting('host');
424 UI
.disableSetting('port');
425 UI
.disableSetting('path');
426 UI
.disableSetting('repeaterID');
427 UI
.setMouseButton(1);
429 // Hide the controlbar after 2 seconds
430 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
432 UI
.enableSetting('encrypt');
433 UI
.enableSetting('shared');
434 UI
.enableSetting('host');
435 UI
.enableSetting('port');
436 UI
.enableSetting('path');
437 UI
.enableSetting('repeaterID');
438 UI
.updatePowerButton();
442 // State change closes the password dialog
443 document
.getElementById('noVNC_credentials_dlg')
444 .classList
.remove('noVNC_open');
447 showStatus(text
, status_type
, time
) {
448 const statusElem
= document
.getElementById('noVNC_status');
450 if (typeof status_type
=== 'undefined') {
451 status_type
= 'normal';
454 // Don't overwrite more severe visible statuses and never
455 // errors. Only shows the first error.
456 if (statusElem
.classList
.contains("noVNC_open")) {
457 if (statusElem
.classList
.contains("noVNC_status_error")) {
460 if (statusElem
.classList
.contains("noVNC_status_warn") &&
461 status_type
=== 'normal') {
466 clearTimeout(UI
.statusTimeout
);
468 switch (status_type
) {
470 statusElem
.classList
.remove("noVNC_status_warn");
471 statusElem
.classList
.remove("noVNC_status_normal");
472 statusElem
.classList
.add("noVNC_status_error");
476 statusElem
.classList
.remove("noVNC_status_error");
477 statusElem
.classList
.remove("noVNC_status_normal");
478 statusElem
.classList
.add("noVNC_status_warn");
483 statusElem
.classList
.remove("noVNC_status_error");
484 statusElem
.classList
.remove("noVNC_status_warn");
485 statusElem
.classList
.add("noVNC_status_normal");
489 statusElem
.textContent
= text
;
490 statusElem
.classList
.add("noVNC_open");
492 // If no time was specified, show the status for 1.5 seconds
493 if (typeof time
=== 'undefined') {
497 // Error messages do not timeout
498 if (status_type
!== 'error') {
499 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
504 clearTimeout(UI
.statusTimeout
);
505 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
508 activateControlbar(event
) {
509 clearTimeout(UI
.idleControlbarTimeout
);
510 // We manipulate the anchor instead of the actual control
511 // bar in order to avoid creating new a stacking group
512 document
.getElementById('noVNC_control_bar_anchor')
513 .classList
.remove("noVNC_idle");
514 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
518 document
.getElementById('noVNC_control_bar_anchor')
519 .classList
.add("noVNC_idle");
523 clearTimeout(UI
.closeControlbarTimeout
);
527 document
.getElementById('noVNC_control_bar')
528 .classList
.add("noVNC_open");
533 document
.getElementById('noVNC_control_bar')
534 .classList
.remove("noVNC_open");
538 if (document
.getElementById('noVNC_control_bar')
539 .classList
.contains("noVNC_open")) {
540 UI
.closeControlbar();
546 toggleControlbarSide() {
547 // Temporarily disable animation, if bar is displayed, to avoid weird
548 // movement. The transitionend-event will not fire when display=none.
549 const bar
= document
.getElementById('noVNC_control_bar');
550 const barDisplayStyle
= window
.getComputedStyle(bar
).display
;
551 if (barDisplayStyle
!== 'none') {
552 bar
.style
.transitionDuration
= '0s';
553 bar
.addEventListener('transitionend', () => bar
.style
.transitionDuration
= '');
556 const anchor
= document
.getElementById('noVNC_control_bar_anchor');
557 if (anchor
.classList
.contains("noVNC_right")) {
558 WebUtil
.writeSetting('controlbar_pos', 'left');
559 anchor
.classList
.remove("noVNC_right");
561 WebUtil
.writeSetting('controlbar_pos', 'right');
562 anchor
.classList
.add("noVNC_right");
565 // Consider this a movement of the handle
566 UI
.controlbarDrag
= true;
569 showControlbarHint(show
) {
570 const hint
= document
.getElementById('noVNC_control_bar_hint');
572 hint
.classList
.add("noVNC_active");
574 hint
.classList
.remove("noVNC_active");
578 dragControlbarHandle(e
) {
579 if (!UI
.controlbarGrabbed
) return;
581 const ptr
= getPointerEvent(e
);
583 const anchor
= document
.getElementById('noVNC_control_bar_anchor');
584 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
585 if (anchor
.classList
.contains("noVNC_right")) {
586 UI
.toggleControlbarSide();
588 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
589 if (!anchor
.classList
.contains("noVNC_right")) {
590 UI
.toggleControlbarSide();
594 if (!UI
.controlbarDrag
) {
595 const dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
597 if (dragDistance
< dragThreshold
) return;
599 UI
.controlbarDrag
= true;
602 const eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
604 UI
.moveControlbarHandle(eventY
);
609 UI
.activateControlbar();
612 // Move the handle but don't allow any position outside the bounds
613 moveControlbarHandle(viewportRelativeY
) {
614 const handle
= document
.getElementById("noVNC_control_bar_handle");
615 const handleHeight
= handle
.getBoundingClientRect().height
;
616 const controlbarBounds
= document
.getElementById("noVNC_control_bar")
617 .getBoundingClientRect();
620 // These heights need to be non-zero for the below logic to work
621 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
625 let newY
= viewportRelativeY
;
627 // Check if the coordinates are outside the control bar
628 if (newY
< controlbarBounds
.top
+ margin
) {
629 // Force coordinates to be below the top of the control bar
630 newY
= controlbarBounds
.top
+ margin
;
632 } else if (newY
> controlbarBounds
.top
+
633 controlbarBounds
.height
- handleHeight
- margin
) {
634 // Force coordinates to be above the bottom of the control bar
635 newY
= controlbarBounds
.top
+
636 controlbarBounds
.height
- handleHeight
- margin
;
639 // Corner case: control bar too small for stable position
640 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
641 newY
= controlbarBounds
.top
+
642 (controlbarBounds
.height
- handleHeight
) / 2;
645 // The transform needs coordinates that are relative to the parent
646 const parentRelativeY
= newY
- controlbarBounds
.top
;
647 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
650 updateControlbarHandle() {
651 // Since the control bar is fixed on the viewport and not the page,
652 // the move function expects coordinates relative the the viewport.
653 const handle
= document
.getElementById("noVNC_control_bar_handle");
654 const handleBounds
= handle
.getBoundingClientRect();
655 UI
.moveControlbarHandle(handleBounds
.top
);
658 controlbarHandleMouseUp(e
) {
659 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
661 // mouseup and mousedown on the same place toggles the controlbar
662 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
663 UI
.toggleControlbar();
667 UI
.activateControlbar();
669 UI
.controlbarGrabbed
= false;
670 UI
.showControlbarHint(false);
673 controlbarHandleMouseDown(e
) {
674 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
676 const ptr
= getPointerEvent(e
);
678 const handle
= document
.getElementById("noVNC_control_bar_handle");
679 const bounds
= handle
.getBoundingClientRect();
681 // Touch events have implicit capture
682 if (e
.type
=== "mousedown") {
686 UI
.controlbarGrabbed
= true;
687 UI
.controlbarDrag
= false;
689 UI
.showControlbarHint(true);
691 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
692 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
696 UI
.activateControlbar();
700 if (this.classList
.contains("noVNC_open")) {
701 this.classList
.remove("noVNC_open");
703 this.classList
.add("noVNC_open");
713 // Initial page load read/initialization of settings
714 initSetting(name
, defVal
) {
715 // Check Query string followed by cookie
716 let val
= WebUtil
.getConfigVar(name
);
718 val
= WebUtil
.readSetting(name
, defVal
);
720 WebUtil
.setSetting(name
, val
);
721 UI
.updateSetting(name
);
725 // Set the new value, update and disable form control setting
726 forceSetting(name
, val
) {
727 WebUtil
.setSetting(name
, val
);
728 UI
.updateSetting(name
);
729 UI
.disableSetting(name
);
732 // Update cookie and form control setting. If value is not set, then
733 // updates from control to current cookie setting.
734 updateSetting(name
) {
736 // Update the settings control
737 let value
= UI
.getSetting(name
);
739 const ctrl
= document
.getElementById('noVNC_setting_' + name
);
740 if (ctrl
.type
=== 'checkbox') {
741 ctrl
.checked
= value
;
743 } else if (typeof ctrl
.options
!== 'undefined') {
744 for (let i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
745 if (ctrl
.options
[i
].value
=== value
) {
746 ctrl
.selectedIndex
= i
;
751 /*Weird IE9 error leads to 'null' appearring
752 in textboxes instead of ''.*/
753 if (value
=== null) {
760 // Save control setting to cookie
762 const 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
778 const ctrl
= document
.getElementById('noVNC_setting_' + name
);
779 let 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(name
) {
794 const ctrl
= document
.getElementById('noVNC_setting_' + name
);
795 ctrl
.disabled
= true;
796 ctrl
.label
.classList
.add('noVNC_disabled');
799 enableSetting(name
) {
800 const ctrl
= document
.getElementById('noVNC_setting_' + name
);
801 ctrl
.disabled
= false;
802 ctrl
.label
.classList
.remove('noVNC_disabled');
812 UI
.closeSettingsPanel();
813 UI
.closePowerPanel();
814 UI
.closeClipboardPanel();
824 openSettingsPanel() {
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() {
847 document
.getElementById('noVNC_settings')
848 .classList
.remove("noVNC_open");
849 document
.getElementById('noVNC_settings_button')
850 .classList
.remove("noVNC_selected");
853 toggleSettingsPanel() {
854 if (document
.getElementById('noVNC_settings')
855 .classList
.contains("noVNC_open")) {
856 UI
.closeSettingsPanel();
858 UI
.openSettingsPanel();
872 document
.getElementById('noVNC_power')
873 .classList
.add("noVNC_open");
874 document
.getElementById('noVNC_power_button')
875 .classList
.add("noVNC_selected");
879 document
.getElementById('noVNC_power')
880 .classList
.remove("noVNC_open");
881 document
.getElementById('noVNC_power_button')
882 .classList
.remove("noVNC_selected");
886 if (document
.getElementById('noVNC_power')
887 .classList
.contains("noVNC_open")) {
888 UI
.closePowerPanel();
894 // Disable/enable power button
895 updatePowerButton() {
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() {
919 document
.getElementById('noVNC_clipboard')
920 .classList
.add("noVNC_open");
921 document
.getElementById('noVNC_clipboard_button')
922 .classList
.add("noVNC_selected");
925 closeClipboardPanel() {
926 document
.getElementById('noVNC_clipboard')
927 .classList
.remove("noVNC_open");
928 document
.getElementById('noVNC_clipboard_button')
929 .classList
.remove("noVNC_selected");
932 toggleClipboardPanel() {
933 if (document
.getElementById('noVNC_clipboard')
934 .classList
.contains("noVNC_open")) {
935 UI
.closeClipboardPanel();
937 UI
.openClipboardPanel();
941 clipboardReceive(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");
948 document
.getElementById('noVNC_clipboard_text').value
= "";
949 UI
.rfb
.clipboardPasteFrom("");
953 const 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");
966 document
.getElementById('noVNC_connect_dlg')
967 .classList
.add("noVNC_open");
970 closeConnectPanel() {
971 document
.getElementById('noVNC_connect_dlg')
972 .classList
.remove("noVNC_open");
975 connect(event
, password
) {
977 // Ignore when rfb already exists
978 if (typeof UI
.rfb
!== 'undefined') {
982 const host
= UI
.getSetting('host');
983 const port
= UI
.getSetting('port');
984 const 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", 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';
1033 UI
.rfb
.showDotCursor
= UI
.getSetting('show_dot');
1035 UI
.updateViewOnly(); // requires UI.rfb
1039 UI
.closeAllPanels();
1040 UI
.rfb
.disconnect();
1042 UI
.connected
= false;
1044 // Disable automatic reconnecting
1045 UI
.inhibit_reconnect
= true;
1047 UI
.updateVisualState('disconnecting');
1049 // Don't display the connection settings until we're actually disconnected
1053 UI
.reconnect_callback
= null;
1055 // if reconnect has been disabled in the meantime, do nothing.
1056 if (UI
.inhibit_reconnect
) {
1060 UI
.connect(null, UI
.reconnect_password
);
1064 if (UI
.reconnect_callback
!== null) {
1065 clearTimeout(UI
.reconnect_callback
);
1066 UI
.reconnect_callback
= null;
1069 UI
.updateVisualState('disconnected');
1071 UI
.openControlbar();
1072 UI
.openConnectPanel();
1075 connectFinished(e
) {
1076 UI
.connected
= true;
1077 UI
.inhibit_reconnect
= false;
1080 if (UI
.getSetting('encrypt')) {
1081 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
1083 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
1086 UI
.updateVisualState('connected');
1088 // Do this last because it can only be used on rendered elements
1092 disconnectFinished(e
) {
1093 const wasConnected
= UI
.connected
;
1095 // This variable is ideally set when disconnection starts, but
1096 // when the disconnection isn't clean or if it is initiated by
1097 // the server, we need to do it here as well since
1098 // UI.disconnect() won't be used in those cases.
1099 UI
.connected
= false;
1103 if (!e
.detail
.clean
) {
1104 UI
.updateVisualState('disconnected');
1106 UI
.showStatus(_("Something went wrong, connection is closed"),
1109 UI
.showStatus(_("Failed to connect to server"), 'error');
1111 } else if (UI
.getSetting('reconnect', false) === true && !UI
.inhibit_reconnect
) {
1112 UI
.updateVisualState('reconnecting');
1114 const delay
= parseInt(UI
.getSetting('reconnect_delay'));
1115 UI
.reconnect_callback
= setTimeout(UI
.reconnect
, delay
);
1118 UI
.updateVisualState('disconnected');
1119 UI
.showStatus(_("Disconnected"), 'normal');
1122 document
.title
= PAGE_TITLE
;
1124 UI
.openControlbar();
1125 UI
.openConnectPanel();
1130 // On security failures we might get a string with a reason
1131 // directly from the server. Note that we can't control if
1132 // this string is translated or not.
1133 if ('reason' in e
.detail
) {
1134 msg
= _("New connection has been rejected with reason: ") +
1137 msg
= _("New connection has been rejected");
1139 UI
.showStatus(msg
, 'error');
1149 // FIXME: handle more types
1151 document
.getElementById("noVNC_username_block").classList
.remove("noVNC_hidden");
1152 document
.getElementById("noVNC_password_block").classList
.remove("noVNC_hidden");
1154 let inputFocus
= "none";
1155 if (e
.detail
.types
.indexOf("username") === -1) {
1156 document
.getElementById("noVNC_username_block").classList
.add("noVNC_hidden");
1158 inputFocus
= inputFocus
=== "none" ? "noVNC_username_input" : inputFocus
;
1160 if (e
.detail
.types
.indexOf("password") === -1) {
1161 document
.getElementById("noVNC_password_block").classList
.add("noVNC_hidden");
1163 inputFocus
= inputFocus
=== "none" ? "noVNC_password_input" : inputFocus
;
1165 document
.getElementById('noVNC_credentials_dlg')
1166 .classList
.add('noVNC_open');
1168 setTimeout(() => document
1169 .getElementById(inputFocus
).focus(), 100);
1171 Log
.Warn("Server asked for credentials");
1172 UI
.showStatus(_("Credentials are required"), "warning");
1176 // Prevent actually submitting the form
1179 let inputElemUsername
= document
.getElementById('noVNC_username_input');
1180 const username
= inputElemUsername
.value
;
1182 let inputElemPassword
= document
.getElementById('noVNC_password_input');
1183 const password
= inputElemPassword
.value
;
1184 // Clear the input after reading the password
1185 inputElemPassword
.value
= "";
1187 UI
.rfb
.sendCredentials({ username
: username
, password
: password
});
1188 UI
.reconnect_password
= password
;
1189 document
.getElementById('noVNC_credentials_dlg')
1190 .classList
.remove('noVNC_open');
1199 toggleFullscreen() {
1200 if (document
.fullscreenElement
|| // alternative standard method
1201 document
.mozFullScreenElement
|| // currently working methods
1202 document
.webkitFullscreenElement
||
1203 document
.msFullscreenElement
) {
1204 if (document
.exitFullscreen
) {
1205 document
.exitFullscreen();
1206 } else if (document
.mozCancelFullScreen
) {
1207 document
.mozCancelFullScreen();
1208 } else if (document
.webkitExitFullscreen
) {
1209 document
.webkitExitFullscreen();
1210 } else if (document
.msExitFullscreen
) {
1211 document
.msExitFullscreen();
1214 if (document
.documentElement
.requestFullscreen
) {
1215 document
.documentElement
.requestFullscreen();
1216 } else if (document
.documentElement
.mozRequestFullScreen
) {
1217 document
.documentElement
.mozRequestFullScreen();
1218 } else if (document
.documentElement
.webkitRequestFullscreen
) {
1219 document
.documentElement
.webkitRequestFullscreen(Element
.ALLOW_KEYBOARD_INPUT
);
1220 } else if (document
.body
.msRequestFullscreen
) {
1221 document
.body
.msRequestFullscreen();
1224 UI
.updateFullscreenButton();
1227 updateFullscreenButton() {
1228 if (document
.fullscreenElement
|| // alternative standard method
1229 document
.mozFullScreenElement
|| // currently working methods
1230 document
.webkitFullscreenElement
||
1231 document
.msFullscreenElement
) {
1232 document
.getElementById('noVNC_fullscreen_button')
1233 .classList
.add("noVNC_selected");
1235 document
.getElementById('noVNC_fullscreen_button')
1236 .classList
.remove("noVNC_selected");
1246 // Apply remote resizing or local scaling
1248 if (!UI
.rfb
) return;
1250 UI
.rfb
.scaleViewport
= UI
.getSetting('resize') === 'scale';
1251 UI
.rfb
.resizeSession
= UI
.getSetting('resize') === 'remote';
1260 // Update viewport clipping property for the connection. The normal
1261 // case is to get the value from the setting. There are special cases
1262 // for when the viewport is scaled or when a touch device is used.
1264 if (!UI
.rfb
) return;
1266 const scaling
= UI
.getSetting('resize') === 'scale';
1269 // Can't be clipping if viewport is scaled to fit
1270 UI
.forceSetting('view_clip', false);
1271 UI
.rfb
.clipViewport
= false;
1272 } else if (isIOS() || isAndroid()) {
1273 // iOS and Android usually have shit scrollbars
1274 UI
.forceSetting('view_clip', true);
1275 UI
.rfb
.clipViewport
= true;
1277 UI
.enableSetting('view_clip');
1278 UI
.rfb
.clipViewport
= UI
.getSetting('view_clip');
1281 // Changing the viewport may change the state of
1282 // the dragging button
1283 UI
.updateViewDrag();
1293 if (!UI
.rfb
) return;
1295 UI
.rfb
.dragViewport
= !UI
.rfb
.dragViewport
;
1296 UI
.updateViewDrag();
1300 if (!UI
.connected
) return;
1302 const viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1304 if (!UI
.rfb
.clipViewport
&& UI
.rfb
.dragViewport
) {
1305 // We are no longer clipping the viewport. Make sure
1306 // viewport drag isn't active when it can't be used.
1307 UI
.rfb
.dragViewport
= false;
1310 if (UI
.rfb
.dragViewport
) {
1311 viewDragButton
.classList
.add("noVNC_selected");
1313 viewDragButton
.classList
.remove("noVNC_selected");
1316 if (UI
.rfb
.clipViewport
) {
1317 viewDragButton
.classList
.remove("noVNC_hidden");
1319 viewDragButton
.classList
.add("noVNC_hidden");
1329 showVirtualKeyboard() {
1330 if (!isTouchDevice
) return;
1332 const input
= document
.getElementById('noVNC_keyboardinput');
1334 if (document
.activeElement
== input
) return;
1339 const l
= input
.value
.length
;
1340 // Move the caret to the end
1341 input
.setSelectionRange(l
, l
);
1343 // setSelectionRange is undefined in Google Chrome
1347 hideVirtualKeyboard() {
1348 if (!isTouchDevice
) return;
1350 const input
= document
.getElementById('noVNC_keyboardinput');
1352 if (document
.activeElement
!= input
) return;
1357 toggleVirtualKeyboard() {
1358 if (document
.getElementById('noVNC_keyboard_button')
1359 .classList
.contains("noVNC_selected")) {
1360 UI
.hideVirtualKeyboard();
1362 UI
.showVirtualKeyboard();
1366 onfocusVirtualKeyboard(event
) {
1367 document
.getElementById('noVNC_keyboard_button')
1368 .classList
.add("noVNC_selected");
1370 UI
.rfb
.focusOnClick
= false;
1374 onblurVirtualKeyboard(event
) {
1375 document
.getElementById('noVNC_keyboard_button')
1376 .classList
.remove("noVNC_selected");
1378 UI
.rfb
.focusOnClick
= true;
1382 keepVirtualKeyboard(event
) {
1383 const input
= document
.getElementById('noVNC_keyboardinput');
1385 // Only prevent focus change if the virtual keyboard is active
1386 if (document
.activeElement
!= input
) {
1390 // Only allow focus to move to other elements that need
1391 // focus to function properly
1392 if (event
.target
.form
!== undefined) {
1393 switch (event
.target
.type
) {
1402 case 'select-multiple':
1407 event
.preventDefault();
1410 keyboardinputReset() {
1411 const kbi
= document
.getElementById('noVNC_keyboardinput');
1412 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1413 UI
.lastKeyboardinput
= kbi
.value
;
1416 keyEvent(keysym
, code
, down
) {
1417 if (!UI
.rfb
) return;
1419 UI
.rfb
.sendKey(keysym
, code
, down
);
1422 // When normal keyboard events are left uncought, use the input events from
1423 // the keyboardinput element instead and generate the corresponding key events.
1424 // This code is required since some browsers on Android are inconsistent in
1425 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1428 if (!UI
.rfb
) return;
1430 const newValue
= event
.target
.value
;
1432 if (!UI
.lastKeyboardinput
) {
1433 UI
.keyboardinputReset();
1435 const oldValue
= UI
.lastKeyboardinput
;
1439 // Try to check caret position since whitespace at the end
1440 // will not be considered by value.length in some browsers
1441 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1443 // selectionStart is undefined in Google Chrome
1444 newLen
= newValue
.length
;
1446 const oldLen
= oldValue
.length
;
1448 let inputs
= newLen
- oldLen
;
1449 let backspaces
= inputs
< 0 ? -inputs
: 0;
1451 // Compare the old string with the new to account for
1452 // text-corrections or other input that modify existing text
1453 for (let i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1454 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1455 inputs
= newLen
- i
;
1456 backspaces
= oldLen
- i
;
1461 // Send the key events
1462 for (let i
= 0; i
< backspaces
; i
++) {
1463 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
, "Backspace");
1465 for (let i
= newLen
- inputs
; i
< newLen
; i
++) {
1466 UI
.rfb
.sendKey(keysyms
.lookup(newValue
.charCodeAt(i
)));
1469 // Control the text content length in the keyboardinput element
1470 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1471 UI
.keyboardinputReset();
1472 } else if (newLen
< 1) {
1473 // There always have to be some text in the keyboardinput
1474 // element with which backspace can interact.
1475 UI
.keyboardinputReset();
1476 // This sometimes causes the keyboard to disappear for a second
1477 // but it is required for the android keyboard to recognize that
1478 // text has been added to the field
1479 event
.target
.blur();
1480 // This has to be ran outside of the input handler in order to work
1481 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1483 UI
.lastKeyboardinput
= newValue
;
1494 UI
.closeAllPanels();
1495 UI
.openControlbar();
1497 document
.getElementById('noVNC_modifiers')
1498 .classList
.add("noVNC_open");
1499 document
.getElementById('noVNC_toggle_extra_keys_button')
1500 .classList
.add("noVNC_selected");
1504 document
.getElementById('noVNC_modifiers')
1505 .classList
.remove("noVNC_open");
1506 document
.getElementById('noVNC_toggle_extra_keys_button')
1507 .classList
.remove("noVNC_selected");
1511 if (document
.getElementById('noVNC_modifiers')
1512 .classList
.contains("noVNC_open")) {
1513 UI
.closeExtraKeys();
1520 UI
.sendKey(KeyTable
.XK_Escape
, "Escape");
1524 UI
.sendKey(KeyTable
.XK_Tab
, "Tab");
1528 const btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1529 if (btn
.classList
.contains("noVNC_selected")) {
1530 UI
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", false);
1531 btn
.classList
.remove("noVNC_selected");
1533 UI
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", true);
1534 btn
.classList
.add("noVNC_selected");
1539 const btn
= document
.getElementById('noVNC_toggle_windows_button');
1540 if (btn
.classList
.contains("noVNC_selected")) {
1541 UI
.sendKey(KeyTable
.XK_Super_L
, "MetaLeft", false);
1542 btn
.classList
.remove("noVNC_selected");
1544 UI
.sendKey(KeyTable
.XK_Super_L
, "MetaLeft", true);
1545 btn
.classList
.add("noVNC_selected");
1550 const btn
= document
.getElementById('noVNC_toggle_alt_button');
1551 if (btn
.classList
.contains("noVNC_selected")) {
1552 UI
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", false);
1553 btn
.classList
.remove("noVNC_selected");
1555 UI
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", true);
1556 btn
.classList
.add("noVNC_selected");
1561 UI
.rfb
.sendCtrlAltDel();
1564 UI
.idleControlbar();
1567 sendKey(keysym
, code
, down
) {
1568 UI
.rfb
.sendKey(keysym
, code
, down
);
1570 // Move focus to the screen in order to be able to use the
1571 // keyboard right after these extra keys.
1572 // The exception is when a virtual keyboard is used, because
1573 // if we focus the screen the virtual keyboard would be closed.
1574 // In this case we focus our special virtual keyboard input
1576 if (document
.getElementById('noVNC_keyboard_button')
1577 .classList
.contains("noVNC_selected")) {
1578 document
.getElementById('noVNC_keyboardinput').focus();
1582 // fade out the controlbar to highlight that
1583 // the focus has been moved to the screen
1584 UI
.idleControlbar();
1593 setMouseButton(num
) {
1594 const view_only
= UI
.rfb
.viewOnly
;
1595 if (UI
.rfb
&& !view_only
) {
1596 UI
.rfb
.touchButton
= num
;
1599 const blist
= [0, 1, 2, 4];
1600 for (let b
= 0; b
< blist
.length
; b
++) {
1601 const button
= document
.getElementById('noVNC_mouse_button' +
1603 if (blist
[b
] === num
&& !view_only
) {
1604 button
.classList
.remove("noVNC_hidden");
1606 button
.classList
.add("noVNC_hidden");
1612 if (!UI
.rfb
) return;
1613 UI
.rfb
.viewOnly
= UI
.getSetting('view_only');
1615 // Hide input related buttons in view only mode
1616 if (UI
.rfb
.viewOnly
) {
1617 document
.getElementById('noVNC_keyboard_button')
1618 .classList
.add('noVNC_hidden');
1619 document
.getElementById('noVNC_toggle_extra_keys_button')
1620 .classList
.add('noVNC_hidden');
1621 document
.getElementById('noVNC_mouse_button' + UI
.rfb
.touchButton
)
1622 .classList
.add('noVNC_hidden');
1624 document
.getElementById('noVNC_keyboard_button')
1625 .classList
.remove('noVNC_hidden');
1626 document
.getElementById('noVNC_toggle_extra_keys_button')
1627 .classList
.remove('noVNC_hidden');
1628 document
.getElementById('noVNC_mouse_button' + UI
.rfb
.touchButton
)
1629 .classList
.remove('noVNC_hidden');
1633 updateShowDotCursor() {
1634 if (!UI
.rfb
) return;
1635 UI
.rfb
.showDotCursor
= UI
.getSetting('show_dot');
1639 WebUtil
.init_logging(UI
.getSetting('logging'));
1642 updateDesktopName(e
) {
1643 UI
.desktopName
= e
.detail
.name
;
1644 // Display the desktop name in the document title
1645 document
.title
= e
.detail
.name
+ " - " + PAGE_TITLE
;
1649 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1650 const promise
= document
.getElementById('noVNC_bell').play();
1651 // The standards disagree on the return value here
1653 promise
.catch((e
) => {
1654 if (e
.name
=== "NotAllowedError") {
1655 // Ignore when the browser doesn't let us play audio.
1656 // It is common that the browsers require audio to be
1657 // initiated from a user action.
1659 Log
.Error("Unable to play bell: " + e
);
1666 //Helper to add options to dropdown.
1667 addOption(selectbox
, text
, value
) {
1668 const optn
= document
.createElement("OPTION");
1671 selectbox
.options
.add(optn
);
1680 // Set up translations
1681 const LINGUAS
= ["cs", "de", "el", "es", "ja", "ko", "nl", "pl", "ru", "sv", "tr", "zh_CN", "zh_TW"];
1682 l10n
.setup(LINGUAS
);
1683 if (l10n
.language
=== "en" || l10n
.dictionary
!== undefined) {
1686 WebUtil
.fetchJSON('app/locale/' + l10n
.language
+ '.json')
1687 .then((translations
) => { l10n
.dictionary
= translations
; })
1688 .catch(err
=> Log
.Error("Failed to load translations: " + err
))