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();
105 // Show the connect panel on first load unless autoconnecting
107 UI
.openConnectPanel();
112 UI
.updateVisualState();
114 document
.getElementById('noVNC_setting_host').focus();
115 document
.documentElement
.classList
.remove("noVNC_loading");
117 var autoconnect
= WebUtil
.getConfigVar('autoconnect', false);
118 if (autoconnect
=== 'true' || autoconnect
== '1') {
125 if (typeof callback
=== "function") {
130 initFullscreen: function() {
131 // Only show the button if fullscreen is properly supported
132 // * Safari doesn't support alphanumerical input while in fullscreen
134 (document
.documentElement
.requestFullscreen
||
135 document
.documentElement
.mozRequestFullScreen
||
136 document
.documentElement
.webkitRequestFullscreen
||
137 document
.body
.msRequestFullscreen
)) {
138 document
.getElementById('noVNC_fullscreen_button')
139 .classList
.remove("noVNC_hidden");
140 UI
.addFullscreenHandlers();
144 initSettings: function() {
147 // Logging selection dropdown
148 var llevels
= ['error', 'warn', 'info', 'debug'];
149 for (i
= 0; i
< llevels
.length
; i
+= 1) {
150 UI
.addOption(document
.getElementById('noVNC_setting_logging'),llevels
[i
], llevels
[i
]);
153 // Settings with immediate effects
154 UI
.initSetting('logging', 'warn');
157 // if port == 80 (or 443) then it won't be present and should be
159 var port
= window
.location
.port
;
161 if (window
.location
.protocol
.substring(0,5) == 'https') {
164 else if (window
.location
.protocol
.substring(0,4) == 'http') {
169 /* Populate the controls if defaults are provided in the URL */
170 UI
.initSetting('host', window
.location
.hostname
);
171 UI
.initSetting('port', port
);
172 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
173 UI
.initSetting('cursor', !isTouchDevice
);
174 UI
.initSetting('view_clip', false);
175 UI
.initSetting('resize', 'off');
176 UI
.initSetting('shared', true);
177 UI
.initSetting('view_only', false);
178 UI
.initSetting('path', 'websockify');
179 UI
.initSetting('repeaterID', '');
180 UI
.initSetting('reconnect', false);
181 UI
.initSetting('reconnect_delay', 5000);
183 UI
.setupSettingLabels();
185 // Adds a link to the label elements on the corresponding input elements
186 setupSettingLabels: function() {
187 var labels
= document
.getElementsByTagName('LABEL');
188 for (var i
= 0; i
< labels
.length
; i
++) {
189 var htmlFor
= labels
[i
].htmlFor
;
191 var elem
= document
.getElementById(htmlFor
);
192 if (elem
) elem
.label
= labels
[i
];
194 // If 'for' isn't set, use the first input element child
195 var children
= labels
[i
].children
;
196 for (var j
= 0; j
< children
.length
; j
++) {
197 if (children
[j
].form
!== undefined) {
198 children
[j
].label
= labels
[i
];
206 initRFB: function() {
208 UI
.rfb
= new RFB({'target': document
.getElementById('noVNC_canvas'),
209 'onNotification': UI
.notification
,
210 'onUpdateState': UI
.updateState
,
211 'onDisconnected': UI
.disconnectFinished
,
212 'onPasswordRequired': UI
.passwordRequired
,
213 'onXvpInit': UI
.updateXvpButton
,
214 'onClipboard': UI
.clipboardReceive
,
216 'onFBUComplete': UI
.initialResize
,
217 'onFBResize': UI
.updateSessionSize
,
218 'onDesktopName': UI
.updateDesktopName
});
221 var msg
= "Unable to create RFB client -- " + exc
;
223 UI
.showStatus(msg
, 'error');
234 addResizeHandlers: function() {
235 window
.addEventListener('resize', UI
.applyResizeMode
);
236 window
.addEventListener('resize', UI
.updateViewClip
);
239 addControlbarHandlers: function() {
240 document
.getElementById("noVNC_control_bar")
241 .addEventListener('mousemove', UI
.activateControlbar
);
242 document
.getElementById("noVNC_control_bar")
243 .addEventListener('mouseup', UI
.activateControlbar
);
244 document
.getElementById("noVNC_control_bar")
245 .addEventListener('mousedown', UI
.activateControlbar
);
246 document
.getElementById("noVNC_control_bar")
247 .addEventListener('keypress', UI
.activateControlbar
);
249 document
.getElementById("noVNC_control_bar")
250 .addEventListener('mousedown', UI
.keepControlbar
);
251 document
.getElementById("noVNC_control_bar")
252 .addEventListener('keypress', UI
.keepControlbar
);
254 document
.getElementById("noVNC_view_drag_button")
255 .addEventListener('click', UI
.toggleViewDrag
);
257 document
.getElementById("noVNC_control_bar_handle")
258 .addEventListener('mousedown', UI
.controlbarHandleMouseDown
);
259 document
.getElementById("noVNC_control_bar_handle")
260 .addEventListener('mouseup', UI
.controlbarHandleMouseUp
);
261 document
.getElementById("noVNC_control_bar_handle")
262 .addEventListener('mousemove', UI
.dragControlbarHandle
);
263 // resize events aren't available for elements
264 window
.addEventListener('resize', UI
.updateControlbarHandle
);
266 var exps
= document
.getElementsByClassName("noVNC_expander");
267 for (var i
= 0;i
< exps
.length
;i
++) {
268 exps
[i
].addEventListener('click', UI
.toggleExpander
);
272 addTouchSpecificHandlers: function() {
273 document
.getElementById("noVNC_mouse_button0")
274 .addEventListener('click', function () { UI
.setMouseButton(1); });
275 document
.getElementById("noVNC_mouse_button1")
276 .addEventListener('click', function () { UI
.setMouseButton(2); });
277 document
.getElementById("noVNC_mouse_button2")
278 .addEventListener('click', function () { UI
.setMouseButton(4); });
279 document
.getElementById("noVNC_mouse_button4")
280 .addEventListener('click', function () { UI
.setMouseButton(0); });
281 document
.getElementById("noVNC_keyboard_button")
282 .addEventListener('click', UI
.toggleVirtualKeyboard
);
284 document
.getElementById("noVNC_keyboardinput")
285 .addEventListener('input', UI
.keyInput
);
286 document
.getElementById("noVNC_keyboardinput")
287 .addEventListener('focus', UI
.onfocusVirtualKeyboard
);
288 document
.getElementById("noVNC_keyboardinput")
289 .addEventListener('blur', UI
.onblurVirtualKeyboard
);
290 document
.getElementById("noVNC_keyboardinput")
291 .addEventListener('submit', function () { return false; });
293 document
.documentElement
294 .addEventListener('mousedown', UI
.keepVirtualKeyboard
, true);
296 document
.getElementById("noVNC_control_bar")
297 .addEventListener('touchstart', UI
.activateControlbar
);
298 document
.getElementById("noVNC_control_bar")
299 .addEventListener('touchmove', UI
.activateControlbar
);
300 document
.getElementById("noVNC_control_bar")
301 .addEventListener('touchend', UI
.activateControlbar
);
302 document
.getElementById("noVNC_control_bar")
303 .addEventListener('input', UI
.activateControlbar
);
305 document
.getElementById("noVNC_control_bar")
306 .addEventListener('touchstart', UI
.keepControlbar
);
307 document
.getElementById("noVNC_control_bar")
308 .addEventListener('input', UI
.keepControlbar
);
310 document
.getElementById("noVNC_control_bar_handle")
311 .addEventListener('touchstart', UI
.controlbarHandleMouseDown
);
312 document
.getElementById("noVNC_control_bar_handle")
313 .addEventListener('touchend', UI
.controlbarHandleMouseUp
);
314 document
.getElementById("noVNC_control_bar_handle")
315 .addEventListener('touchmove', UI
.dragControlbarHandle
);
318 addExtraKeysHandlers: function() {
319 document
.getElementById("noVNC_toggle_extra_keys_button")
320 .addEventListener('click', UI
.toggleExtraKeys
);
321 document
.getElementById("noVNC_toggle_ctrl_button")
322 .addEventListener('click', UI
.toggleCtrl
);
323 document
.getElementById("noVNC_toggle_alt_button")
324 .addEventListener('click', UI
.toggleAlt
);
325 document
.getElementById("noVNC_send_tab_button")
326 .addEventListener('click', UI
.sendTab
);
327 document
.getElementById("noVNC_send_esc_button")
328 .addEventListener('click', UI
.sendEsc
);
329 document
.getElementById("noVNC_send_ctrl_alt_del_button")
330 .addEventListener('click', UI
.sendCtrlAltDel
);
333 addXvpHandlers: function() {
334 document
.getElementById("noVNC_xvp_shutdown_button")
335 .addEventListener('click', function() { UI
.rfb
.xvpShutdown(); });
336 document
.getElementById("noVNC_xvp_reboot_button")
337 .addEventListener('click', function() { UI
.rfb
.xvpReboot(); });
338 document
.getElementById("noVNC_xvp_reset_button")
339 .addEventListener('click', function() { UI
.rfb
.xvpReset(); });
340 document
.getElementById("noVNC_xvp_button")
341 .addEventListener('click', UI
.toggleXvpPanel
);
344 addConnectionControlHandlers: function() {
345 document
.getElementById("noVNC_disconnect_button")
346 .addEventListener('click', UI
.disconnect
);
347 document
.getElementById("noVNC_connect_button")
348 .addEventListener('click', UI
.connect
);
349 document
.getElementById("noVNC_cancel_reconnect_button")
350 .addEventListener('click', UI
.cancelReconnect
);
352 document
.getElementById("noVNC_password_button")
353 .addEventListener('click', UI
.setPassword
);
356 addClipboardHandlers: function() {
357 document
.getElementById("noVNC_clipboard_button")
358 .addEventListener('click', UI
.toggleClipboardPanel
);
359 document
.getElementById("noVNC_clipboard_text")
360 .addEventListener('focus', UI
.displayBlur
);
361 document
.getElementById("noVNC_clipboard_text")
362 .addEventListener('blur', UI
.displayFocus
);
363 document
.getElementById("noVNC_clipboard_text")
364 .addEventListener('change', UI
.clipboardSend
);
365 document
.getElementById("noVNC_clipboard_clear_button")
366 .addEventListener('click', UI
.clipboardClear
);
369 // Add a call to save settings when the element changes,
370 // unless the optional parameter changeFunc is used instead.
371 addSettingChangeHandler: function(name
, changeFunc
) {
372 var settingElem
= document
.getElementById("noVNC_setting_" + name
);
373 if (changeFunc
=== undefined) {
374 changeFunc = function () { UI
.saveSetting(name
); };
376 settingElem
.addEventListener('change', changeFunc
);
379 addSettingsHandlers: function() {
380 document
.getElementById("noVNC_settings_button")
381 .addEventListener('click', UI
.toggleSettingsPanel
);
383 UI
.addSettingChangeHandler('encrypt');
384 UI
.addSettingChangeHandler('cursor');
385 UI
.addSettingChangeHandler('cursor', UI
.updateLocalCursor
);
386 UI
.addSettingChangeHandler('resize');
387 UI
.addSettingChangeHandler('resize', UI
.enableDisableViewClip
);
388 UI
.addSettingChangeHandler('resize', UI
.applyResizeMode
);
389 UI
.addSettingChangeHandler('view_clip');
390 UI
.addSettingChangeHandler('view_clip', UI
.updateViewClip
);
391 UI
.addSettingChangeHandler('shared');
392 UI
.addSettingChangeHandler('view_only');
393 UI
.addSettingChangeHandler('view_only', UI
.updateViewOnly
);
394 UI
.addSettingChangeHandler('host');
395 UI
.addSettingChangeHandler('port');
396 UI
.addSettingChangeHandler('path');
397 UI
.addSettingChangeHandler('repeaterID');
398 UI
.addSettingChangeHandler('logging');
399 UI
.addSettingChangeHandler('logging', UI
.updateLogging
);
400 UI
.addSettingChangeHandler('reconnect');
401 UI
.addSettingChangeHandler('reconnect_delay');
404 addFullscreenHandlers: function() {
405 document
.getElementById("noVNC_fullscreen_button")
406 .addEventListener('click', UI
.toggleFullscreen
);
408 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
409 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
410 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
411 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
420 updateState: function(rfb
, state
, oldstate
) {
423 document
.documentElement
.classList
.remove("noVNC_connecting");
424 document
.documentElement
.classList
.remove("noVNC_connected");
425 document
.documentElement
.classList
.remove("noVNC_disconnecting");
426 document
.documentElement
.classList
.remove("noVNC_reconnecting");
430 document
.getElementById("noVNC_transition_text").textContent
= _("Connecting...");
431 document
.documentElement
.classList
.add("noVNC_connecting");
435 UI
.inhibit_reconnect
= false;
436 document
.documentElement
.classList
.add("noVNC_connected");
437 if (rfb
&& rfb
.get_encrypt()) {
438 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
440 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
444 case 'disconnecting':
445 UI
.connected
= false;
446 document
.getElementById("noVNC_transition_text").textContent
= _("Disconnecting...");
447 document
.documentElement
.classList
.add("noVNC_disconnecting");
450 UI
.showStatus(_("Disconnected"));
453 msg
= "Invalid UI state";
455 UI
.showStatus(msg
, 'error');
459 UI
.updateVisualState();
462 // Disable/enable controls depending on connection state
463 updateVisualState: function() {
464 //Log.Debug(">> updateVisualState");
466 UI
.enableDisableViewClip();
468 if (cursorURIsSupported() && !isTouchDevice
) {
469 UI
.enableSetting('cursor');
471 UI
.disableSetting('cursor');
475 UI
.disableSetting('encrypt');
476 UI
.disableSetting('shared');
477 UI
.disableSetting('host');
478 UI
.disableSetting('port');
479 UI
.disableSetting('path');
480 UI
.disableSetting('repeaterID');
482 UI
.setMouseButton(1);
484 // Hide the controlbar after 2 seconds
485 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
487 UI
.enableSetting('encrypt');
488 UI
.enableSetting('shared');
489 UI
.enableSetting('host');
490 UI
.enableSetting('port');
491 UI
.enableSetting('path');
492 UI
.enableSetting('repeaterID');
493 UI
.updateXvpButton(0);
497 // Hide input related buttons in view only mode
498 if (UI
.rfb
&& UI
.rfb
.get_view_only()) {
499 document
.getElementById('noVNC_keyboard_button')
500 .classList
.add('noVNC_hidden');
501 document
.getElementById('noVNC_toggle_extra_keys_button')
502 .classList
.add('noVNC_hidden');
504 document
.getElementById('noVNC_keyboard_button')
505 .classList
.remove('noVNC_hidden');
506 document
.getElementById('noVNC_toggle_extra_keys_button')
507 .classList
.remove('noVNC_hidden');
510 // State change disables viewport dragging.
511 // It is enabled (toggled) by direct click on the button
512 UI
.setViewDrag(false);
514 // State change also closes the password dialog
515 document
.getElementById('noVNC_password_dlg')
516 .classList
.remove('noVNC_open');
518 //Log.Debug("<< updateVisualState");
521 showStatus: function(text
, status_type
, time
) {
522 var statusElem
= document
.getElementById('noVNC_status');
524 clearTimeout(UI
.statusTimeout
);
526 if (typeof status_type
=== 'undefined') {
527 status_type
= 'normal';
530 statusElem
.classList
.remove("noVNC_status_normal");
531 statusElem
.classList
.remove("noVNC_status_warn");
532 statusElem
.classList
.remove("noVNC_status_error");
534 switch (status_type
) {
537 statusElem
.classList
.add("noVNC_status_warn");
540 statusElem
.classList
.add("noVNC_status_error");
545 statusElem
.classList
.add("noVNC_status_normal");
549 statusElem
.textContent
= text
;
550 statusElem
.classList
.add("noVNC_open");
552 // If no time was specified, show the status for 1.5 seconds
553 if (typeof time
=== 'undefined') {
557 // Error messages do not timeout
558 if (status_type
!== 'error') {
559 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
563 hideStatus: function() {
564 clearTimeout(UI
.statusTimeout
);
565 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
568 notification: function (rfb
, msg
, level
, options
) {
569 UI
.showStatus(msg
, level
);
572 activateControlbar: function(event
) {
573 clearTimeout(UI
.idleControlbarTimeout
);
574 // We manipulate the anchor instead of the actual control
575 // bar in order to avoid creating new a stacking group
576 document
.getElementById('noVNC_control_bar_anchor')
577 .classList
.remove("noVNC_idle");
578 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
581 idleControlbar: function() {
582 document
.getElementById('noVNC_control_bar_anchor')
583 .classList
.add("noVNC_idle");
586 keepControlbar: function() {
587 clearTimeout(UI
.closeControlbarTimeout
);
590 openControlbar: function() {
591 document
.getElementById('noVNC_control_bar')
592 .classList
.add("noVNC_open");
595 closeControlbar: function() {
597 document
.getElementById('noVNC_control_bar')
598 .classList
.remove("noVNC_open");
601 toggleControlbar: function() {
602 if (document
.getElementById('noVNC_control_bar')
603 .classList
.contains("noVNC_open")) {
604 UI
.closeControlbar();
610 toggleControlbarSide: function () {
611 // Temporarily disable animation to avoid weird movement
612 var bar
= document
.getElementById('noVNC_control_bar');
613 bar
.style
.transitionDuration
= '0s';
614 bar
.addEventListener('transitionend', function () { this.style
.transitionDuration
= ""; });
616 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
617 if (anchor
.classList
.contains("noVNC_right")) {
618 WebUtil
.writeSetting('controlbar_pos', 'left');
619 anchor
.classList
.remove("noVNC_right");
621 WebUtil
.writeSetting('controlbar_pos', 'right');
622 anchor
.classList
.add("noVNC_right");
625 // Consider this a movement of the handle
626 UI
.controlbarDrag
= true;
629 showControlbarHint: function (show
) {
630 var hint
= document
.getElementById('noVNC_control_bar_hint');
632 hint
.classList
.add("noVNC_active");
634 hint
.classList
.remove("noVNC_active");
638 dragControlbarHandle: function (e
) {
639 if (!UI
.controlbarGrabbed
) return;
641 var ptr
= getPointerEvent(e
);
643 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
644 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
645 if (anchor
.classList
.contains("noVNC_right")) {
646 UI
.toggleControlbarSide();
648 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
649 if (!anchor
.classList
.contains("noVNC_right")) {
650 UI
.toggleControlbarSide();
654 if (!UI
.controlbarDrag
) {
655 // The goal is to trigger on a certain physical width, the
656 // devicePixelRatio brings us a bit closer but is not optimal.
657 var dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
658 var dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
660 if (dragDistance
< dragThreshold
) return;
662 UI
.controlbarDrag
= true;
665 var eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
667 UI
.moveControlbarHandle(eventY
);
672 UI
.activateControlbar();
675 // Move the handle but don't allow any position outside the bounds
676 moveControlbarHandle: function (viewportRelativeY
) {
677 var handle
= document
.getElementById("noVNC_control_bar_handle");
678 var handleHeight
= handle
.getBoundingClientRect().height
;
679 var controlbarBounds
= document
.getElementById("noVNC_control_bar")
680 .getBoundingClientRect();
683 // These heights need to be non-zero for the below logic to work
684 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
688 var newY
= viewportRelativeY
;
690 // Check if the coordinates are outside the control bar
691 if (newY
< controlbarBounds
.top
+ margin
) {
692 // Force coordinates to be below the top of the control bar
693 newY
= controlbarBounds
.top
+ margin
;
695 } else if (newY
> controlbarBounds
.top
+
696 controlbarBounds
.height
- handleHeight
- margin
) {
697 // Force coordinates to be above the bottom of the control bar
698 newY
= controlbarBounds
.top
+
699 controlbarBounds
.height
- handleHeight
- margin
;
702 // Corner case: control bar too small for stable position
703 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
704 newY
= controlbarBounds
.top
+
705 (controlbarBounds
.height
- handleHeight
) / 2;
708 // The transform needs coordinates that are relative to the parent
709 var parentRelativeY
= newY
- controlbarBounds
.top
;
710 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
713 updateControlbarHandle: function () {
714 // Since the control bar is fixed on the viewport and not the page,
715 // the move function expects coordinates relative the the viewport.
716 var handle
= document
.getElementById("noVNC_control_bar_handle");
717 var handleBounds
= handle
.getBoundingClientRect();
718 UI
.moveControlbarHandle(handleBounds
.top
);
721 controlbarHandleMouseUp: function(e
) {
722 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
724 // mouseup and mousedown on the same place toggles the controlbar
725 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
726 UI
.toggleControlbar();
730 UI
.activateControlbar();
732 UI
.controlbarGrabbed
= false;
733 UI
.showControlbarHint(false);
736 controlbarHandleMouseDown: function(e
) {
737 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
739 var ptr
= getPointerEvent(e
);
741 var handle
= document
.getElementById("noVNC_control_bar_handle");
742 var bounds
= handle
.getBoundingClientRect();
744 // Touch events have implicit capture
745 if (e
.type
=== "mousedown") {
749 UI
.controlbarGrabbed
= true;
750 UI
.controlbarDrag
= false;
752 UI
.showControlbarHint(true);
754 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
755 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
759 UI
.activateControlbar();
762 toggleExpander: function(e
) {
763 if (this.classList
.contains("noVNC_open")) {
764 this.classList
.remove("noVNC_open");
766 this.classList
.add("noVNC_open");
776 // Initial page load read/initialization of settings
777 initSetting: function(name
, defVal
) {
778 // Check Query string followed by cookie
779 var val
= WebUtil
.getConfigVar(name
);
781 val
= WebUtil
.readSetting(name
, defVal
);
783 UI
.updateSetting(name
, val
);
787 // Update cookie and form control setting. If value is not set, then
788 // updates from control to current cookie setting.
789 updateSetting: function(name
, value
) {
791 // Save the cookie for this session
792 if (typeof value
!== 'undefined') {
793 WebUtil
.writeSetting(name
, value
);
796 // Update the settings control
797 value
= UI
.getSetting(name
);
799 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
800 if (ctrl
.type
=== 'checkbox') {
801 ctrl
.checked
= value
;
803 } else if (typeof ctrl
.options
!== 'undefined') {
804 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
805 if (ctrl
.options
[i
].value
=== value
) {
806 ctrl
.selectedIndex
= i
;
811 /*Weird IE9 error leads to 'null' appearring
812 in textboxes instead of ''.*/
813 if (value
=== null) {
820 // Save control setting to cookie
821 saveSetting: function(name
) {
822 var val
, ctrl
= document
.getElementById('noVNC_setting_' + name
);
823 if (ctrl
.type
=== 'checkbox') {
825 } else if (typeof ctrl
.options
!== 'undefined') {
826 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
830 WebUtil
.writeSetting(name
, val
);
831 //Log.Debug("Setting saved '" + name + "=" + val + "'");
835 // Read form control compatible setting from cookie
836 getSetting: function(name
) {
837 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
838 var val
= WebUtil
.readSetting(name
);
839 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
840 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
849 // These helpers compensate for the lack of parent-selectors and
850 // previous-sibling-selectors in CSS which are needed when we want to
851 // disable the labels that belong to disabled input elements.
852 disableSetting: function(name
) {
853 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
854 ctrl
.disabled
= true;
855 ctrl
.label
.classList
.add('noVNC_disabled');
858 enableSetting: function(name
) {
859 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
860 ctrl
.disabled
= false;
861 ctrl
.label
.classList
.remove('noVNC_disabled');
870 closeAllPanels: function() {
871 UI
.closeSettingsPanel();
873 UI
.closeClipboardPanel();
883 openSettingsPanel: function() {
887 // Refresh UI elements from saved cookies
888 UI
.updateSetting('encrypt');
889 if (cursorURIsSupported()) {
890 UI
.updateSetting('cursor');
892 UI
.updateSetting('cursor', !isTouchDevice
);
893 UI
.disableSetting('cursor');
895 UI
.updateSetting('view_clip');
896 UI
.updateSetting('resize');
897 UI
.updateSetting('shared');
898 UI
.updateSetting('view_only');
899 UI
.updateSetting('path');
900 UI
.updateSetting('repeaterID');
901 UI
.updateSetting('logging');
902 UI
.updateSetting('reconnect');
903 UI
.updateSetting('reconnect_delay');
905 document
.getElementById('noVNC_settings')
906 .classList
.add("noVNC_open");
907 document
.getElementById('noVNC_settings_button')
908 .classList
.add("noVNC_selected");
911 closeSettingsPanel: function() {
912 document
.getElementById('noVNC_settings')
913 .classList
.remove("noVNC_open");
914 document
.getElementById('noVNC_settings_button')
915 .classList
.remove("noVNC_selected");
918 toggleSettingsPanel: function() {
919 if (document
.getElementById('noVNC_settings')
920 .classList
.contains("noVNC_open")) {
921 UI
.closeSettingsPanel();
923 UI
.openSettingsPanel();
933 openXvpPanel: function() {
937 document
.getElementById('noVNC_xvp')
938 .classList
.add("noVNC_open");
939 document
.getElementById('noVNC_xvp_button')
940 .classList
.add("noVNC_selected");
943 closeXvpPanel: function() {
944 document
.getElementById('noVNC_xvp')
945 .classList
.remove("noVNC_open");
946 document
.getElementById('noVNC_xvp_button')
947 .classList
.remove("noVNC_selected");
950 toggleXvpPanel: function() {
951 if (document
.getElementById('noVNC_xvp')
952 .classList
.contains("noVNC_open")) {
959 // Disable/enable XVP button
960 updateXvpButton: function(ver
) {
961 if (ver
>= 1 && !UI
.rfb
.get_view_only()) {
962 document
.getElementById('noVNC_xvp_button')
963 .classList
.remove("noVNC_hidden");
965 document
.getElementById('noVNC_xvp_button')
966 .classList
.add("noVNC_hidden");
967 // Close XVP panel if open
978 openClipboardPanel: function() {
982 document
.getElementById('noVNC_clipboard')
983 .classList
.add("noVNC_open");
984 document
.getElementById('noVNC_clipboard_button')
985 .classList
.add("noVNC_selected");
988 closeClipboardPanel: function() {
989 document
.getElementById('noVNC_clipboard')
990 .classList
.remove("noVNC_open");
991 document
.getElementById('noVNC_clipboard_button')
992 .classList
.remove("noVNC_selected");
995 toggleClipboardPanel: function() {
996 if (document
.getElementById('noVNC_clipboard')
997 .classList
.contains("noVNC_open")) {
998 UI
.closeClipboardPanel();
1000 UI
.openClipboardPanel();
1004 clipboardReceive: function(rfb
, text
) {
1005 Log
.Debug(">> UI.clipboardReceive: " + text
.substr(0,40) + "...");
1006 document
.getElementById('noVNC_clipboard_text').value
= text
;
1007 Log
.Debug("<< UI.clipboardReceive");
1010 clipboardClear: function() {
1011 document
.getElementById('noVNC_clipboard_text').value
= "";
1012 UI
.rfb
.clipboardPasteFrom("");
1015 clipboardSend: function() {
1016 var text
= document
.getElementById('noVNC_clipboard_text').value
;
1017 Log
.Debug(">> UI.clipboardSend: " + text
.substr(0,40) + "...");
1018 UI
.rfb
.clipboardPasteFrom(text
);
1019 Log
.Debug("<< UI.clipboardSend");
1028 openConnectPanel: function() {
1029 document
.getElementById('noVNC_connect_dlg')
1030 .classList
.add("noVNC_open");
1033 closeConnectPanel: function() {
1034 document
.getElementById('noVNC_connect_dlg')
1035 .classList
.remove("noVNC_open");
1038 connect: function(event
, password
) {
1039 var host
= UI
.getSetting('host');
1040 var port
= UI
.getSetting('port');
1041 var path
= UI
.getSetting('path');
1043 if (typeof password
=== 'undefined') {
1044 password
= WebUtil
.getConfigVar('password');
1047 if (password
=== null) {
1048 password
= undefined;
1051 if ((!host
) || (!port
)) {
1052 var msg
= _("Must set host and port");
1054 UI
.showStatus(msg
, 'error');
1058 if (!UI
.initRFB()) return;
1060 UI
.closeAllPanels();
1061 UI
.closeConnectPanel();
1063 UI
.rfb
.set_encrypt(UI
.getSetting('encrypt'));
1064 UI
.rfb
.set_shared(UI
.getSetting('shared'));
1065 UI
.rfb
.set_repeaterID(UI
.getSetting('repeaterID'));
1067 UI
.updateLocalCursor();
1068 UI
.updateViewOnly();
1070 UI
.rfb
.connect(host
, port
, password
, path
);
1073 disconnect: function() {
1074 UI
.closeAllPanels();
1075 UI
.rfb
.disconnect();
1077 // Disable automatic reconnecting
1078 UI
.inhibit_reconnect
= true;
1080 // Restore the callback used for initial resize
1081 UI
.rfb
.set_onFBUComplete(UI
.initialResize
);
1083 // Don't display the connection settings until we're actually disconnected
1086 reconnect: function() {
1087 UI
.reconnect_callback
= null;
1089 // if reconnect has been disabled in the meantime, do nothing.
1090 if (UI
.inhibit_reconnect
) {
1094 UI
.connect(null, UI
.reconnect_password
);
1097 disconnectFinished: function (rfb
, reason
) {
1098 if (typeof reason
!== 'undefined') {
1099 UI
.showStatus(reason
, 'error');
1100 } else if (UI
.getSetting('reconnect', false) === true && !UI
.inhibit_reconnect
) {
1101 document
.getElementById("noVNC_transition_text").textContent
= _("Reconnecting...");
1102 document
.documentElement
.classList
.add("noVNC_reconnecting");
1104 var delay
= parseInt(UI
.getSetting('reconnect_delay'));
1105 UI
.reconnect_callback
= setTimeout(UI
.reconnect
, delay
);
1109 UI
.openControlbar();
1110 UI
.openConnectPanel();
1113 cancelReconnect: function() {
1114 if (UI
.reconnect_callback
!== null) {
1115 clearTimeout(UI
.reconnect_callback
);
1116 UI
.reconnect_callback
= null;
1119 document
.documentElement
.classList
.remove("noVNC_reconnecting");
1120 UI
.openControlbar();
1121 UI
.openConnectPanel();
1130 passwordRequired: function(rfb
, msg
) {
1132 document
.getElementById('noVNC_password_dlg')
1133 .classList
.add('noVNC_open');
1135 setTimeout(function () {
1136 document
.getElementById('noVNC_password_input').focus();
1139 if (typeof msg
=== 'undefined') {
1140 msg
= _("Password is required");
1143 UI
.showStatus(msg
, "warning");
1146 setPassword: function(e
) {
1147 var inputElem
= document
.getElementById('noVNC_password_input');
1148 var password
= inputElem
.value
;
1149 // Clear the input after reading the password
1150 inputElem
.value
= "";
1151 UI
.rfb
.sendPassword(password
);
1152 UI
.reconnect_password
= password
;
1153 document
.getElementById('noVNC_password_dlg')
1154 .classList
.remove('noVNC_open');
1155 // Prevent actually submitting the form
1165 toggleFullscreen: function() {
1166 if (document
.fullscreenElement
|| // alternative standard method
1167 document
.mozFullScreenElement
|| // currently working methods
1168 document
.webkitFullscreenElement
||
1169 document
.msFullscreenElement
) {
1170 if (document
.exitFullscreen
) {
1171 document
.exitFullscreen();
1172 } else if (document
.mozCancelFullScreen
) {
1173 document
.mozCancelFullScreen();
1174 } else if (document
.webkitExitFullscreen
) {
1175 document
.webkitExitFullscreen();
1176 } else if (document
.msExitFullscreen
) {
1177 document
.msExitFullscreen();
1180 if (document
.documentElement
.requestFullscreen
) {
1181 document
.documentElement
.requestFullscreen();
1182 } else if (document
.documentElement
.mozRequestFullScreen
) {
1183 document
.documentElement
.mozRequestFullScreen();
1184 } else if (document
.documentElement
.webkitRequestFullscreen
) {
1185 document
.documentElement
.webkitRequestFullscreen(Element
.ALLOW_KEYBOARD_INPUT
);
1186 } else if (document
.body
.msRequestFullscreen
) {
1187 document
.body
.msRequestFullscreen();
1190 UI
.enableDisableViewClip();
1191 UI
.updateFullscreenButton();
1194 updateFullscreenButton: function() {
1195 if (document
.fullscreenElement
|| // alternative standard method
1196 document
.mozFullScreenElement
|| // currently working methods
1197 document
.webkitFullscreenElement
||
1198 document
.msFullscreenElement
) {
1199 document
.getElementById('noVNC_fullscreen_button')
1200 .classList
.add("noVNC_selected");
1202 document
.getElementById('noVNC_fullscreen_button')
1203 .classList
.remove("noVNC_selected");
1213 // Apply remote resizing or local scaling
1214 applyResizeMode: function() {
1215 if (!UI
.rfb
) return;
1217 var screen
= UI
.screenSize();
1219 if (screen
&& UI
.connected
&& UI
.rfb
.get_display()) {
1221 var display
= UI
.rfb
.get_display();
1222 var resizeMode
= UI
.getSetting('resize');
1223 display
.set_scale(1);
1225 // Make sure the viewport is adjusted first
1226 UI
.updateViewClip();
1228 if (resizeMode
=== 'remote') {
1230 // Request changing the resolution of the remote display to
1231 // the size of the local browser viewport.
1233 // In order to not send multiple requests before the browser-resize
1234 // is finished we wait 0.5 seconds before sending the request.
1235 clearTimeout(UI
.resizeTimeout
);
1236 UI
.resizeTimeout
= setTimeout(function(){
1237 // Request a remote size covering the viewport
1238 if (UI
.rfb
.requestDesktopSize(screen
.w
, screen
.h
)) {
1239 Log
.Debug('Requested new desktop size: ' +
1240 screen
.w
+ 'x' + screen
.h
);
1250 // Re-calculate local scaling
1251 updateScaling: function() {
1252 if (!UI
.rfb
) return;
1254 var resizeMode
= UI
.getSetting('resize');
1255 if (resizeMode
!== 'scale' && resizeMode
!== 'downscale') {
1259 var screen
= UI
.screenSize();
1261 if (!screen
|| !UI
.connected
|| !UI
.rfb
.get_display()) {
1265 var display
= UI
.rfb
.get_display();
1266 var downscaleOnly
= resizeMode
=== 'downscale';
1267 display
.autoscale(screen
.w
, screen
.h
, downscaleOnly
);
1271 // Gets the the size of the available viewport in the browser window
1272 screenSize: function() {
1273 var screen
= document
.getElementById('noVNC_screen');
1274 return {w
: screen
.offsetWidth
, h
: screen
.offsetHeight
};
1277 // Normally we only apply the current resize mode after a window resize
1278 // event. This means that when a new connection is opened, there is no
1279 // resize mode active.
1280 // We have to wait until the first FBU because this is where the client
1281 // will find the supported encodings of the server. Some calls later in
1282 // the chain is dependant on knowing the server-capabilities.
1283 initialResize: function(rfb
, fbu
) {
1284 UI
.applyResizeMode();
1285 // After doing this once, we remove the callback.
1286 UI
.rfb
.set_onFBUComplete(function() { });
1295 // Set and configure viewport clipping
1296 setViewClip: function(clip
) {
1297 UI
.updateSetting('view_clip', clip
);
1298 UI
.updateViewClip();
1301 // Update parameters that depend on the viewport clip setting
1302 updateViewClip: function() {
1303 if (!UI
.rfb
) return;
1305 var display
= UI
.rfb
.get_display();
1306 var cur_clip
= display
.get_viewport();
1307 var new_clip
= UI
.getSetting('view_clip');
1309 var resizeSetting
= UI
.getSetting('resize');
1310 if (resizeSetting
=== 'downscale' || resizeSetting
=== 'scale') {
1311 // Disable viewport clipping if we are scaling
1313 } else if (isTouchDevice
) {
1314 // Touch devices usually have shit scrollbars
1318 if (cur_clip
!== new_clip
) {
1319 display
.set_viewport(new_clip
);
1322 var size
= UI
.screenSize();
1324 if (new_clip
&& size
) {
1325 // When clipping is enabled, the screen is limited to
1326 // the size of the browser window.
1327 display
.viewportChangeSize(size
.w
, size
.h
);
1331 // Changing the viewport may change the state of
1332 // the dragging button
1333 UI
.updateViewDrag();
1336 // Handle special cases where viewport clipping is forced on/off or locked
1337 enableDisableViewClip: function() {
1338 var resizeSetting
= UI
.getSetting('resize');
1339 // Disable clipping if we are scaling, connected or on touch
1340 if (resizeSetting
=== 'downscale' || resizeSetting
=== 'scale' ||
1342 UI
.disableSetting('view_clip');
1344 UI
.enableSetting('view_clip');
1354 toggleViewDrag: function() {
1355 if (!UI
.rfb
) return;
1357 var drag
= UI
.rfb
.get_viewportDrag();
1358 UI
.setViewDrag(!drag
);
1361 // Set the view drag mode which moves the viewport on mouse drags
1362 setViewDrag: function(drag
) {
1363 if (!UI
.rfb
) return;
1365 UI
.rfb
.set_viewportDrag(drag
);
1367 UI
.updateViewDrag();
1370 updateViewDrag: function() {
1371 var clipping
= false;
1373 if (!UI
.connected
) return;
1375 // Check if viewport drag is possible. It is only possible
1376 // if the remote display is clipping the client display.
1377 if (UI
.rfb
.get_display().get_viewport() &&
1378 UI
.rfb
.get_display().clippingDisplay()) {
1382 var viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1385 UI
.rfb
.get_viewportDrag()) {
1386 // The size of the remote display is the same or smaller
1387 // than the client display. Make sure viewport drag isn't
1388 // active when it can't be used.
1389 UI
.rfb
.set_viewportDrag(false);
1392 if (UI
.rfb
.get_viewportDrag()) {
1393 viewDragButton
.classList
.add("noVNC_selected");
1395 viewDragButton
.classList
.remove("noVNC_selected");
1398 // Different behaviour for touch vs non-touch
1399 // The button is disabled instead of hidden on touch devices
1400 if (isTouchDevice
) {
1401 viewDragButton
.classList
.remove("noVNC_hidden");
1404 viewDragButton
.disabled
= false;
1406 viewDragButton
.disabled
= true;
1409 viewDragButton
.disabled
= false;
1412 viewDragButton
.classList
.remove("noVNC_hidden");
1414 viewDragButton
.classList
.add("noVNC_hidden");
1425 showVirtualKeyboard: function() {
1426 if (!isTouchDevice
) return;
1428 var input
= document
.getElementById('noVNC_keyboardinput');
1430 if (document
.activeElement
== input
) return;
1435 var l
= input
.value
.length
;
1436 // Move the caret to the end
1437 input
.setSelectionRange(l
, l
);
1438 } catch (err
) {} // setSelectionRange is undefined in Google Chrome
1441 hideVirtualKeyboard: function() {
1442 if (!isTouchDevice
) return;
1444 var input
= document
.getElementById('noVNC_keyboardinput');
1446 if (document
.activeElement
!= input
) return;
1451 toggleVirtualKeyboard: function () {
1452 if (document
.getElementById('noVNC_keyboard_button')
1453 .classList
.contains("noVNC_selected")) {
1454 UI
.hideVirtualKeyboard();
1456 UI
.showVirtualKeyboard();
1460 onfocusVirtualKeyboard: function(event
) {
1461 document
.getElementById('noVNC_keyboard_button')
1462 .classList
.add("noVNC_selected");
1465 onblurVirtualKeyboard: function(event
) {
1466 document
.getElementById('noVNC_keyboard_button')
1467 .classList
.remove("noVNC_selected");
1470 keepVirtualKeyboard: function(event
) {
1471 var input
= document
.getElementById('noVNC_keyboardinput');
1473 // Only prevent focus change if the virtual keyboard is active
1474 if (document
.activeElement
!= input
) {
1478 // Only allow focus to move to other elements that need
1479 // focus to function properly
1480 if (event
.target
.form
!== undefined) {
1481 switch (event
.target
.type
) {
1490 case 'select-multiple':
1495 event
.preventDefault();
1498 keyboardinputReset: function() {
1499 var kbi
= document
.getElementById('noVNC_keyboardinput');
1500 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1501 UI
.lastKeyboardinput
= kbi
.value
;
1504 // When normal keyboard events are left uncought, use the input events from
1505 // the keyboardinput element instead and generate the corresponding key events.
1506 // This code is required since some browsers on Android are inconsistent in
1507 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1508 keyInput: function(event
) {
1510 if (!UI
.rfb
) return;
1512 var newValue
= event
.target
.value
;
1514 if (!UI
.lastKeyboardinput
) {
1515 UI
.keyboardinputReset();
1517 var oldValue
= UI
.lastKeyboardinput
;
1521 // Try to check caret position since whitespace at the end
1522 // will not be considered by value.length in some browsers
1523 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1525 // selectionStart is undefined in Google Chrome
1526 newLen
= newValue
.length
;
1528 var oldLen
= oldValue
.length
;
1531 var inputs
= newLen
- oldLen
;
1533 backspaces
= -inputs
;
1538 // Compare the old string with the new to account for
1539 // text-corrections or other input that modify existing text
1541 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1542 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1543 inputs
= newLen
- i
;
1544 backspaces
= oldLen
- i
;
1549 // Send the key events
1550 for (i
= 0; i
< backspaces
; i
++) {
1551 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
, "Backspace");
1553 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1554 UI
.rfb
.sendKey(keysyms
.lookup(newValue
.charCodeAt(i
)));
1557 // Control the text content length in the keyboardinput element
1558 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1559 UI
.keyboardinputReset();
1560 } else if (newLen
< 1) {
1561 // There always have to be some text in the keyboardinput
1562 // element with which backspace can interact.
1563 UI
.keyboardinputReset();
1564 // This sometimes causes the keyboard to disappear for a second
1565 // but it is required for the android keyboard to recognize that
1566 // text has been added to the field
1567 event
.target
.blur();
1568 // This has to be ran outside of the input handler in order to work
1569 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1571 UI
.lastKeyboardinput
= newValue
;
1581 openExtraKeys: function() {
1582 UI
.closeAllPanels();
1583 UI
.openControlbar();
1585 document
.getElementById('noVNC_modifiers')
1586 .classList
.add("noVNC_open");
1587 document
.getElementById('noVNC_toggle_extra_keys_button')
1588 .classList
.add("noVNC_selected");
1591 closeExtraKeys: function() {
1592 document
.getElementById('noVNC_modifiers')
1593 .classList
.remove("noVNC_open");
1594 document
.getElementById('noVNC_toggle_extra_keys_button')
1595 .classList
.remove("noVNC_selected");
1598 toggleExtraKeys: function() {
1599 if(document
.getElementById('noVNC_modifiers')
1600 .classList
.contains("noVNC_open")) {
1601 UI
.closeExtraKeys();
1607 sendEsc: function() {
1608 UI
.rfb
.sendKey(KeyTable
.XK_Escape
, "Escape");
1611 sendTab: function() {
1612 UI
.rfb
.sendKey(KeyTable
.XK_Tab
);
1615 toggleCtrl: function() {
1616 var btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1617 if (btn
.classList
.contains("noVNC_selected")) {
1618 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", false);
1619 btn
.classList
.remove("noVNC_selected");
1621 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, "ControlLeft", true);
1622 btn
.classList
.add("noVNC_selected");
1626 toggleAlt: function() {
1627 var btn
= document
.getElementById('noVNC_toggle_alt_button');
1628 if (btn
.classList
.contains("noVNC_selected")) {
1629 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", false);
1630 btn
.classList
.remove("noVNC_selected");
1632 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, "AltLeft", true);
1633 btn
.classList
.add("noVNC_selected");
1637 sendCtrlAltDel: function() {
1638 UI
.rfb
.sendCtrlAltDel();
1647 setMouseButton: function(num
) {
1648 var view_only
= UI
.rfb
.get_view_only();
1649 if (UI
.rfb
&& !view_only
) {
1650 UI
.rfb
.get_mouse().set_touchButton(num
);
1653 var blist
= [0, 1,2,4];
1654 for (var b
= 0; b
< blist
.length
; b
++) {
1655 var button
= document
.getElementById('noVNC_mouse_button' +
1657 if (blist
[b
] === num
&& !view_only
) {
1658 button
.classList
.remove("noVNC_hidden");
1660 button
.classList
.add("noVNC_hidden");
1665 displayBlur: function() {
1666 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1667 UI
.rfb
.get_keyboard().set_focused(false);
1668 UI
.rfb
.get_mouse().set_focused(false);
1672 displayFocus: function() {
1673 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1674 UI
.rfb
.get_keyboard().set_focused(true);
1675 UI
.rfb
.get_mouse().set_focused(true);
1679 updateLocalCursor: function() {
1680 if (!UI
.rfb
) return;
1681 UI
.rfb
.set_local_cursor(UI
.getSetting('cursor'));
1684 updateViewOnly: function() {
1685 if (!UI
.rfb
) return;
1686 UI
.rfb
.set_view_only(UI
.getSetting('view_only'));
1689 updateLogging: function() {
1690 WebUtil
.init_logging(UI
.getSetting('logging'));
1693 updateSessionSize: function(rfb
, width
, height
) {
1694 UI
.updateViewClip();
1699 fixScrollbars: function() {
1700 // This is a hack because Chrome screws up the calculation
1701 // for when scrollbars are needed. So to fix it we temporarily
1702 // toggle them off and on.
1703 var screen
= document
.getElementById('noVNC_screen');
1704 screen
.style
.overflow
= 'hidden';
1705 // Force Chrome to recalculate the layout by asking for
1706 // an element's dimensions
1707 screen
.getBoundingClientRect();
1708 screen
.style
.overflow
= "";
1711 updateDesktopName: function(rfb
, name
) {
1712 UI
.desktopName
= name
;
1713 // Display the desktop name in the document title
1714 document
.title
= name
+ " - noVNC";
1717 bell: function(rfb
) {
1718 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1719 document
.getElementById('noVNC_bell').play()
1720 .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
);
1732 //Helper to add options to dropdown.
1733 addOption: function(selectbox
, text
, value
) {
1734 var optn
= document
.createElement("OPTION");
1737 selectbox
.options
.add(optn
);
1746 // Set up translations
1747 var LINGUAS
= ["de", "el", "nl", "sv"];
1748 l10n
.setup(LINGUAS
);
1749 if (l10n
.language
!== "en" && l10n
.dictionary
=== undefined) {
1750 WebUtil
.fetchJSON('app/locale/' + l10n
.language
+ '.json', function (translations
) {
1751 l10n
.dictionary
= translations
;
1753 // wait for translations to load before loading the UI