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 */
15 * import Util from "../core/util";
16 * import KeyTable from "../core/input/keysym";
17 * import keysyms from "./keysymdef";
18 * import RFB from "../core/rfb";
19 * import Display from "../core/display";
20 * import WebUtil from "./webutil";
28 // Fallback for all uncought errors
29 window
.addEventListener('error', function(event
) {
33 msg
= document
.getElementById('noVNC_fallback_errormsg');
35 // Only show the initial error
36 if (msg
.hasChildNodes()) {
40 div
= document
.createElement("div");
41 div
.appendChild(document
.createTextNode(event
.message
));
44 div
= document
.createElement("div");
45 div
.className
= 'noVNC_location';
46 text
= event
.filename
+ ":" + event
.lineno
+ ":" + event
.colno
;
47 div
.appendChild(document
.createTextNode(text
));
50 if ((event
.error
!== undefined) &&
51 (event
.error
.stack
!== undefined)) {
52 div
= document
.createElement("div");
53 div
.className
= 'noVNC_stack';
54 div
.appendChild(document
.createTextNode(event
.error
.stack
));
58 document
.getElementById('noVNC_fallback_error')
59 .classList
.add("noVNC_open");
61 document
.write("noVNC encountered an error.");
63 // Don't return true since this would prevent the error
64 // from being printed to the browser console.
68 // Set up translations
69 var LINGUAS
= ["de", "el", "nl", "sv"];
70 Util
.Localisation
.setup(LINGUAS
);
71 if (Util
.Localisation
.language
!== "en") {
73 {'app': ["locale/" + Util
.Localisation
.language
+ ".js"]});
76 /* [begin skip-as-module] */
77 // Load supporting scripts
79 {'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js",
80 "input/xtscancodes.js", "input/util.js", "input/devices.js",
81 "display.js", "inflator.js", "rfb.js", "input/keysym.js"]});
83 window
.onscriptsload = function () { UI
.load(); };
84 /* [end skip-as-module] */
86 var _
= Util
.Localisation
.get;
95 hideKeyboardTimeout
: null,
96 idleControlbarTimeout
: null,
97 closeControlbarTimeout
: null,
99 controlbarGrabbed
: false,
100 controlbarDrag
: false,
101 controlbarMouseDownClientY
: 0,
102 controlbarMouseDownOffsetY
: 0,
105 rememberedClipSetting
: null,
106 lastKeyboardinput
: null,
107 defaultKeyboardinputLen
: 100,
109 inhibit_reconnect
: true,
110 reconnect_callback
: null,
111 reconnect_password
: null,
113 // Setup rfb object, load settings from browser storage, then call
114 // UI.init to setup the UI/menus
115 load: function(callback
) {
116 WebUtil
.initSettings(UI
.start
, callback
);
119 // Render default UI and initialize settings menu
120 start: function(callback
) {
122 // Setup global variables first
123 UI
.isSafari
= (navigator
.userAgent
.indexOf('Safari') !== -1 &&
124 navigator
.userAgent
.indexOf('Chrome') === -1);
129 Util
.Localisation
.translateDOM();
131 // Adapt the interface for touch screen devices
132 if (Util
.isTouchDevice
) {
133 document
.documentElement
.classList
.add("noVNC_touch");
134 // Remove the address bar
135 setTimeout(function() { window
.scrollTo(0, 1); }, 100);
138 // Restore control bar position
139 if (WebUtil
.readSetting('controlbar_pos') === 'right') {
140 UI
.toggleControlbarSide();
145 // Setup event handlers
146 UI
.addResizeHandlers();
147 UI
.addControlbarHandlers();
148 UI
.addTouchSpecificHandlers();
149 UI
.addExtraKeysHandlers();
151 UI
.addConnectionControlHandlers();
152 UI
.addClipboardHandlers();
153 UI
.addSettingsHandlers();
154 document
.getElementById("noVNC_status")
155 .addEventListener('click', UI
.hideStatus
);
159 // Show the connect panel on first load unless autoconnecting
161 UI
.openConnectPanel();
166 UI
.updateVisualState();
168 document
.getElementById('noVNC_setting_host').focus();
170 var autoconnect
= WebUtil
.getConfigVar('autoconnect', false);
171 if (autoconnect
=== 'true' || autoconnect
== '1') {
178 if (typeof callback
=== "function") {
183 initFullscreen: function() {
184 // Only show the button if fullscreen is properly supported
185 // * Safari doesn't support alphanumerical input while in fullscreen
187 (document
.documentElement
.requestFullscreen
||
188 document
.documentElement
.mozRequestFullScreen
||
189 document
.documentElement
.webkitRequestFullscreen
||
190 document
.body
.msRequestFullscreen
)) {
191 document
.getElementById('noVNC_fullscreen_button')
192 .classList
.remove("noVNC_hidden");
193 UI
.addFullscreenHandlers();
197 initSettings: function() {
200 // Logging selection dropdown
201 var llevels
= ['error', 'warn', 'info', 'debug'];
202 for (i
= 0; i
< llevels
.length
; i
+= 1) {
203 UI
.addOption(document
.getElementById('noVNC_setting_logging'),llevels
[i
], llevels
[i
]);
206 // Settings with immediate effects
207 UI
.initSetting('logging', 'warn');
210 // if port == 80 (or 443) then it won't be present and should be
212 var port
= window
.location
.port
;
214 if (window
.location
.protocol
.substring(0,5) == 'https') {
217 else if (window
.location
.protocol
.substring(0,4) == 'http') {
222 /* Populate the controls if defaults are provided in the URL */
223 UI
.initSetting('host', window
.location
.hostname
);
224 UI
.initSetting('port', port
);
225 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
226 UI
.initSetting('true_color', true);
227 UI
.initSetting('cursor', !Util
.isTouchDevice
);
228 UI
.initSetting('clip', false);
229 UI
.initSetting('resize', 'off');
230 UI
.initSetting('shared', true);
231 UI
.initSetting('view_only', false);
232 UI
.initSetting('path', 'websockify');
233 UI
.initSetting('repeaterID', '');
234 UI
.initSetting('reconnect', false);
235 UI
.initSetting('reconnect_delay', 5000);
238 initRFB: function() {
240 UI
.rfb
= new RFB({'target': document
.getElementById('noVNC_canvas'),
241 'onNotification': UI
.notification
,
242 'onUpdateState': UI
.updateState
,
243 'onDisconnected': UI
.disconnectFinished
,
244 'onPasswordRequired': UI
.passwordRequired
,
245 'onXvpInit': UI
.updateXvpButton
,
246 'onClipboard': UI
.clipboardReceive
,
248 'onFBUComplete': UI
.initialResize
,
249 'onFBResize': UI
.updateSessionSize
,
250 'onDesktopName': UI
.updateDesktopName
});
253 var msg
= "Unable to create RFB client -- " + exc
;
255 UI
.showStatus(msg
, 'error');
266 addResizeHandlers: function() {
267 window
.addEventListener('resize', UI
.applyResizeMode
);
268 window
.addEventListener('resize', UI
.updateViewClip
);
269 window
.addEventListener('resize', UI
.updateViewDrag
);
272 addControlbarHandlers: function() {
273 document
.getElementById("noVNC_control_bar")
274 .addEventListener('mousemove', UI
.activateControlbar
);
275 document
.getElementById("noVNC_control_bar")
276 .addEventListener('mouseup', UI
.activateControlbar
);
277 document
.getElementById("noVNC_control_bar")
278 .addEventListener('mousedown', UI
.activateControlbar
);
279 document
.getElementById("noVNC_control_bar")
280 .addEventListener('keypress', UI
.activateControlbar
);
282 document
.getElementById("noVNC_control_bar")
283 .addEventListener('mousedown', UI
.keepControlbar
);
284 document
.getElementById("noVNC_control_bar")
285 .addEventListener('keypress', UI
.keepControlbar
);
287 document
.getElementById("noVNC_view_drag_button")
288 .addEventListener('click', UI
.toggleViewDrag
);
290 document
.getElementById("noVNC_control_bar_handle")
291 .addEventListener('mousedown', UI
.controlbarHandleMouseDown
);
292 document
.getElementById("noVNC_control_bar_handle")
293 .addEventListener('mouseup', UI
.controlbarHandleMouseUp
);
294 document
.getElementById("noVNC_control_bar_handle")
295 .addEventListener('mousemove', UI
.dragControlbarHandle
);
296 // resize events aren't available for elements
297 window
.addEventListener('resize', UI
.updateControlbarHandle
);
299 var exps
= document
.getElementsByClassName("noVNC_expander");
300 for (var i
= 0;i
< exps
.length
;i
++) {
301 exps
[i
].addEventListener('click', UI
.toggleExpander
);
305 addTouchSpecificHandlers: function() {
306 document
.getElementById("noVNC_mouse_button0")
307 .addEventListener('click', function () { UI
.setMouseButton(1); });
308 document
.getElementById("noVNC_mouse_button1")
309 .addEventListener('click', function () { UI
.setMouseButton(2); });
310 document
.getElementById("noVNC_mouse_button2")
311 .addEventListener('click', function () { UI
.setMouseButton(4); });
312 document
.getElementById("noVNC_mouse_button4")
313 .addEventListener('click', function () { UI
.setMouseButton(0); });
314 document
.getElementById("noVNC_keyboard_button")
315 .addEventListener('click', UI
.toggleVirtualKeyboard
);
317 document
.getElementById("noVNC_keyboardinput")
318 .addEventListener('input', UI
.keyInput
);
319 document
.getElementById("noVNC_keyboardinput")
320 .addEventListener('focus', UI
.onfocusVirtualKeyboard
);
321 document
.getElementById("noVNC_keyboardinput")
322 .addEventListener('blur', UI
.onblurVirtualKeyboard
);
323 document
.getElementById("noVNC_keyboardinput")
324 .addEventListener('submit', function () { return false; });
326 document
.documentElement
327 .addEventListener('mousedown', UI
.keepVirtualKeyboard
, true);
329 document
.getElementById("noVNC_control_bar")
330 .addEventListener('touchstart', UI
.activateControlbar
);
331 document
.getElementById("noVNC_control_bar")
332 .addEventListener('touchmove', UI
.activateControlbar
);
333 document
.getElementById("noVNC_control_bar")
334 .addEventListener('touchend', UI
.activateControlbar
);
335 document
.getElementById("noVNC_control_bar")
336 .addEventListener('input', UI
.activateControlbar
);
338 document
.getElementById("noVNC_control_bar")
339 .addEventListener('touchstart', UI
.keepControlbar
);
340 document
.getElementById("noVNC_control_bar")
341 .addEventListener('input', UI
.keepControlbar
);
343 document
.getElementById("noVNC_control_bar_handle")
344 .addEventListener('touchstart', UI
.controlbarHandleMouseDown
);
345 document
.getElementById("noVNC_control_bar_handle")
346 .addEventListener('touchend', UI
.controlbarHandleMouseUp
);
347 document
.getElementById("noVNC_control_bar_handle")
348 .addEventListener('touchmove', UI
.dragControlbarHandle
);
350 window
.addEventListener('load', UI
.keyboardinputReset
);
353 addExtraKeysHandlers: function() {
354 document
.getElementById("noVNC_toggle_extra_keys_button")
355 .addEventListener('click', UI
.toggleExtraKeys
);
356 document
.getElementById("noVNC_toggle_ctrl_button")
357 .addEventListener('click', UI
.toggleCtrl
);
358 document
.getElementById("noVNC_toggle_alt_button")
359 .addEventListener('click', UI
.toggleAlt
);
360 document
.getElementById("noVNC_send_tab_button")
361 .addEventListener('click', UI
.sendTab
);
362 document
.getElementById("noVNC_send_esc_button")
363 .addEventListener('click', UI
.sendEsc
);
364 document
.getElementById("noVNC_send_ctrl_alt_del_button")
365 .addEventListener('click', UI
.sendCtrlAltDel
);
368 addXvpHandlers: function() {
369 document
.getElementById("noVNC_xvp_shutdown_button")
370 .addEventListener('click', function() { UI
.rfb
.xvpShutdown(); });
371 document
.getElementById("noVNC_xvp_reboot_button")
372 .addEventListener('click', function() { UI
.rfb
.xvpReboot(); });
373 document
.getElementById("noVNC_xvp_reset_button")
374 .addEventListener('click', function() { UI
.rfb
.xvpReset(); });
375 document
.getElementById("noVNC_xvp_button")
376 .addEventListener('click', UI
.toggleXvpPanel
);
379 addConnectionControlHandlers: function() {
380 document
.getElementById("noVNC_disconnect_button")
381 .addEventListener('click', UI
.disconnect
);
382 document
.getElementById("noVNC_connect_button")
383 .addEventListener('click', UI
.connect
);
384 document
.getElementById("noVNC_cancel_reconnect_button")
385 .addEventListener('click', UI
.cancelReconnect
);
387 document
.getElementById("noVNC_password_button")
388 .addEventListener('click', UI
.setPassword
);
391 addClipboardHandlers: function() {
392 document
.getElementById("noVNC_clipboard_button")
393 .addEventListener('click', UI
.toggleClipboardPanel
);
394 document
.getElementById("noVNC_clipboard_text")
395 .addEventListener('focus', UI
.displayBlur
);
396 document
.getElementById("noVNC_clipboard_text")
397 .addEventListener('blur', UI
.displayFocus
);
398 document
.getElementById("noVNC_clipboard_text")
399 .addEventListener('change', UI
.clipboardSend
);
400 document
.getElementById("noVNC_clipboard_clear_button")
401 .addEventListener('click', UI
.clipboardClear
);
404 // Add a call to save settings when the element changes,
405 // unless the optional parameter changeFunc is used instead.
406 addSettingChangeHandler: function(name
, changeFunc
) {
407 var settingElem
= document
.getElementById("noVNC_setting_" + name
);
408 if (changeFunc
=== undefined) {
409 changeFunc = function () { UI
.saveSetting(name
); };
411 settingElem
.addEventListener('change', changeFunc
);
414 addSettingsHandlers: function() {
415 document
.getElementById("noVNC_settings_button")
416 .addEventListener('click', UI
.toggleSettingsPanel
);
418 UI
.addSettingChangeHandler('encrypt');
419 UI
.addSettingChangeHandler('true_color');
420 UI
.addSettingChangeHandler('cursor');
421 UI
.addSettingChangeHandler('resize');
422 UI
.addSettingChangeHandler('resize', UI
.enableDisableViewClip
);
423 UI
.addSettingChangeHandler('resize', UI
.applyResizeMode
);
424 UI
.addSettingChangeHandler('clip');
425 UI
.addSettingChangeHandler('shared');
426 UI
.addSettingChangeHandler('view_only');
427 UI
.addSettingChangeHandler('host');
428 UI
.addSettingChangeHandler('port');
429 UI
.addSettingChangeHandler('path');
430 UI
.addSettingChangeHandler('repeaterID');
431 UI
.addSettingChangeHandler('logging');
432 UI
.addSettingChangeHandler('logging', UI
.updateLogging
);
433 UI
.addSettingChangeHandler('reconnect');
434 UI
.addSettingChangeHandler('reconnect_delay');
437 addFullscreenHandlers: function() {
438 document
.getElementById("noVNC_fullscreen_button")
439 .addEventListener('click', UI
.toggleFullscreen
);
441 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
442 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
443 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
444 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
453 updateState: function(rfb
, state
, oldstate
) {
456 document
.documentElement
.classList
.remove("noVNC_connecting");
457 document
.documentElement
.classList
.remove("noVNC_connected");
458 document
.documentElement
.classList
.remove("noVNC_disconnecting");
459 document
.documentElement
.classList
.remove("noVNC_reconnecting");
463 document
.getElementById("noVNC_transition_text").textContent
= _("Connecting...");
464 document
.documentElement
.classList
.add("noVNC_connecting");
468 UI
.inhibit_reconnect
= false;
469 document
.documentElement
.classList
.add("noVNC_connected");
470 if (rfb
&& rfb
.get_encrypt()) {
471 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
473 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
477 case 'disconnecting':
478 UI
.connected
= false;
479 document
.getElementById("noVNC_transition_text").textContent
= _("Disconnecting...");
480 document
.documentElement
.classList
.add("noVNC_disconnecting");
483 UI
.showStatus(_("Disconnected"));
486 msg
= "Invalid UI state";
488 UI
.showStatus(msg
, 'error');
492 UI
.updateVisualState();
495 // Disable/enable controls depending on connection state
496 updateVisualState: function() {
497 //Util.Debug(">> updateVisualState");
498 document
.getElementById('noVNC_setting_encrypt').disabled
= UI
.connected
;
499 document
.getElementById('noVNC_setting_true_color').disabled
= UI
.connected
;
500 if (Util
.browserSupportsCursorURIs()) {
501 document
.getElementById('noVNC_setting_cursor').disabled
= UI
.connected
;
503 UI
.updateSetting('cursor', !Util
.isTouchDevice
);
504 document
.getElementById('noVNC_setting_cursor').disabled
= true;
507 UI
.enableDisableViewClip();
508 document
.getElementById('noVNC_setting_shared').disabled
= UI
.connected
;
509 document
.getElementById('noVNC_setting_view_only').disabled
= UI
.connected
;
510 document
.getElementById('noVNC_setting_host').disabled
= UI
.connected
;
511 document
.getElementById('noVNC_setting_port').disabled
= UI
.connected
;
512 document
.getElementById('noVNC_setting_path').disabled
= UI
.connected
;
513 document
.getElementById('noVNC_setting_repeaterID').disabled
= UI
.connected
;
514 document
.getElementById('noVNC_setting_reconnect').disabled
= UI
.connected
;
515 document
.getElementById('noVNC_setting_reconnect_delay').disabled
= UI
.connected
;
519 UI
.setMouseButton(1);
521 // Hide the controlbar after 2 seconds
522 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
524 UI
.updateXvpButton(0);
528 // Hide input related buttons in view only mode
529 if (UI
.rfb
&& UI
.rfb
.get_view_only()) {
530 document
.getElementById('noVNC_keyboard_button')
531 .classList
.add('noVNC_hidden');
532 document
.getElementById('noVNC_toggle_extra_keys_button')
533 .classList
.add('noVNC_hidden');
535 document
.getElementById('noVNC_keyboard_button')
536 .classList
.remove('noVNC_hidden');
537 document
.getElementById('noVNC_toggle_extra_keys_button')
538 .classList
.remove('noVNC_hidden');
541 // State change disables viewport dragging.
542 // It is enabled (toggled) by direct click on the button
543 UI
.setViewDrag(false);
545 // State change also closes the password dialog
546 document
.getElementById('noVNC_password_dlg')
547 .classList
.remove('noVNC_open');
549 //Util.Debug("<< updateVisualState");
552 showStatus: function(text
, status_type
, time
) {
553 var statusElem
= document
.getElementById('noVNC_status');
555 clearTimeout(UI
.statusTimeout
);
557 if (typeof status_type
=== 'undefined') {
558 status_type
= 'normal';
561 statusElem
.classList
.remove("noVNC_status_normal");
562 statusElem
.classList
.remove("noVNC_status_warn");
563 statusElem
.classList
.remove("noVNC_status_error");
565 switch (status_type
) {
568 statusElem
.classList
.add("noVNC_status_warn");
571 statusElem
.classList
.add("noVNC_status_error");
576 statusElem
.classList
.add("noVNC_status_normal");
580 statusElem
.textContent
= text
;
581 statusElem
.classList
.add("noVNC_open");
583 // If no time was specified, show the status for 1.5 seconds
584 if (typeof time
=== 'undefined') {
588 // Error messages do not timeout
589 if (status_type
!== 'error') {
590 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
594 hideStatus: function() {
595 clearTimeout(UI
.statusTimeout
);
596 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
599 notification: function (rfb
, msg
, level
, options
) {
600 UI
.showStatus(msg
, level
);
603 activateControlbar: function(event
) {
604 clearTimeout(UI
.idleControlbarTimeout
);
605 // We manipulate the anchor instead of the actual control
606 // bar in order to avoid creating new a stacking group
607 document
.getElementById('noVNC_control_bar_anchor')
608 .classList
.remove("noVNC_idle");
609 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
612 idleControlbar: function() {
613 document
.getElementById('noVNC_control_bar_anchor')
614 .classList
.add("noVNC_idle");
617 keepControlbar: function() {
618 clearTimeout(UI
.closeControlbarTimeout
);
621 openControlbar: function() {
622 document
.getElementById('noVNC_control_bar')
623 .classList
.add("noVNC_open");
626 closeControlbar: function() {
628 document
.getElementById('noVNC_control_bar')
629 .classList
.remove("noVNC_open");
632 toggleControlbar: function() {
633 if (document
.getElementById('noVNC_control_bar')
634 .classList
.contains("noVNC_open")) {
635 UI
.closeControlbar();
641 toggleControlbarSide: function () {
642 // Temporarily disable animation to avoid weird movement
643 var bar
= document
.getElementById('noVNC_control_bar');
644 bar
.style
.transitionDuration
= '0s';
645 bar
.addEventListener('transitionend', function () { this.style
.transitionDuration
= ""; });
647 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
648 if (anchor
.classList
.contains("noVNC_right")) {
649 WebUtil
.writeSetting('controlbar_pos', 'left');
650 anchor
.classList
.remove("noVNC_right");
652 WebUtil
.writeSetting('controlbar_pos', 'right');
653 anchor
.classList
.add("noVNC_right");
656 // Consider this a movement of the handle
657 UI
.controlbarDrag
= true;
660 dragControlbarHandle: function (e
) {
661 if (!UI
.controlbarGrabbed
) return;
663 var ptr
= Util
.getPointerEvent(e
);
665 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
666 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
667 if (anchor
.classList
.contains("noVNC_right")) {
668 UI
.toggleControlbarSide();
670 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
671 if (!anchor
.classList
.contains("noVNC_right")) {
672 UI
.toggleControlbarSide();
676 if (!UI
.controlbarDrag
) {
677 // The goal is to trigger on a certain physical width, the
678 // devicePixelRatio brings us a bit closer but is not optimal.
679 var dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
680 var dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
682 if (dragDistance
< dragThreshold
) return;
684 UI
.controlbarDrag
= true;
687 var eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
689 UI
.moveControlbarHandle(eventY
);
694 UI
.activateControlbar();
697 // Move the handle but don't allow any position outside the bounds
698 moveControlbarHandle: function (viewportRelativeY
) {
699 var handle
= document
.getElementById("noVNC_control_bar_handle");
700 var handleHeight
= handle
.getBoundingClientRect().height
;
701 var controlbarBounds
= document
.getElementById("noVNC_control_bar")
702 .getBoundingClientRect();
705 // These heights need to be non-zero for the below logic to work
706 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
710 var newY
= viewportRelativeY
;
712 // Check if the coordinates are outside the control bar
713 if (newY
< controlbarBounds
.top
+ margin
) {
714 // Force coordinates to be below the top of the control bar
715 newY
= controlbarBounds
.top
+ margin
;
717 } else if (newY
> controlbarBounds
.top
+
718 controlbarBounds
.height
- handleHeight
- margin
) {
719 // Force coordinates to be above the bottom of the control bar
720 newY
= controlbarBounds
.top
+
721 controlbarBounds
.height
- handleHeight
- margin
;
724 // Corner case: control bar too small for stable position
725 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
726 newY
= controlbarBounds
.top
+
727 (controlbarBounds
.height
- handleHeight
) / 2;
730 // The transform needs coordinates that are relative to the parent
731 var parentRelativeY
= newY
- controlbarBounds
.top
;
732 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
735 updateControlbarHandle: function () {
736 // Since the control bar is fixed on the viewport and not the page,
737 // the move function expects coordinates relative the the viewport.
738 var handle
= document
.getElementById("noVNC_control_bar_handle");
739 var handleBounds
= handle
.getBoundingClientRect();
740 UI
.moveControlbarHandle(handleBounds
.top
);
743 controlbarHandleMouseUp: function(e
) {
744 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
746 // mouseup and mousedown on the same place toggles the controlbar
747 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
748 UI
.toggleControlbar();
752 UI
.activateControlbar();
754 UI
.controlbarGrabbed
= false;
757 controlbarHandleMouseDown: function(e
) {
758 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
760 var ptr
= Util
.getPointerEvent(e
);
762 var handle
= document
.getElementById("noVNC_control_bar_handle");
763 var bounds
= handle
.getBoundingClientRect();
765 Util
.setCapture(handle
);
766 UI
.controlbarGrabbed
= true;
767 UI
.controlbarDrag
= false;
769 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
770 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
774 UI
.activateControlbar();
777 toggleExpander: function(e
) {
778 if (this.classList
.contains("noVNC_open")) {
779 this.classList
.remove("noVNC_open");
781 this.classList
.add("noVNC_open");
791 // Initial page load read/initialization of settings
792 initSetting: function(name
, defVal
) {
793 // Check Query string followed by cookie
794 var val
= WebUtil
.getConfigVar(name
);
796 val
= WebUtil
.readSetting(name
, defVal
);
798 UI
.updateSetting(name
, val
);
802 // Update cookie and form control setting. If value is not set, then
803 // updates from control to current cookie setting.
804 updateSetting: function(name
, value
) {
806 // Save the cookie for this session
807 if (typeof value
!== 'undefined') {
808 WebUtil
.writeSetting(name
, value
);
811 // Update the settings control
812 value
= UI
.getSetting(name
);
814 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
815 if (ctrl
.type
=== 'checkbox') {
816 ctrl
.checked
= value
;
818 } else if (typeof ctrl
.options
!== 'undefined') {
819 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
820 if (ctrl
.options
[i
].value
=== value
) {
821 ctrl
.selectedIndex
= i
;
826 /*Weird IE9 error leads to 'null' appearring
827 in textboxes instead of ''.*/
828 if (value
=== null) {
835 // Save control setting to cookie
836 saveSetting: function(name
) {
837 var val
, ctrl
= document
.getElementById('noVNC_setting_' + name
);
838 if (ctrl
.type
=== 'checkbox') {
840 } else if (typeof ctrl
.options
!== 'undefined') {
841 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
845 WebUtil
.writeSetting(name
, val
);
846 //Util.Debug("Setting saved '" + name + "=" + val + "'");
850 // Read form control compatible setting from cookie
851 getSetting: function(name
) {
852 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
853 var val
= WebUtil
.readSetting(name
);
854 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
855 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
870 closeAllPanels: function() {
871 UI
.closeSettingsPanel();
873 UI
.closeClipboardPanel();
883 openSettingsPanel: function() {
887 // Refresh UI elements from saved cookies
888 UI
.updateSetting('encrypt');
889 UI
.updateSetting('true_color');
890 if (Util
.browserSupportsCursorURIs()) {
891 UI
.updateSetting('cursor');
893 UI
.updateSetting('cursor', !Util
.isTouchDevice
);
894 document
.getElementById('noVNC_setting_cursor').disabled
= true;
896 UI
.updateSetting('clip');
897 UI
.updateSetting('resize');
898 UI
.updateSetting('shared');
899 UI
.updateSetting('view_only');
900 UI
.updateSetting('path');
901 UI
.updateSetting('repeaterID');
902 UI
.updateSetting('logging');
903 UI
.updateSetting('reconnect');
904 UI
.updateSetting('reconnect_delay');
906 document
.getElementById('noVNC_settings')
907 .classList
.add("noVNC_open");
908 document
.getElementById('noVNC_settings_button')
909 .classList
.add("noVNC_selected");
912 closeSettingsPanel: function() {
913 document
.getElementById('noVNC_settings')
914 .classList
.remove("noVNC_open");
915 document
.getElementById('noVNC_settings_button')
916 .classList
.remove("noVNC_selected");
919 toggleSettingsPanel: function() {
920 if (document
.getElementById('noVNC_settings')
921 .classList
.contains("noVNC_open")) {
922 UI
.closeSettingsPanel();
924 UI
.openSettingsPanel();
934 openXvpPanel: function() {
938 document
.getElementById('noVNC_xvp')
939 .classList
.add("noVNC_open");
940 document
.getElementById('noVNC_xvp_button')
941 .classList
.add("noVNC_selected");
944 closeXvpPanel: function() {
945 document
.getElementById('noVNC_xvp')
946 .classList
.remove("noVNC_open");
947 document
.getElementById('noVNC_xvp_button')
948 .classList
.remove("noVNC_selected");
951 toggleXvpPanel: function() {
952 if (document
.getElementById('noVNC_xvp')
953 .classList
.contains("noVNC_open")) {
960 // Disable/enable XVP button
961 updateXvpButton: function(ver
) {
962 if (ver
>= 1 && !UI
.rfb
.get_view_only()) {
963 document
.getElementById('noVNC_xvp_button')
964 .classList
.remove("noVNC_hidden");
966 document
.getElementById('noVNC_xvp_button')
967 .classList
.add("noVNC_hidden");
968 // Close XVP panel if open
979 openClipboardPanel: function() {
983 document
.getElementById('noVNC_clipboard')
984 .classList
.add("noVNC_open");
985 document
.getElementById('noVNC_clipboard_button')
986 .classList
.add("noVNC_selected");
989 closeClipboardPanel: function() {
990 document
.getElementById('noVNC_clipboard')
991 .classList
.remove("noVNC_open");
992 document
.getElementById('noVNC_clipboard_button')
993 .classList
.remove("noVNC_selected");
996 toggleClipboardPanel: function() {
997 if (document
.getElementById('noVNC_clipboard')
998 .classList
.contains("noVNC_open")) {
999 UI
.closeClipboardPanel();
1001 UI
.openClipboardPanel();
1005 clipboardReceive: function(rfb
, text
) {
1006 Util
.Debug(">> UI.clipboardReceive: " + text
.substr(0,40) + "...");
1007 document
.getElementById('noVNC_clipboard_text').value
= text
;
1008 Util
.Debug("<< UI.clipboardReceive");
1011 clipboardClear: function() {
1012 document
.getElementById('noVNC_clipboard_text').value
= "";
1013 UI
.rfb
.clipboardPasteFrom("");
1016 clipboardSend: function() {
1017 var text
= document
.getElementById('noVNC_clipboard_text').value
;
1018 Util
.Debug(">> UI.clipboardSend: " + text
.substr(0,40) + "...");
1019 UI
.rfb
.clipboardPasteFrom(text
);
1020 Util
.Debug("<< UI.clipboardSend");
1029 openConnectPanel: function() {
1030 document
.getElementById('noVNC_connect_dlg')
1031 .classList
.add("noVNC_open");
1034 closeConnectPanel: function() {
1035 document
.getElementById('noVNC_connect_dlg')
1036 .classList
.remove("noVNC_open");
1039 connect: function(event
, password
) {
1040 var host
= UI
.getSetting('host');
1041 var port
= UI
.getSetting('port');
1042 var path
= UI
.getSetting('path');
1044 if (typeof password
=== 'undefined') {
1045 password
= WebUtil
.getConfigVar('password');
1048 if (password
=== null) {
1049 password
= undefined;
1052 if ((!host
) || (!port
)) {
1053 var msg
= _("Must set host and port");
1055 UI
.showStatus(msg
, 'error');
1059 if (!UI
.initRFB()) return;
1061 UI
.closeAllPanels();
1062 UI
.closeConnectPanel();
1064 UI
.rfb
.set_encrypt(UI
.getSetting('encrypt'));
1065 UI
.rfb
.set_true_color(UI
.getSetting('true_color'));
1066 UI
.rfb
.set_local_cursor(UI
.getSetting('cursor'));
1067 UI
.rfb
.set_shared(UI
.getSetting('shared'));
1068 UI
.rfb
.set_view_only(UI
.getSetting('view_only'));
1069 UI
.rfb
.set_repeaterID(UI
.getSetting('repeaterID'));
1071 UI
.rfb
.connect(host
, port
, password
, path
);
1074 disconnect: function() {
1075 UI
.closeAllPanels();
1076 UI
.rfb
.disconnect();
1078 // Disable automatic reconnecting
1079 UI
.inhibit_reconnect
= true;
1081 // Restore the callback used for initial resize
1082 UI
.rfb
.set_onFBUComplete(UI
.initialResize
);
1084 // Don't display the connection settings until we're actually disconnected
1087 reconnect: function() {
1088 UI
.reconnect_callback
= null;
1090 // if reconnect has been disabled in the meantime, do nothing.
1091 if (UI
.inhibit_reconnect
) {
1095 UI
.connect(null, UI
.reconnect_password
);
1098 disconnectFinished: function (rfb
, reason
) {
1099 if (typeof reason
!== 'undefined') {
1100 UI
.showStatus(reason
, 'error');
1101 } else if (UI
.getSetting('reconnect', false) === true && !UI
.inhibit_reconnect
) {
1102 document
.getElementById("noVNC_transition_text").textContent
= _("Reconnecting...");
1103 document
.documentElement
.classList
.add("noVNC_reconnecting");
1105 var delay
= parseInt(UI
.getSetting('reconnect_delay'));
1106 UI
.reconnect_callback
= setTimeout(UI
.reconnect
, delay
);
1110 UI
.openControlbar();
1111 UI
.openConnectPanel();
1114 cancelReconnect: function() {
1115 if (UI
.reconnect_callback
!== null) {
1116 clearTimeout(UI
.reconnect_callback
);
1117 UI
.reconnect_callback
= null;
1120 document
.documentElement
.classList
.remove("noVNC_reconnecting");
1121 UI
.openControlbar();
1122 UI
.openConnectPanel();
1131 passwordRequired: function(rfb
, msg
) {
1133 document
.getElementById('noVNC_password_dlg')
1134 .classList
.add('noVNC_open');
1136 setTimeout(function () {
1137 document
.getElementById('noVNC_password_input').focus();
1140 if (typeof msg
=== 'undefined') {
1141 msg
= _("Password is required");
1144 UI
.showStatus(msg
, "warning");
1147 setPassword: function(e
) {
1148 var password
= document
.getElementById('noVNC_password_input').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 if (resizeMode
=== 'remote') {
1225 // Request changing the resolution of the remote display to
1226 // the size of the local browser viewport.
1228 // In order to not send multiple requests before the browser-resize
1229 // is finished we wait 0.5 seconds before sending the request.
1230 clearTimeout(UI
.resizeTimeout
);
1231 UI
.resizeTimeout
= setTimeout(function(){
1232 // Request a remote size covering the viewport
1233 if (UI
.rfb
.requestDesktopSize(screen
.w
, screen
.h
)) {
1234 Util
.Debug('Requested new desktop size: ' +
1235 screen
.w
+ 'x' + screen
.h
);
1239 } else if (resizeMode
=== 'scale' || resizeMode
=== 'downscale') {
1240 var downscaleOnly
= resizeMode
=== 'downscale';
1241 display
.autoscale(screen
.w
, screen
.h
, downscaleOnly
);
1246 // Gets the the size of the available viewport in the browser window
1247 screenSize: function() {
1248 var screen
= document
.getElementById('noVNC_screen');
1251 screen
.style
.overflow
= "hidden";
1253 width
= screen
.offsetWidth
;
1254 height
= screen
.offsetHeight
;
1256 screen
.style
.overflow
= "auto";
1258 return {w
: width
, h
: height
};
1261 // Normally we only apply the current resize mode after a window resize
1262 // event. This means that when a new connection is opened, there is no
1263 // resize mode active.
1264 // We have to wait until the first FBU because this is where the client
1265 // will find the supported encodings of the server. Some calls later in
1266 // the chain is dependant on knowing the server-capabilities.
1267 initialResize: function(rfb
, fbu
) {
1268 UI
.applyResizeMode();
1269 // After doing this once, we remove the callback.
1270 UI
.rfb
.set_onFBUComplete(function() { });
1279 // Set and configure viewport clipping
1280 setViewClip: function(clip
) {
1281 UI
.updateSetting('clip', clip
);
1282 UI
.updateViewClip();
1285 // Update parameters that depend on the clip setting
1286 updateViewClip: function() {
1287 if (!UI
.rfb
) return;
1289 var display
= UI
.rfb
.get_display();
1290 var cur_clip
= display
.get_viewport();
1291 var new_clip
= UI
.getSetting('clip');
1293 var resizeSetting
= UI
.getSetting('resize');
1294 if (resizeSetting
=== 'downscale' || resizeSetting
=== 'scale') {
1295 // Disable clipping if we are scaling
1297 } else if (Util
.isTouchDevice
) {
1298 // Touch devices usually have shit scrollbars
1302 if (cur_clip
!== new_clip
) {
1303 display
.set_viewport(new_clip
);
1306 var size
= UI
.screenSize();
1308 if (new_clip
&& size
) {
1309 // When clipping is enabled, the screen is limited to
1310 // the size of the browser window.
1311 display
.viewportChangeSize(size
.w
, size
.h
);
1315 // Handle special cases where clipping is forced on/off or locked
1316 enableDisableViewClip: function() {
1317 var resizeSetting
= UI
.getSetting('resize');
1318 if (resizeSetting
=== 'downscale' || resizeSetting
=== 'scale') {
1319 // Disable clipping if we are scaling
1320 document
.getElementById('noVNC_setting_clip').disabled
= true;
1322 document
.getElementById('noVNC_setting_clip').disabled
=
1323 UI
.connected
|| Util
.isTouchDevice
;
1333 toggleViewDrag: function() {
1334 if (!UI
.rfb
) return;
1336 var drag
= UI
.rfb
.get_viewportDrag();
1337 UI
.setViewDrag(!drag
);
1340 // Set the view drag mode which moves the viewport on mouse drags
1341 setViewDrag: function(drag
) {
1342 if (!UI
.rfb
) return;
1344 UI
.rfb
.set_viewportDrag(drag
);
1346 UI
.updateViewDrag();
1349 updateViewDrag: function() {
1350 var clipping
= false;
1352 if (!UI
.connected
) return;
1354 // Check if viewport drag is possible. It is only possible
1355 // if the remote display is clipping the client display.
1356 if (UI
.rfb
.get_display().get_viewport() &&
1357 UI
.rfb
.get_display().clippingDisplay()) {
1361 var viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1364 UI
.rfb
.get_viewportDrag()) {
1365 // The size of the remote display is the same or smaller
1366 // than the client display. Make sure viewport drag isn't
1367 // active when it can't be used.
1368 UI
.rfb
.set_viewportDrag(false);
1371 if (UI
.rfb
.get_viewportDrag()) {
1372 viewDragButton
.classList
.add("noVNC_selected");
1374 viewDragButton
.classList
.remove("noVNC_selected");
1377 // Different behaviour for touch vs non-touch
1378 // The button is disabled instead of hidden on touch devices
1379 if (Util
.isTouchDevice
) {
1380 viewDragButton
.classList
.remove("noVNC_hidden");
1383 viewDragButton
.disabled
= false;
1385 viewDragButton
.disabled
= true;
1388 viewDragButton
.disabled
= false;
1391 viewDragButton
.classList
.remove("noVNC_hidden");
1393 viewDragButton
.classList
.add("noVNC_hidden");
1404 showVirtualKeyboard: function() {
1405 if (!Util
.isTouchDevice
) return;
1407 var input
= document
.getElementById('noVNC_keyboardinput');
1409 if (document
.activeElement
== input
) return;
1414 var l
= input
.value
.length
;
1415 // Move the caret to the end
1416 input
.setSelectionRange(l
, l
);
1417 } catch (err
) {} // setSelectionRange is undefined in Google Chrome
1420 hideVirtualKeyboard: function() {
1421 if (!Util
.isTouchDevice
) return;
1423 var input
= document
.getElementById('noVNC_keyboardinput');
1425 if (document
.activeElement
!= input
) return;
1430 toggleVirtualKeyboard: function () {
1431 if (document
.getElementById('noVNC_keyboard_button')
1432 .classList
.contains("noVNC_selected")) {
1433 UI
.hideVirtualKeyboard();
1435 UI
.showVirtualKeyboard();
1439 onfocusVirtualKeyboard: function(event
) {
1440 document
.getElementById('noVNC_keyboard_button')
1441 .classList
.add("noVNC_selected");
1444 onblurVirtualKeyboard: function(event
) {
1445 document
.getElementById('noVNC_keyboard_button')
1446 .classList
.remove("noVNC_selected");
1449 keepVirtualKeyboard: function(event
) {
1450 var input
= document
.getElementById('noVNC_keyboardinput');
1452 // Only prevent focus change if the virtual keyboard is active
1453 if (document
.activeElement
!= input
) {
1457 // Only allow focus to move to other elements that need
1458 // focus to function properly
1459 if (event
.target
.form
!== undefined) {
1460 switch (event
.target
.type
) {
1469 case 'select-multiple':
1474 event
.preventDefault();
1477 keyboardinputReset: function() {
1478 var kbi
= document
.getElementById('noVNC_keyboardinput');
1479 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1480 UI
.lastKeyboardinput
= kbi
.value
;
1483 // When normal keyboard events are left uncought, use the input events from
1484 // the keyboardinput element instead and generate the corresponding key events.
1485 // This code is required since some browsers on Android are inconsistent in
1486 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1487 keyInput: function(event
) {
1489 if (!UI
.rfb
) return;
1491 var newValue
= event
.target
.value
;
1493 if (!UI
.lastKeyboardinput
) {
1494 UI
.keyboardinputReset();
1496 var oldValue
= UI
.lastKeyboardinput
;
1500 // Try to check caret position since whitespace at the end
1501 // will not be considered by value.length in some browsers
1502 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1504 // selectionStart is undefined in Google Chrome
1505 newLen
= newValue
.length
;
1507 var oldLen
= oldValue
.length
;
1510 var inputs
= newLen
- oldLen
;
1512 backspaces
= -inputs
;
1517 // Compare the old string with the new to account for
1518 // text-corrections or other input that modify existing text
1520 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1521 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1522 inputs
= newLen
- i
;
1523 backspaces
= oldLen
- i
;
1528 // Send the key events
1529 for (i
= 0; i
< backspaces
; i
++) {
1530 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
);
1532 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1533 UI
.rfb
.sendKey(keysyms
.fromUnicode(newValue
.charCodeAt(i
)).keysym
);
1536 // Control the text content length in the keyboardinput element
1537 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1538 UI
.keyboardinputReset();
1539 } else if (newLen
< 1) {
1540 // There always have to be some text in the keyboardinput
1541 // element with which backspace can interact.
1542 UI
.keyboardinputReset();
1543 // This sometimes causes the keyboard to disappear for a second
1544 // but it is required for the android keyboard to recognize that
1545 // text has been added to the field
1546 event
.target
.blur();
1547 // This has to be ran outside of the input handler in order to work
1548 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1550 UI
.lastKeyboardinput
= newValue
;
1560 openExtraKeys: function() {
1561 UI
.closeAllPanels();
1562 UI
.openControlbar();
1564 document
.getElementById('noVNC_modifiers')
1565 .classList
.add("noVNC_open");
1566 document
.getElementById('noVNC_toggle_extra_keys_button')
1567 .classList
.add("noVNC_selected");
1570 closeExtraKeys: function() {
1571 document
.getElementById('noVNC_modifiers')
1572 .classList
.remove("noVNC_open");
1573 document
.getElementById('noVNC_toggle_extra_keys_button')
1574 .classList
.remove("noVNC_selected");
1577 toggleExtraKeys: function() {
1578 if(document
.getElementById('noVNC_modifiers')
1579 .classList
.contains("noVNC_open")) {
1580 UI
.closeExtraKeys();
1586 sendEsc: function() {
1587 UI
.rfb
.sendKey(KeyTable
.XK_Escape
);
1590 sendTab: function() {
1591 UI
.rfb
.sendKey(KeyTable
.XK_Tab
);
1594 toggleCtrl: function() {
1595 var btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1596 if (btn
.classList
.contains("noVNC_selected")) {
1597 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, false);
1598 btn
.classList
.remove("noVNC_selected");
1600 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, true);
1601 btn
.classList
.add("noVNC_selected");
1605 toggleAlt: function() {
1606 var btn
= document
.getElementById('noVNC_toggle_alt_button');
1607 if (btn
.classList
.contains("noVNC_selected")) {
1608 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, false);
1609 btn
.classList
.remove("noVNC_selected");
1611 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, true);
1612 btn
.classList
.add("noVNC_selected");
1616 sendCtrlAltDel: function() {
1617 UI
.rfb
.sendCtrlAltDel();
1626 setMouseButton: function(num
) {
1627 var view_only
= UI
.rfb
.get_view_only();
1628 if (UI
.rfb
&& !view_only
) {
1629 UI
.rfb
.get_mouse().set_touchButton(num
);
1632 var blist
= [0, 1,2,4];
1633 for (var b
= 0; b
< blist
.length
; b
++) {
1634 var button
= document
.getElementById('noVNC_mouse_button' +
1636 if (blist
[b
] === num
&& !view_only
) {
1637 button
.classList
.remove("noVNC_hidden");
1639 button
.classList
.add("noVNC_hidden");
1644 displayBlur: function() {
1645 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1646 UI
.rfb
.get_keyboard().set_focused(false);
1647 UI
.rfb
.get_mouse().set_focused(false);
1651 displayFocus: function() {
1652 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1653 UI
.rfb
.get_keyboard().set_focused(true);
1654 UI
.rfb
.get_mouse().set_focused(true);
1658 updateLogging: function() {
1659 WebUtil
.init_logging(UI
.getSetting('logging'));
1662 updateSessionSize: function(rfb
, width
, height
) {
1663 UI
.updateViewClip();
1664 UI
.updateViewDrag();
1667 updateDesktopName: function(rfb
, name
) {
1668 UI
.desktopName
= name
;
1669 // Display the desktop name in the document title
1670 document
.title
= name
+ " - noVNC";
1673 bell: function(rfb
) {
1674 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1675 document
.getElementById('noVNC_bell').play();
1679 //Helper to add options to dropdown.
1680 addOption: function(selectbox
, text
, value
) {
1681 var optn
= document
.createElement("OPTION");
1684 selectbox
.options
.add(optn
);
1693 /* [module] UI.load(); */
1696 /* [module] export default UI; */