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
, browserSupportsCursorURIs as cursorURIsSupported
} 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 RFB
from "../core/rfb.js";
21 import Display
from "../core/display.js";
22 import * as WebUtil
from "./webutil.js";
31 hideKeyboardTimeout
: null,
32 idleControlbarTimeout
: null,
33 closeControlbarTimeout
: null,
35 controlbarGrabbed
: false,
36 controlbarDrag
: false,
37 controlbarMouseDownClientY
: 0,
38 controlbarMouseDownOffsetY
: 0,
41 lastKeyboardinput
: null,
42 defaultKeyboardinputLen
: 100,
44 inhibit_reconnect
: true,
45 reconnect_callback
: null,
46 reconnect_password
: null,
48 prime: function(callback
) {
49 if (document
.readyState
=== "interactive" || document
.readyState
=== "complete") {
52 document
.addEventListener('DOMContentLoaded', UI
.load
.bind(UI
, callback
));
56 // Setup rfb object, load settings from browser storage, then call
57 // UI.init to setup the UI/menus
58 load: function(callback
) {
59 WebUtil
.initSettings(UI
.start
, callback
);
62 // Render default UI and initialize settings menu
63 start: function(callback
) {
65 // Setup global variables first
66 UI
.isSafari
= (navigator
.userAgent
.indexOf('Safari') !== -1 &&
67 navigator
.userAgent
.indexOf('Chrome') === -1);
74 // Adapt the interface for touch screen devices
76 document
.documentElement
.classList
.add("noVNC_touch");
77 // Remove the address bar
78 setTimeout(function() { window
.scrollTo(0, 1); }, 100);
81 // Restore control bar position
82 if (WebUtil
.readSetting('controlbar_pos') === 'right') {
83 UI
.toggleControlbarSide();
88 // Setup event handlers
89 UI
.addResizeHandlers();
90 UI
.addControlbarHandlers();
91 UI
.addTouchSpecificHandlers();
92 UI
.addExtraKeysHandlers();
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();
107 UI
.updateVisualState();
109 document
.getElementById('noVNC_setting_host').focus();
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('cursor', !isTouchDevice
);
171 UI
.initSetting('view_clip', false);
172 UI
.initSetting('resize', 'off');
173 UI
.initSetting('shared', true);
174 UI
.initSetting('view_only', false);
175 UI
.initSetting('path', 'websockify');
176 UI
.initSetting('repeaterID', '');
177 UI
.initSetting('reconnect', false);
178 UI
.initSetting('reconnect_delay', 5000);
180 UI
.setupSettingLabels();
182 // Adds a link to the label elements on the corresponding input elements
183 setupSettingLabels: function() {
184 var labels
= document
.getElementsByTagName('LABEL');
185 for (var i
= 0; i
< labels
.length
; i
++) {
186 var htmlFor
= labels
[i
].htmlFor
;
188 var elem
= document
.getElementById(htmlFor
);
189 if (elem
) elem
.label
= labels
[i
];
191 // If 'for' isn't set, use the first input element child
192 var children
= labels
[i
].children
;
193 for (var j
= 0; j
< children
.length
; j
++) {
194 if (children
[j
].form
!== undefined) {
195 children
[j
].label
= labels
[i
];
203 initRFB: function() {
205 UI
.rfb
= new RFB({'target': document
.getElementById('noVNC_canvas'),
206 'onNotification': UI
.notification
,
207 'onUpdateState': UI
.updateState
,
208 'onDisconnected': UI
.disconnectFinished
,
209 'onPasswordRequired': UI
.passwordRequired
,
210 'onXvpInit': UI
.updateXvpButton
,
211 'onClipboard': UI
.clipboardReceive
,
213 'onFBUComplete': UI
.initialResize
,
214 'onFBResize': UI
.updateSessionSize
,
215 'onDesktopName': UI
.updateDesktopName
});
218 var msg
= "Unable to create RFB client -- " + exc
;
220 UI
.showStatus(msg
, 'error');
231 addResizeHandlers: function() {
232 window
.addEventListener('resize', UI
.applyResizeMode
);
233 window
.addEventListener('resize', UI
.updateViewClip
);
236 addControlbarHandlers: function() {
237 document
.getElementById("noVNC_control_bar")
238 .addEventListener('mousemove', UI
.activateControlbar
);
239 document
.getElementById("noVNC_control_bar")
240 .addEventListener('mouseup', UI
.activateControlbar
);
241 document
.getElementById("noVNC_control_bar")
242 .addEventListener('mousedown', UI
.activateControlbar
);
243 document
.getElementById("noVNC_control_bar")
244 .addEventListener('keypress', UI
.activateControlbar
);
246 document
.getElementById("noVNC_control_bar")
247 .addEventListener('mousedown', UI
.keepControlbar
);
248 document
.getElementById("noVNC_control_bar")
249 .addEventListener('keypress', UI
.keepControlbar
);
251 document
.getElementById("noVNC_view_drag_button")
252 .addEventListener('click', UI
.toggleViewDrag
);
254 document
.getElementById("noVNC_control_bar_handle")
255 .addEventListener('mousedown', UI
.controlbarHandleMouseDown
);
256 document
.getElementById("noVNC_control_bar_handle")
257 .addEventListener('mouseup', UI
.controlbarHandleMouseUp
);
258 document
.getElementById("noVNC_control_bar_handle")
259 .addEventListener('mousemove', UI
.dragControlbarHandle
);
260 // resize events aren't available for elements
261 window
.addEventListener('resize', UI
.updateControlbarHandle
);
263 var exps
= document
.getElementsByClassName("noVNC_expander");
264 for (var i
= 0;i
< exps
.length
;i
++) {
265 exps
[i
].addEventListener('click', UI
.toggleExpander
);
269 addTouchSpecificHandlers: function() {
270 document
.getElementById("noVNC_mouse_button0")
271 .addEventListener('click', function () { UI
.setMouseButton(1); });
272 document
.getElementById("noVNC_mouse_button1")
273 .addEventListener('click', function () { UI
.setMouseButton(2); });
274 document
.getElementById("noVNC_mouse_button2")
275 .addEventListener('click', function () { UI
.setMouseButton(4); });
276 document
.getElementById("noVNC_mouse_button4")
277 .addEventListener('click', function () { UI
.setMouseButton(0); });
278 document
.getElementById("noVNC_keyboard_button")
279 .addEventListener('click', UI
.toggleVirtualKeyboard
);
281 document
.getElementById("noVNC_keyboardinput")
282 .addEventListener('input', UI
.keyInput
);
283 document
.getElementById("noVNC_keyboardinput")
284 .addEventListener('focus', UI
.onfocusVirtualKeyboard
);
285 document
.getElementById("noVNC_keyboardinput")
286 .addEventListener('blur', UI
.onblurVirtualKeyboard
);
287 document
.getElementById("noVNC_keyboardinput")
288 .addEventListener('submit', function () { return false; });
290 document
.documentElement
291 .addEventListener('mousedown', UI
.keepVirtualKeyboard
, true);
293 document
.getElementById("noVNC_control_bar")
294 .addEventListener('touchstart', UI
.activateControlbar
);
295 document
.getElementById("noVNC_control_bar")
296 .addEventListener('touchmove', UI
.activateControlbar
);
297 document
.getElementById("noVNC_control_bar")
298 .addEventListener('touchend', UI
.activateControlbar
);
299 document
.getElementById("noVNC_control_bar")
300 .addEventListener('input', UI
.activateControlbar
);
302 document
.getElementById("noVNC_control_bar")
303 .addEventListener('touchstart', UI
.keepControlbar
);
304 document
.getElementById("noVNC_control_bar")
305 .addEventListener('input', UI
.keepControlbar
);
307 document
.getElementById("noVNC_control_bar_handle")
308 .addEventListener('touchstart', UI
.controlbarHandleMouseDown
);
309 document
.getElementById("noVNC_control_bar_handle")
310 .addEventListener('touchend', UI
.controlbarHandleMouseUp
);
311 document
.getElementById("noVNC_control_bar_handle")
312 .addEventListener('touchmove', UI
.dragControlbarHandle
);
315 addExtraKeysHandlers: function() {
316 document
.getElementById("noVNC_toggle_extra_keys_button")
317 .addEventListener('click', UI
.toggleExtraKeys
);
318 document
.getElementById("noVNC_toggle_ctrl_button")
319 .addEventListener('click', UI
.toggleCtrl
);
320 document
.getElementById("noVNC_toggle_alt_button")
321 .addEventListener('click', UI
.toggleAlt
);
322 document
.getElementById("noVNC_send_tab_button")
323 .addEventListener('click', UI
.sendTab
);
324 document
.getElementById("noVNC_send_esc_button")
325 .addEventListener('click', UI
.sendEsc
);
326 document
.getElementById("noVNC_send_ctrl_alt_del_button")
327 .addEventListener('click', UI
.sendCtrlAltDel
);
330 addXvpHandlers: function() {
331 document
.getElementById("noVNC_xvp_shutdown_button")
332 .addEventListener('click', function() { UI
.rfb
.xvpShutdown(); });
333 document
.getElementById("noVNC_xvp_reboot_button")
334 .addEventListener('click', function() { UI
.rfb
.xvpReboot(); });
335 document
.getElementById("noVNC_xvp_reset_button")
336 .addEventListener('click', function() { UI
.rfb
.xvpReset(); });
337 document
.getElementById("noVNC_xvp_button")
338 .addEventListener('click', UI
.toggleXvpPanel
);
341 addConnectionControlHandlers: function() {
342 document
.getElementById("noVNC_disconnect_button")
343 .addEventListener('click', UI
.disconnect
);
344 document
.getElementById("noVNC_connect_button")
345 .addEventListener('click', UI
.connect
);
346 document
.getElementById("noVNC_cancel_reconnect_button")
347 .addEventListener('click', UI
.cancelReconnect
);
349 document
.getElementById("noVNC_password_button")
350 .addEventListener('click', UI
.setPassword
);
353 addClipboardHandlers: function() {
354 document
.getElementById("noVNC_clipboard_button")
355 .addEventListener('click', UI
.toggleClipboardPanel
);
356 document
.getElementById("noVNC_clipboard_text")
357 .addEventListener('focus', UI
.displayBlur
);
358 document
.getElementById("noVNC_clipboard_text")
359 .addEventListener('blur', UI
.displayFocus
);
360 document
.getElementById("noVNC_clipboard_text")
361 .addEventListener('change', UI
.clipboardSend
);
362 document
.getElementById("noVNC_clipboard_clear_button")
363 .addEventListener('click', UI
.clipboardClear
);
366 // Add a call to save settings when the element changes,
367 // unless the optional parameter changeFunc is used instead.
368 addSettingChangeHandler: function(name
, changeFunc
) {
369 var settingElem
= document
.getElementById("noVNC_setting_" + name
);
370 if (changeFunc
=== undefined) {
371 changeFunc = function () { UI
.saveSetting(name
); };
373 settingElem
.addEventListener('change', changeFunc
);
376 addSettingsHandlers: function() {
377 document
.getElementById("noVNC_settings_button")
378 .addEventListener('click', UI
.toggleSettingsPanel
);
380 UI
.addSettingChangeHandler('encrypt');
381 UI
.addSettingChangeHandler('cursor');
382 UI
.addSettingChangeHandler('cursor', UI
.updateLocalCursor
);
383 UI
.addSettingChangeHandler('resize');
384 UI
.addSettingChangeHandler('resize', UI
.enableDisableViewClip
);
385 UI
.addSettingChangeHandler('resize', UI
.applyResizeMode
);
386 UI
.addSettingChangeHandler('view_clip');
387 UI
.addSettingChangeHandler('view_clip', UI
.updateViewClip
);
388 UI
.addSettingChangeHandler('shared');
389 UI
.addSettingChangeHandler('view_only');
390 UI
.addSettingChangeHandler('view_only', UI
.updateViewOnly
);
391 UI
.addSettingChangeHandler('host');
392 UI
.addSettingChangeHandler('port');
393 UI
.addSettingChangeHandler('path');
394 UI
.addSettingChangeHandler('repeaterID');
395 UI
.addSettingChangeHandler('logging');
396 UI
.addSettingChangeHandler('logging', UI
.updateLogging
);
397 UI
.addSettingChangeHandler('reconnect');
398 UI
.addSettingChangeHandler('reconnect_delay');
401 addFullscreenHandlers: function() {
402 document
.getElementById("noVNC_fullscreen_button")
403 .addEventListener('click', UI
.toggleFullscreen
);
405 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
406 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
407 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
408 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
417 updateState: function(rfb
, state
, oldstate
) {
420 document
.documentElement
.classList
.remove("noVNC_connecting");
421 document
.documentElement
.classList
.remove("noVNC_connected");
422 document
.documentElement
.classList
.remove("noVNC_disconnecting");
423 document
.documentElement
.classList
.remove("noVNC_reconnecting");
427 document
.getElementById("noVNC_transition_text").textContent
= _("Connecting...");
428 document
.documentElement
.classList
.add("noVNC_connecting");
432 UI
.inhibit_reconnect
= false;
433 document
.documentElement
.classList
.add("noVNC_connected");
434 if (rfb
&& rfb
.get_encrypt()) {
435 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
437 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
441 case 'disconnecting':
442 UI
.connected
= false;
443 document
.getElementById("noVNC_transition_text").textContent
= _("Disconnecting...");
444 document
.documentElement
.classList
.add("noVNC_disconnecting");
447 UI
.showStatus(_("Disconnected"));
450 msg
= "Invalid UI state";
452 UI
.showStatus(msg
, 'error');
456 UI
.updateVisualState();
459 // Disable/enable controls depending on connection state
460 updateVisualState: function() {
461 //Log.Debug(">> updateVisualState");
463 UI
.enableDisableViewClip();
465 if (cursorURIsSupported() && !isTouchDevice
) {
466 UI
.enableSetting('cursor');
468 UI
.disableSetting('cursor');
472 UI
.disableSetting('encrypt');
473 UI
.disableSetting('shared');
474 UI
.disableSetting('host');
475 UI
.disableSetting('port');
476 UI
.disableSetting('path');
477 UI
.disableSetting('repeaterID');
479 UI
.setMouseButton(1);
481 // Hide the controlbar after 2 seconds
482 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
484 UI
.enableSetting('encrypt');
485 UI
.enableSetting('shared');
486 UI
.enableSetting('host');
487 UI
.enableSetting('port');
488 UI
.enableSetting('path');
489 UI
.enableSetting('repeaterID');
490 UI
.updateXvpButton(0);
494 // Hide input related buttons in view only mode
495 if (UI
.rfb
&& UI
.rfb
.get_view_only()) {
496 document
.getElementById('noVNC_keyboard_button')
497 .classList
.add('noVNC_hidden');
498 document
.getElementById('noVNC_toggle_extra_keys_button')
499 .classList
.add('noVNC_hidden');
501 document
.getElementById('noVNC_keyboard_button')
502 .classList
.remove('noVNC_hidden');
503 document
.getElementById('noVNC_toggle_extra_keys_button')
504 .classList
.remove('noVNC_hidden');
507 // State change disables viewport dragging.
508 // It is enabled (toggled) by direct click on the button
509 UI
.setViewDrag(false);
511 // State change also closes the password dialog
512 document
.getElementById('noVNC_password_dlg')
513 .classList
.remove('noVNC_open');
515 //Log.Debug("<< updateVisualState");
518 showStatus: function(text
, status_type
, time
) {
519 var statusElem
= document
.getElementById('noVNC_status');
521 clearTimeout(UI
.statusTimeout
);
523 if (typeof status_type
=== 'undefined') {
524 status_type
= 'normal';
527 statusElem
.classList
.remove("noVNC_status_normal");
528 statusElem
.classList
.remove("noVNC_status_warn");
529 statusElem
.classList
.remove("noVNC_status_error");
531 switch (status_type
) {
534 statusElem
.classList
.add("noVNC_status_warn");
537 statusElem
.classList
.add("noVNC_status_error");
542 statusElem
.classList
.add("noVNC_status_normal");
546 statusElem
.textContent
= text
;
547 statusElem
.classList
.add("noVNC_open");
549 // If no time was specified, show the status for 1.5 seconds
550 if (typeof time
=== 'undefined') {
554 // Error messages do not timeout
555 if (status_type
!== 'error') {
556 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
560 hideStatus: function() {
561 clearTimeout(UI
.statusTimeout
);
562 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
565 notification: function (rfb
, msg
, level
, options
) {
566 UI
.showStatus(msg
, level
);
569 activateControlbar: function(event
) {
570 clearTimeout(UI
.idleControlbarTimeout
);
571 // We manipulate the anchor instead of the actual control
572 // bar in order to avoid creating new a stacking group
573 document
.getElementById('noVNC_control_bar_anchor')
574 .classList
.remove("noVNC_idle");
575 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
578 idleControlbar: function() {
579 document
.getElementById('noVNC_control_bar_anchor')
580 .classList
.add("noVNC_idle");
583 keepControlbar: function() {
584 clearTimeout(UI
.closeControlbarTimeout
);
587 openControlbar: function() {
588 document
.getElementById('noVNC_control_bar')
589 .classList
.add("noVNC_open");
592 closeControlbar: function() {
594 document
.getElementById('noVNC_control_bar')
595 .classList
.remove("noVNC_open");
598 toggleControlbar: function() {
599 if (document
.getElementById('noVNC_control_bar')
600 .classList
.contains("noVNC_open")) {
601 UI
.closeControlbar();
607 toggleControlbarSide: function () {
608 // Temporarily disable animation to avoid weird movement
609 var bar
= document
.getElementById('noVNC_control_bar');
610 bar
.style
.transitionDuration
= '0s';
611 bar
.addEventListener('transitionend', function () { this.style
.transitionDuration
= ""; });
613 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
614 if (anchor
.classList
.contains("noVNC_right")) {
615 WebUtil
.writeSetting('controlbar_pos', 'left');
616 anchor
.classList
.remove("noVNC_right");
618 WebUtil
.writeSetting('controlbar_pos', 'right');
619 anchor
.classList
.add("noVNC_right");
622 // Consider this a movement of the handle
623 UI
.controlbarDrag
= true;
626 showControlbarHint: function (show
) {
627 var hint
= document
.getElementById('noVNC_control_bar_hint');
629 hint
.classList
.add("noVNC_active");
631 hint
.classList
.remove("noVNC_active");
635 dragControlbarHandle: function (e
) {
636 if (!UI
.controlbarGrabbed
) return;
638 var ptr
= getPointerEvent(e
);
640 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
641 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
642 if (anchor
.classList
.contains("noVNC_right")) {
643 UI
.toggleControlbarSide();
645 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
646 if (!anchor
.classList
.contains("noVNC_right")) {
647 UI
.toggleControlbarSide();
651 if (!UI
.controlbarDrag
) {
652 // The goal is to trigger on a certain physical width, the
653 // devicePixelRatio brings us a bit closer but is not optimal.
654 var dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
655 var dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
657 if (dragDistance
< dragThreshold
) return;
659 UI
.controlbarDrag
= true;
662 var eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
664 UI
.moveControlbarHandle(eventY
);
669 UI
.activateControlbar();
672 // Move the handle but don't allow any position outside the bounds
673 moveControlbarHandle: function (viewportRelativeY
) {
674 var handle
= document
.getElementById("noVNC_control_bar_handle");
675 var handleHeight
= handle
.getBoundingClientRect().height
;
676 var controlbarBounds
= document
.getElementById("noVNC_control_bar")
677 .getBoundingClientRect();
680 // These heights need to be non-zero for the below logic to work
681 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
685 var newY
= viewportRelativeY
;
687 // Check if the coordinates are outside the control bar
688 if (newY
< controlbarBounds
.top
+ margin
) {
689 // Force coordinates to be below the top of the control bar
690 newY
= controlbarBounds
.top
+ margin
;
692 } else if (newY
> controlbarBounds
.top
+
693 controlbarBounds
.height
- handleHeight
- margin
) {
694 // Force coordinates to be above the bottom of the control bar
695 newY
= controlbarBounds
.top
+
696 controlbarBounds
.height
- handleHeight
- margin
;
699 // Corner case: control bar too small for stable position
700 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
701 newY
= controlbarBounds
.top
+
702 (controlbarBounds
.height
- handleHeight
) / 2;
705 // The transform needs coordinates that are relative to the parent
706 var parentRelativeY
= newY
- controlbarBounds
.top
;
707 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
710 updateControlbarHandle: function () {
711 // Since the control bar is fixed on the viewport and not the page,
712 // the move function expects coordinates relative the the viewport.
713 var handle
= document
.getElementById("noVNC_control_bar_handle");
714 var handleBounds
= handle
.getBoundingClientRect();
715 UI
.moveControlbarHandle(handleBounds
.top
);
718 controlbarHandleMouseUp: function(e
) {
719 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
721 // mouseup and mousedown on the same place toggles the controlbar
722 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
723 UI
.toggleControlbar();
727 UI
.activateControlbar();
729 UI
.controlbarGrabbed
= false;
730 UI
.showControlbarHint(false);
733 controlbarHandleMouseDown: function(e
) {
734 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
736 var ptr
= getPointerEvent(e
);
738 var handle
= document
.getElementById("noVNC_control_bar_handle");
739 var bounds
= handle
.getBoundingClientRect();
741 // Touch events have implicit capture
742 if (e
.type
=== "mousedown") {
746 UI
.controlbarGrabbed
= true;
747 UI
.controlbarDrag
= false;
749 UI
.showControlbarHint(true);
751 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
752 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
756 UI
.activateControlbar();
759 toggleExpander: function(e
) {
760 if (this.classList
.contains("noVNC_open")) {
761 this.classList
.remove("noVNC_open");
763 this.classList
.add("noVNC_open");
773 // Initial page load read/initialization of settings
774 initSetting: function(name
, defVal
) {
775 // Check Query string followed by cookie
776 var val
= WebUtil
.getConfigVar(name
);
778 val
= WebUtil
.readSetting(name
, defVal
);
780 UI
.updateSetting(name
, val
);
784 // Update cookie and form control setting. If value is not set, then
785 // updates from control to current cookie setting.
786 updateSetting: function(name
, value
) {
788 // Save the cookie for this session
789 if (typeof value
!== 'undefined') {
790 WebUtil
.writeSetting(name
, value
);
793 // Update the settings control
794 value
= UI
.getSetting(name
);
796 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
797 if (ctrl
.type
=== 'checkbox') {
798 ctrl
.checked
= value
;
800 } else if (typeof ctrl
.options
!== 'undefined') {
801 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
802 if (ctrl
.options
[i
].value
=== value
) {
803 ctrl
.selectedIndex
= i
;
808 /*Weird IE9 error leads to 'null' appearring
809 in textboxes instead of ''.*/
810 if (value
=== null) {
817 // Save control setting to cookie
818 saveSetting: function(name
) {
819 var val
, ctrl
= document
.getElementById('noVNC_setting_' + name
);
820 if (ctrl
.type
=== 'checkbox') {
822 } else if (typeof ctrl
.options
!== 'undefined') {
823 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
827 WebUtil
.writeSetting(name
, val
);
828 //Log.Debug("Setting saved '" + name + "=" + val + "'");
832 // Read form control compatible setting from cookie
833 getSetting: function(name
) {
834 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
835 var val
= WebUtil
.readSetting(name
);
836 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
837 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
846 // These helpers compensate for the lack of parent-selectors and
847 // previous-sibling-selectors in CSS which are needed when we want to
848 // disable the labels that belong to disabled input elements.
849 disableSetting: function(name
) {
850 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
851 ctrl
.disabled
= true;
852 ctrl
.label
.classList
.add('noVNC_disabled');
855 enableSetting: function(name
) {
856 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
857 ctrl
.disabled
= false;
858 ctrl
.label
.classList
.remove('noVNC_disabled');
867 closeAllPanels: function() {
868 UI
.closeSettingsPanel();
870 UI
.closeClipboardPanel();
880 openSettingsPanel: function() {
884 // Refresh UI elements from saved cookies
885 UI
.updateSetting('encrypt');
886 if (cursorURIsSupported()) {
887 UI
.updateSetting('cursor');
889 UI
.updateSetting('cursor', !isTouchDevice
);
890 UI
.disableSetting('cursor');
892 UI
.updateSetting('view_clip');
893 UI
.updateSetting('resize');
894 UI
.updateSetting('shared');
895 UI
.updateSetting('view_only');
896 UI
.updateSetting('path');
897 UI
.updateSetting('repeaterID');
898 UI
.updateSetting('logging');
899 UI
.updateSetting('reconnect');
900 UI
.updateSetting('reconnect_delay');
902 document
.getElementById('noVNC_settings')
903 .classList
.add("noVNC_open");
904 document
.getElementById('noVNC_settings_button')
905 .classList
.add("noVNC_selected");
908 closeSettingsPanel: function() {
909 document
.getElementById('noVNC_settings')
910 .classList
.remove("noVNC_open");
911 document
.getElementById('noVNC_settings_button')
912 .classList
.remove("noVNC_selected");
915 toggleSettingsPanel: function() {
916 if (document
.getElementById('noVNC_settings')
917 .classList
.contains("noVNC_open")) {
918 UI
.closeSettingsPanel();
920 UI
.openSettingsPanel();
930 openXvpPanel: function() {
934 document
.getElementById('noVNC_xvp')
935 .classList
.add("noVNC_open");
936 document
.getElementById('noVNC_xvp_button')
937 .classList
.add("noVNC_selected");
940 closeXvpPanel: function() {
941 document
.getElementById('noVNC_xvp')
942 .classList
.remove("noVNC_open");
943 document
.getElementById('noVNC_xvp_button')
944 .classList
.remove("noVNC_selected");
947 toggleXvpPanel: function() {
948 if (document
.getElementById('noVNC_xvp')
949 .classList
.contains("noVNC_open")) {
956 // Disable/enable XVP button
957 updateXvpButton: function(ver
) {
958 if (ver
>= 1 && !UI
.rfb
.get_view_only()) {
959 document
.getElementById('noVNC_xvp_button')
960 .classList
.remove("noVNC_hidden");
962 document
.getElementById('noVNC_xvp_button')
963 .classList
.add("noVNC_hidden");
964 // Close XVP panel if open
975 openClipboardPanel: function() {
979 document
.getElementById('noVNC_clipboard')
980 .classList
.add("noVNC_open");
981 document
.getElementById('noVNC_clipboard_button')
982 .classList
.add("noVNC_selected");
985 closeClipboardPanel: function() {
986 document
.getElementById('noVNC_clipboard')
987 .classList
.remove("noVNC_open");
988 document
.getElementById('noVNC_clipboard_button')
989 .classList
.remove("noVNC_selected");
992 toggleClipboardPanel: function() {
993 if (document
.getElementById('noVNC_clipboard')
994 .classList
.contains("noVNC_open")) {
995 UI
.closeClipboardPanel();
997 UI
.openClipboardPanel();
1001 clipboardReceive: function(rfb
, text
) {
1002 Log
.Debug(">> UI.clipboardReceive: " + text
.substr(0,40) + "...");
1003 document
.getElementById('noVNC_clipboard_text').value
= text
;
1004 Log
.Debug("<< UI.clipboardReceive");
1007 clipboardClear: function() {
1008 document
.getElementById('noVNC_clipboard_text').value
= "";
1009 UI
.rfb
.clipboardPasteFrom("");
1012 clipboardSend: function() {
1013 var text
= document
.getElementById('noVNC_clipboard_text').value
;
1014 Log
.Debug(">> UI.clipboardSend: " + text
.substr(0,40) + "...");
1015 UI
.rfb
.clipboardPasteFrom(text
);
1016 Log
.Debug("<< UI.clipboardSend");
1025 openConnectPanel: function() {
1026 document
.getElementById('noVNC_connect_dlg')
1027 .classList
.add("noVNC_open");
1030 closeConnectPanel: function() {
1031 document
.getElementById('noVNC_connect_dlg')
1032 .classList
.remove("noVNC_open");
1035 connect: function(event
, password
) {
1036 var host
= UI
.getSetting('host');
1037 var port
= UI
.getSetting('port');
1038 var path
= UI
.getSetting('path');
1040 if (typeof password
=== 'undefined') {
1041 password
= WebUtil
.getConfigVar('password');
1042 UI
.reconnect_password
= password
;
1045 if (password
=== null) {
1046 password
= undefined;
1050 var msg
= _("Must set host");
1052 UI
.showStatus(msg
, 'error');
1056 if (!UI
.initRFB()) return;
1058 UI
.closeAllPanels();
1059 UI
.closeConnectPanel();
1061 UI
.rfb
.set_encrypt(UI
.getSetting('encrypt'));
1062 UI
.rfb
.set_shared(UI
.getSetting('shared'));
1063 UI
.rfb
.set_repeaterID(UI
.getSetting('repeaterID'));
1065 UI
.updateLocalCursor();
1066 UI
.updateViewOnly();
1068 UI
.rfb
.connect(host
, port
, password
, path
);
1071 disconnect: function() {
1072 UI
.closeAllPanels();
1073 UI
.rfb
.disconnect();
1075 // Disable automatic reconnecting
1076 UI
.inhibit_reconnect
= true;
1078 // Restore the callback used for initial resize
1079 UI
.rfb
.set_onFBUComplete(UI
.initialResize
);
1081 // Don't display the connection settings until we're actually disconnected
1084 reconnect: function() {
1085 UI
.reconnect_callback
= null;
1087 // if reconnect has been disabled in the meantime, do nothing.
1088 if (UI
.inhibit_reconnect
) {
1092 UI
.connect(null, UI
.reconnect_password
);
1095 disconnectFinished: function (rfb
, reason
) {
1096 if (typeof reason
!== 'undefined') {
1097 UI
.showStatus(reason
, 'error');
1098 } else if (UI
.getSetting('reconnect', false) === true && !UI
.inhibit_reconnect
) {
1099 document
.getElementById("noVNC_transition_text").textContent
= _("Reconnecting...");
1100 document
.documentElement
.classList
.add("noVNC_reconnecting");
1102 var delay
= parseInt(UI
.getSetting('reconnect_delay'));
1103 UI
.reconnect_callback
= setTimeout(UI
.reconnect
, delay
);
1107 UI
.openControlbar();
1108 UI
.openConnectPanel();
1111 cancelReconnect: function() {
1112 if (UI
.reconnect_callback
!== null) {
1113 clearTimeout(UI
.reconnect_callback
);
1114 UI
.reconnect_callback
= null;
1117 document
.documentElement
.classList
.remove("noVNC_reconnecting");
1118 UI
.openControlbar();
1119 UI
.openConnectPanel();
1128 passwordRequired: function(rfb
, msg
) {
1130 document
.getElementById('noVNC_password_dlg')
1131 .classList
.add('noVNC_open');
1133 setTimeout(function () {
1134 document
.getElementById('noVNC_password_input').focus();
1137 if (typeof msg
=== 'undefined') {
1138 msg
= _("Password is required");
1141 UI
.showStatus(msg
, "warning");
1144 setPassword: function(e
) {
1145 var inputElem
= document
.getElementById('noVNC_password_input');
1146 var password
= inputElem
.value
;
1147 // Clear the input after reading the password
1148 inputElem
.value
= "";
1149 UI
.rfb
.sendPassword(password
);
1150 UI
.reconnect_password
= password
;
1151 document
.getElementById('noVNC_password_dlg')
1152 .classList
.remove('noVNC_open');
1153 // Prevent actually submitting the form
1163 toggleFullscreen: function() {
1164 if (document
.fullscreenElement
|| // alternative standard method
1165 document
.mozFullScreenElement
|| // currently working methods
1166 document
.webkitFullscreenElement
||
1167 document
.msFullscreenElement
) {
1168 if (document
.exitFullscreen
) {
1169 document
.exitFullscreen();
1170 } else if (document
.mozCancelFullScreen
) {
1171 document
.mozCancelFullScreen();
1172 } else if (document
.webkitExitFullscreen
) {
1173 document
.webkitExitFullscreen();
1174 } else if (document
.msExitFullscreen
) {
1175 document
.msExitFullscreen();
1178 if (document
.documentElement
.requestFullscreen
) {
1179 document
.documentElement
.requestFullscreen();
1180 } else if (document
.documentElement
.mozRequestFullScreen
) {
1181 document
.documentElement
.mozRequestFullScreen();
1182 } else if (document
.documentElement
.webkitRequestFullscreen
) {
1183 document
.documentElement
.webkitRequestFullscreen(Element
.ALLOW_KEYBOARD_INPUT
);
1184 } else if (document
.body
.msRequestFullscreen
) {
1185 document
.body
.msRequestFullscreen();
1188 UI
.enableDisableViewClip();
1189 UI
.updateFullscreenButton();
1192 updateFullscreenButton: function() {
1193 if (document
.fullscreenElement
|| // alternative standard method
1194 document
.mozFullScreenElement
|| // currently working methods
1195 document
.webkitFullscreenElement
||
1196 document
.msFullscreenElement
) {
1197 document
.getElementById('noVNC_fullscreen_button')
1198 .classList
.add("noVNC_selected");
1200 document
.getElementById('noVNC_fullscreen_button')
1201 .classList
.remove("noVNC_selected");
1211 // Apply remote resizing or local scaling
1212 applyResizeMode: function() {
1213 if (!UI
.rfb
) return;
1215 var screen
= UI
.screenSize();
1217 if (screen
&& UI
.connected
&& UI
.rfb
.get_display()) {
1219 var display
= UI
.rfb
.get_display();
1220 var resizeMode
= UI
.getSetting('resize');
1221 display
.set_scale(1);
1223 // Make sure the viewport is adjusted first
1224 UI
.updateViewClip();
1226 if (resizeMode
=== 'remote') {
1228 // Request changing the resolution of the remote display to
1229 // the size of the local browser viewport.
1231 // In order to not send multiple requests before the browser-resize
1232 // is finished we wait 0.5 seconds before sending the request.
1233 clearTimeout(UI
.resizeTimeout
);
1234 UI
.resizeTimeout
= setTimeout(function(){
1235 // Request a remote size covering the viewport
1236 if (UI
.rfb
.requestDesktopSize(screen
.w
, screen
.h
)) {
1237 Log
.Debug('Requested new desktop size: ' +
1238 screen
.w
+ 'x' + screen
.h
);
1248 // Re-calculate local scaling
1249 updateScaling: function() {
1250 if (!UI
.rfb
) return;
1252 var resizeMode
= UI
.getSetting('resize');
1253 if (resizeMode
!== 'scale' && resizeMode
!== 'downscale') {
1257 var screen
= UI
.screenSize();
1259 if (!screen
|| !UI
.connected
|| !UI
.rfb
.get_display()) {
1263 var display
= UI
.rfb
.get_display();
1264 var downscaleOnly
= resizeMode
=== 'downscale';
1265 display
.autoscale(screen
.w
, screen
.h
, downscaleOnly
);
1269 // Gets the the size of the available viewport in the browser window
1270 screenSize: function() {
1271 var screen
= document
.getElementById('noVNC_screen');
1272 return {w
: screen
.offsetWidth
, h
: screen
.offsetHeight
};
1275 // Normally we only apply the current resize mode after a window resize
1276 // event. This means that when a new connection is opened, there is no
1277 // resize mode active.
1278 // We have to wait until the first FBU because this is where the client
1279 // will find the supported encodings of the server. Some calls later in
1280 // the chain is dependant on knowing the server-capabilities.
1281 initialResize: function(rfb
, fbu
) {
1282 UI
.applyResizeMode();
1283 // After doing this once, we remove the callback.
1284 UI
.rfb
.set_onFBUComplete(function() { });
1293 // Set and configure viewport clipping
1294 setViewClip: function(clip
) {
1295 UI
.updateSetting('view_clip', clip
);
1296 UI
.updateViewClip();
1299 // Update parameters that depend on the viewport clip setting
1300 updateViewClip: function() {
1301 if (!UI
.rfb
) return;
1303 var display
= UI
.rfb
.get_display();
1304 var cur_clip
= display
.get_viewport();
1305 var new_clip
= UI
.getSetting('view_clip');
1307 var resizeSetting
= UI
.getSetting('resize');
1308 if (resizeSetting
=== 'downscale' || resizeSetting
=== 'scale') {
1309 // Disable viewport clipping if we are scaling
1311 } else if (isTouchDevice
) {
1312 // Touch devices usually have shit scrollbars
1316 if (cur_clip
!== new_clip
) {
1317 display
.set_viewport(new_clip
);
1320 var size
= UI
.screenSize();
1322 if (new_clip
&& size
) {
1323 // When clipping is enabled, the screen is limited to
1324 // the size of the browser window.
1325 display
.viewportChangeSize(size
.w
, size
.h
);
1329 // Changing the viewport may change the state of
1330 // the dragging button
1331 UI
.updateViewDrag();
1334 // Handle special cases where viewport clipping is forced on/off or locked
1335 enableDisableViewClip: function() {
1336 var resizeSetting
= UI
.getSetting('resize');
1337 // Disable clipping if we are scaling, connected or on touch
1338 if (resizeSetting
=== 'downscale' || resizeSetting
=== 'scale' ||
1340 UI
.disableSetting('view_clip');
1342 UI
.enableSetting('view_clip');
1352 toggleViewDrag: function() {
1353 if (!UI
.rfb
) return;
1355 var drag
= UI
.rfb
.get_viewportDrag();
1356 UI
.setViewDrag(!drag
);
1359 // Set the view drag mode which moves the viewport on mouse drags
1360 setViewDrag: function(drag
) {
1361 if (!UI
.rfb
) return;
1363 UI
.rfb
.set_viewportDrag(drag
);
1365 UI
.updateViewDrag();
1368 updateViewDrag: function() {
1369 var clipping
= false;
1371 if (!UI
.connected
) return;
1373 // Check if viewport drag is possible. It is only possible
1374 // if the remote display is clipping the client display.
1375 if (UI
.rfb
.get_display().get_viewport() &&
1376 UI
.rfb
.get_display().clippingDisplay()) {
1380 var viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1383 UI
.rfb
.get_viewportDrag()) {
1384 // The size of the remote display is the same or smaller
1385 // than the client display. Make sure viewport drag isn't
1386 // active when it can't be used.
1387 UI
.rfb
.set_viewportDrag(false);
1390 if (UI
.rfb
.get_viewportDrag()) {
1391 viewDragButton
.classList
.add("noVNC_selected");
1393 viewDragButton
.classList
.remove("noVNC_selected");
1396 // Different behaviour for touch vs non-touch
1397 // The button is disabled instead of hidden on touch devices
1398 if (isTouchDevice
) {
1399 viewDragButton
.classList
.remove("noVNC_hidden");
1402 viewDragButton
.disabled
= false;
1404 viewDragButton
.disabled
= true;
1407 viewDragButton
.disabled
= false;
1410 viewDragButton
.classList
.remove("noVNC_hidden");
1412 viewDragButton
.classList
.add("noVNC_hidden");
1423 showVirtualKeyboard: function() {
1424 if (!isTouchDevice
) return;
1426 var input
= document
.getElementById('noVNC_keyboardinput');
1428 if (document
.activeElement
== input
) return;
1433 var l
= input
.value
.length
;
1434 // Move the caret to the end
1435 input
.setSelectionRange(l
, l
);
1436 } catch (err
) {} // setSelectionRange is undefined in Google Chrome
1439 hideVirtualKeyboard: function() {
1440 if (!isTouchDevice
) return;
1442 var input
= document
.getElementById('noVNC_keyboardinput');
1444 if (document
.activeElement
!= input
) return;
1449 toggleVirtualKeyboard: function () {
1450 if (document
.getElementById('noVNC_keyboard_button')
1451 .classList
.contains("noVNC_selected")) {
1452 UI
.hideVirtualKeyboard();
1454 UI
.showVirtualKeyboard();
1458 onfocusVirtualKeyboard: function(event
) {
1459 document
.getElementById('noVNC_keyboard_button')
1460 .classList
.add("noVNC_selected");
1463 onblurVirtualKeyboard: function(event
) {
1464 document
.getElementById('noVNC_keyboard_button')
1465 .classList
.remove("noVNC_selected");
1468 keepVirtualKeyboard: function(event
) {
1469 var input
= document
.getElementById('noVNC_keyboardinput');
1471 // Only prevent focus change if the virtual keyboard is active
1472 if (document
.activeElement
!= input
) {
1476 // Only allow focus to move to other elements that need
1477 // focus to function properly
1478 if (event
.target
.form
!== undefined) {
1479 switch (event
.target
.type
) {
1488 case 'select-multiple':
1493 event
.preventDefault();
1496 keyboardinputReset: function() {
1497 var kbi
= document
.getElementById('noVNC_keyboardinput');
1498 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1499 UI
.lastKeyboardinput
= kbi
.value
;
1502 // When normal keyboard events are left uncought, use the input events from
1503 // the keyboardinput element instead and generate the corresponding key events.
1504 // This code is required since some browsers on Android are inconsistent in
1505 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1506 keyInput: function(event
) {
1508 if (!UI
.rfb
) return;
1510 var newValue
= event
.target
.value
;
1512 if (!UI
.lastKeyboardinput
) {
1513 UI
.keyboardinputReset();
1515 var oldValue
= UI
.lastKeyboardinput
;
1519 // Try to check caret position since whitespace at the end
1520 // will not be considered by value.length in some browsers
1521 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1523 // selectionStart is undefined in Google Chrome
1524 newLen
= newValue
.length
;
1526 var oldLen
= oldValue
.length
;
1529 var inputs
= newLen
- oldLen
;
1531 backspaces
= -inputs
;
1536 // Compare the old string with the new to account for
1537 // text-corrections or other input that modify existing text
1539 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1540 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1541 inputs
= newLen
- i
;
1542 backspaces
= oldLen
- i
;
1547 // Send the key events
1548 for (i
= 0; i
< backspaces
; i
++) {
1549 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
, "Backspace");
1551 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1552 UI
.rfb
.sendKey(keysyms
.lookup(newValue
.charCodeAt(i
)));
1555 // Control the text content length in the keyboardinput element
1556 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1557 UI
.keyboardinputReset();
1558 } else if (newLen
< 1) {
1559 // There always have to be some text in the keyboardinput
1560 // element with which backspace can interact.
1561 UI
.keyboardinputReset();
1562 // This sometimes causes the keyboard to disappear for a second
1563 // but it is required for the android keyboard to recognize that
1564 // text has been added to the field
1565 event
.target
.blur();
1566 // This has to be ran outside of the input handler in order to work
1567 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1569 UI
.lastKeyboardinput
= newValue
;
1579 openExtraKeys: function() {
1580 UI
.closeAllPanels();
1581 UI
.openControlbar();
1583 document
.getElementById('noVNC_modifiers')
1584 .classList
.add("noVNC_open");
1585 document
.getElementById('noVNC_toggle_extra_keys_button')
1586 .classList
.add("noVNC_selected");
1589 closeExtraKeys: function() {
1590 document
.getElementById('noVNC_modifiers')
1591 .classList
.remove("noVNC_open");
1592 document
.getElementById('noVNC_toggle_extra_keys_button')
1593 .classList
.remove("noVNC_selected");
1596 toggleExtraKeys: function() {
1597 if(document
.getElementById('noVNC_modifiers')
1598 .classList
.contains("noVNC_open")) {
1599 UI
.closeExtraKeys();
1605 sendEsc: function() {
1606 UI
.rfb
.sendKey(KeyTable
.XK_Escape
, "Escape");
1609 sendTab: function() {
1610 UI
.rfb
.sendKey(KeyTable
.XK_Tab
);
1613 toggleCtrl: function() {
1614 var btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1615 if (btn
.classList
.contains("noVNC_selected")) {
1616 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", false);
1617 btn
.classList
.remove("noVNC_selected");
1619 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", true);
1620 btn
.classList
.add("noVNC_selected");
1624 toggleAlt: function() {
1625 var btn
= document
.getElementById('noVNC_toggle_alt_button');
1626 if (btn
.classList
.contains("noVNC_selected")) {
1627 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", false);
1628 btn
.classList
.remove("noVNC_selected");
1630 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", true);
1631 btn
.classList
.add("noVNC_selected");
1635 sendCtrlAltDel: function() {
1636 UI
.rfb
.sendCtrlAltDel();
1645 setMouseButton: function(num
) {
1646 var view_only
= UI
.rfb
.get_view_only();
1647 if (UI
.rfb
&& !view_only
) {
1648 UI
.rfb
.get_mouse().set_touchButton(num
);
1651 var blist
= [0, 1,2,4];
1652 for (var b
= 0; b
< blist
.length
; b
++) {
1653 var button
= document
.getElementById('noVNC_mouse_button' +
1655 if (blist
[b
] === num
&& !view_only
) {
1656 button
.classList
.remove("noVNC_hidden");
1658 button
.classList
.add("noVNC_hidden");
1663 displayBlur: function() {
1664 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1665 UI
.rfb
.get_keyboard().set_focused(false);
1666 UI
.rfb
.get_mouse().set_focused(false);
1670 displayFocus: function() {
1671 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1672 UI
.rfb
.get_keyboard().set_focused(true);
1673 UI
.rfb
.get_mouse().set_focused(true);
1677 updateLocalCursor: function() {
1678 if (!UI
.rfb
) return;
1679 UI
.rfb
.set_local_cursor(UI
.getSetting('cursor'));
1682 updateViewOnly: function() {
1683 if (!UI
.rfb
) return;
1684 UI
.rfb
.set_view_only(UI
.getSetting('view_only'));
1687 updateLogging: function() {
1688 WebUtil
.init_logging(UI
.getSetting('logging'));
1691 updateSessionSize: function(rfb
, width
, height
) {
1692 UI
.updateViewClip();
1697 fixScrollbars: function() {
1698 // This is a hack because Chrome screws up the calculation
1699 // for when scrollbars are needed. So to fix it we temporarily
1700 // toggle them off and on.
1701 var screen
= document
.getElementById('noVNC_screen');
1702 screen
.style
.overflow
= 'hidden';
1703 // Force Chrome to recalculate the layout by asking for
1704 // an element's dimensions
1705 screen
.getBoundingClientRect();
1706 screen
.style
.overflow
= "";
1709 updateDesktopName: function(rfb
, name
) {
1710 UI
.desktopName
= name
;
1711 // Display the desktop name in the document title
1712 document
.title
= name
+ " - noVNC";
1715 bell: function(rfb
) {
1716 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1717 var promise
= document
.getElementById('noVNC_bell').play();
1718 // The standards disagree on the return value here
1720 promise
.catch(function(e
) {
1721 if (e
.name
=== "NotAllowedError") {
1722 // Ignore when the browser doesn't let us play audio.
1723 // It is common that the browsers require audio to be
1724 // initiated from a user action.
1726 Log
.Error("Unable to play bell: " + e
);
1733 //Helper to add options to dropdown.
1734 addOption: function(selectbox
, text
, value
) {
1735 var optn
= document
.createElement("OPTION");
1738 selectbox
.options
.add(optn
);
1747 // Set up translations
1748 var LINGUAS
= ["de", "el", "nl", "pl", "sv"];
1749 l10n
.setup(LINGUAS
);
1750 if (l10n
.language
!== "en" && l10n
.dictionary
=== undefined) {
1751 WebUtil
.fetchJSON('app/locale/' + l10n
.language
+ '.json', function (translations
) {
1752 l10n
.dictionary
= translations
;
1754 // wait for translations to load before loading the UI