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
) {
37 msg
+= " <div class=\"noVNC_location\">";
38 msg
+= event
.filename
;
39 msg
+= ":" + event
.lineno
+ ":" + event
.colno
;
42 if ((event
.error
!== undefined) &&
43 (event
.error
.stack
!== undefined)) {
44 msg
+= "<div class=\"noVNC_stack\">";
45 msg
+= event
.error
.stack
;
49 document
.getElementById('noVNC_fallback_error')
50 .classList
.add("noVNC_open");
51 document
.getElementById('noVNC_fallback_errormsg').innerHTML
= msg
;
53 document
.write("noVNC encountered an error.");
55 // Don't return true since this would prevent the error
56 // from being printed to the browser console.
60 // Set up translations
61 var LINGUAS
= ["de", "el", "nl", "sv"];
62 Util
.Localisation
.setup(LINGUAS
);
63 if (Util
.Localisation
.language
!== "en") {
65 {'app': ["locale/" + Util
.Localisation
.language
+ ".js"]});
68 /* [begin skip-as-module] */
69 // Load supporting scripts
71 {'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js",
72 "input/xtscancodes.js", "input/util.js", "input/devices.js",
73 "display.js", "inflator.js", "rfb.js", "input/keysym.js"]});
75 window
.onscriptsload = function () { UI
.load(); };
76 /* [end skip-as-module] */
78 var _
= Util
.Localisation
.get;
87 hideKeyboardTimeout
: null,
88 idleControlbarTimeout
: null,
89 closeControlbarTimeout
: null,
91 controlbarGrabbed
: false,
92 controlbarDrag
: false,
93 controlbarMouseDownClientY
: 0,
94 controlbarMouseDownOffsetY
: 0,
97 rememberedClipSetting
: null,
98 lastKeyboardinput
: null,
99 defaultKeyboardinputLen
: 100,
101 // Setup rfb object, load settings from browser storage, then call
102 // UI.init to setup the UI/menus
103 load: function(callback
) {
104 WebUtil
.initSettings(UI
.start
, callback
);
107 // Render default UI and initialize settings menu
108 start: function(callback
) {
110 // Setup global variables first
111 UI
.isSafari
= (navigator
.userAgent
.indexOf('Safari') !== -1 &&
112 navigator
.userAgent
.indexOf('Chrome') === -1);
117 Util
.Localisation
.translateDOM();
119 // Adapt the interface for touch screen devices
120 if (Util
.isTouchDevice
) {
121 document
.documentElement
.classList
.add("noVNC_touch");
122 // Remove the address bar
123 setTimeout(function() { window
.scrollTo(0, 1); }, 100);
124 UI
.forceSetting('clip', true);
126 UI
.initSetting('clip', false);
129 // Restore control bar position
130 if (WebUtil
.readSetting('controlbar_pos') === 'right') {
131 UI
.toggleControlbarSide();
134 // Setup and initialize event handlers
135 UI
.setupWindowEvents();
136 UI
.setupFullscreen();
137 UI
.addControlbarHandlers();
138 UI
.addTouchSpecificHandlers();
139 UI
.addExtraKeysHandlers();
141 UI
.addConnectionControlHandlers();
142 UI
.addClipboardHandlers();
143 UI
.addSettingsHandlers();
145 // Show the connect panel on first load unless autoconnecting
147 UI
.openConnectPanel();
152 UI
.updateVisualState();
154 document
.getElementById('noVNC_setting_host').focus();
156 var autoconnect
= WebUtil
.getConfigVar('autoconnect', false);
157 if (autoconnect
=== 'true' || autoconnect
== '1') {
164 if (typeof callback
=== "function") {
169 initSettings: function() {
170 // Stylesheet selection dropdown
171 var sheet
= WebUtil
.selectStylesheet();
172 var sheets
= WebUtil
.getStylesheets();
174 for (i
= 0; i
< sheets
.length
; i
+= 1) {
175 UI
.addOption(document
.getElementById('noVNC_setting_stylesheet'),sheets
[i
].title
, sheets
[i
].title
);
178 // Logging selection dropdown
179 var llevels
= ['error', 'warn', 'info', 'debug'];
180 for (i
= 0; i
< llevels
.length
; i
+= 1) {
181 UI
.addOption(document
.getElementById('noVNC_setting_logging'),llevels
[i
], llevels
[i
]);
184 // Settings with immediate effects
185 UI
.initSetting('logging', 'warn');
186 WebUtil
.init_logging(UI
.getSetting('logging'));
188 UI
.initSetting('stylesheet', 'default');
189 WebUtil
.selectStylesheet(null);
190 // call twice to get around webkit bug
191 WebUtil
.selectStylesheet(UI
.getSetting('stylesheet'));
193 // if port == 80 (or 443) then it won't be present and should be
195 var port
= window
.location
.port
;
197 if (window
.location
.protocol
.substring(0,5) == 'https') {
200 else if (window
.location
.protocol
.substring(0,4) == 'http') {
205 /* Populate the controls if defaults are provided in the URL */
206 UI
.initSetting('host', window
.location
.hostname
);
207 UI
.initSetting('port', port
);
208 UI
.initSetting('password', '');
209 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
210 UI
.initSetting('true_color', true);
211 UI
.initSetting('cursor', !Util
.isTouchDevice
);
212 UI
.initSetting('resize', 'off');
213 UI
.initSetting('shared', true);
214 UI
.initSetting('view_only', false);
215 UI
.initSetting('path', 'websockify');
216 UI
.initSetting('repeaterID', '');
217 UI
.initSetting('token', '');
220 setupWindowEvents: function() {
221 window
.addEventListener('resize', UI
.applyResizeMode
);
222 window
.addEventListener('resize', UI
.updateViewClip
);
223 window
.addEventListener('resize', UI
.updateViewDrag
);
225 document
.getElementById("noVNC_status")
226 .addEventListener('click', UI
.hideStatus
);
229 setupFullscreen: function() {
230 // Only show the button if fullscreen is properly supported
231 // * Safari doesn't support alphanumerical input while in fullscreen
233 (document
.documentElement
.requestFullscreen
||
234 document
.documentElement
.mozRequestFullScreen
||
235 document
.documentElement
.webkitRequestFullscreen
||
236 document
.body
.msRequestFullscreen
)) {
237 document
.getElementById('noVNC_fullscreen_button')
238 .classList
.remove("noVNC_hidden");
239 UI
.addFullscreenHandlers();
243 addControlbarHandlers: function() {
244 document
.getElementById("noVNC_control_bar")
245 .addEventListener('mousemove', UI
.activateControlbar
);
246 document
.getElementById("noVNC_control_bar")
247 .addEventListener('mouseup', UI
.activateControlbar
);
248 document
.getElementById("noVNC_control_bar")
249 .addEventListener('mousedown', UI
.activateControlbar
);
250 document
.getElementById("noVNC_control_bar")
251 .addEventListener('keypress', UI
.activateControlbar
);
253 document
.getElementById("noVNC_control_bar")
254 .addEventListener('mousedown', UI
.keepControlbar
);
255 document
.getElementById("noVNC_control_bar")
256 .addEventListener('keypress', UI
.keepControlbar
);
258 document
.getElementById("noVNC_view_drag_button")
259 .addEventListener('click', UI
.toggleViewDrag
);
261 document
.getElementById("noVNC_control_bar_handle")
262 .addEventListener('mousedown', UI
.controlbarHandleMouseDown
);
263 document
.getElementById("noVNC_control_bar_handle")
264 .addEventListener('mouseup', UI
.controlbarHandleMouseUp
);
265 document
.getElementById("noVNC_control_bar_handle")
266 .addEventListener('mousemove', UI
.dragControlbarHandle
);
267 // resize events aren't available for elements
268 window
.addEventListener('resize', UI
.updateControlbarHandle
);
271 addTouchSpecificHandlers: function() {
272 document
.getElementById("noVNC_mouse_button0")
273 .addEventListener('click', function () { UI
.setMouseButton(1); });
274 document
.getElementById("noVNC_mouse_button1")
275 .addEventListener('click', function () { UI
.setMouseButton(2); });
276 document
.getElementById("noVNC_mouse_button2")
277 .addEventListener('click', function () { UI
.setMouseButton(4); });
278 document
.getElementById("noVNC_mouse_button4")
279 .addEventListener('click', function () { UI
.setMouseButton(0); });
280 document
.getElementById("noVNC_keyboard_button")
281 .addEventListener('click', UI
.toggleVirtualKeyboard
);
283 document
.getElementById("noVNC_keyboardinput")
284 .addEventListener('input', UI
.keyInput
);
285 document
.getElementById("noVNC_keyboardinput")
286 .addEventListener('focus', UI
.onfocusVirtualKeyboard
);
287 document
.getElementById("noVNC_keyboardinput")
288 .addEventListener('blur', UI
.onblurVirtualKeyboard
);
289 document
.getElementById("noVNC_keyboardinput")
290 .addEventListener('submit', function () { return false; });
292 document
.documentElement
293 .addEventListener('mousedown', UI
.keepVirtualKeyboard
, true);
295 document
.getElementById("noVNC_control_bar")
296 .addEventListener('touchstart', UI
.activateControlbar
);
297 document
.getElementById("noVNC_control_bar")
298 .addEventListener('touchmove', UI
.activateControlbar
);
299 document
.getElementById("noVNC_control_bar")
300 .addEventListener('touchend', UI
.activateControlbar
);
301 document
.getElementById("noVNC_control_bar")
302 .addEventListener('input', UI
.activateControlbar
);
304 document
.getElementById("noVNC_control_bar")
305 .addEventListener('touchstart', UI
.keepControlbar
);
306 document
.getElementById("noVNC_control_bar")
307 .addEventListener('input', UI
.keepControlbar
);
309 document
.getElementById("noVNC_control_bar_handle")
310 .addEventListener('touchstart', UI
.controlbarHandleMouseDown
);
311 document
.getElementById("noVNC_control_bar_handle")
312 .addEventListener('touchend', UI
.controlbarHandleMouseUp
);
313 document
.getElementById("noVNC_control_bar_handle")
314 .addEventListener('touchmove', UI
.dragControlbarHandle
);
316 window
.addEventListener('load', UI
.keyboardinputReset
);
319 addExtraKeysHandlers: function() {
320 document
.getElementById("noVNC_toggle_extra_keys_button")
321 .addEventListener('click', UI
.toggleExtraKeys
);
322 document
.getElementById("noVNC_toggle_ctrl_button")
323 .addEventListener('click', UI
.toggleCtrl
);
324 document
.getElementById("noVNC_toggle_alt_button")
325 .addEventListener('click', UI
.toggleAlt
);
326 document
.getElementById("noVNC_send_tab_button")
327 .addEventListener('click', UI
.sendTab
);
328 document
.getElementById("noVNC_send_esc_button")
329 .addEventListener('click', UI
.sendEsc
);
330 document
.getElementById("noVNC_send_ctrl_alt_del_button")
331 .addEventListener('click', UI
.sendCtrlAltDel
);
334 addXvpHandlers: function() {
335 document
.getElementById("noVNC_xvp_shutdown_button")
336 .addEventListener('click', function() { UI
.rfb
.xvpShutdown(); });
337 document
.getElementById("noVNC_xvp_reboot_button")
338 .addEventListener('click', function() { UI
.rfb
.xvpReboot(); });
339 document
.getElementById("noVNC_xvp_reset_button")
340 .addEventListener('click', function() { UI
.rfb
.xvpReset(); });
341 document
.getElementById("noVNC_xvp_button")
342 .addEventListener('click', UI
.toggleXvpPanel
);
345 addConnectionControlHandlers: function() {
346 document
.getElementById("noVNC_connect_controls_button")
347 .addEventListener('click', UI
.toggleConnectPanel
);
348 document
.getElementById("noVNC_disconnect_button")
349 .addEventListener('click', UI
.disconnect
);
350 document
.getElementById("noVNC_connect_button")
351 .addEventListener('click', UI
.connect
);
353 document
.getElementById("noVNC_password_button")
354 .addEventListener('click', UI
.setPassword
);
357 addClipboardHandlers: function() {
358 document
.getElementById("noVNC_clipboard_button")
359 .addEventListener('click', UI
.toggleClipboardPanel
);
360 document
.getElementById("noVNC_clipboard_text")
361 .addEventListener('focus', UI
.displayBlur
);
362 document
.getElementById("noVNC_clipboard_text")
363 .addEventListener('blur', UI
.displayFocus
);
364 document
.getElementById("noVNC_clipboard_text")
365 .addEventListener('change', UI
.clipboardSend
);
366 document
.getElementById("noVNC_clipboard_clear_button")
367 .addEventListener('click', UI
.clipboardClear
);
370 addSettingsHandlers: function() {
371 document
.getElementById("noVNC_settings_button")
372 .addEventListener('click', UI
.toggleSettingsPanel
);
373 document
.getElementById("noVNC_settings_apply")
374 .addEventListener('click', UI
.settingsApply
);
376 document
.getElementById("noVNC_setting_resize")
377 .addEventListener('change', UI
.enableDisableViewClip
);
380 addFullscreenHandlers: function() {
381 document
.getElementById("noVNC_fullscreen_button")
382 .addEventListener('click', UI
.toggleFullscreen
);
384 window
.addEventListener('fullscreenchange', UI
.updateFullscreenButton
);
385 window
.addEventListener('mozfullscreenchange', UI
.updateFullscreenButton
);
386 window
.addEventListener('webkitfullscreenchange', UI
.updateFullscreenButton
);
387 window
.addEventListener('msfullscreenchange', UI
.updateFullscreenButton
);
390 initRFB: function() {
392 UI
.rfb
= new RFB({'target': document
.getElementById('noVNC_canvas'),
393 'onNotification': UI
.notification
,
394 'onUpdateState': UI
.updateState
,
395 'onDisconnected': UI
.disconnectFinished
,
396 'onPasswordRequired': UI
.passwordRequired
,
397 'onXvpInit': UI
.updateXvpButton
,
398 'onClipboard': UI
.clipboardReceive
,
400 'onFBUComplete': UI
.initialResize
,
401 'onFBResize': UI
.updateSessionSize
,
402 'onDesktopName': UI
.updateDesktopName
});
405 var msg
= "Unable to create RFB client -- " + exc
;
407 UI
.showStatus(msg
, 'error');
418 updateState: function(rfb
, state
, oldstate
) {
421 document
.documentElement
.classList
.remove("noVNC_connecting");
422 document
.documentElement
.classList
.remove("noVNC_connected");
423 document
.documentElement
.classList
.remove("noVNC_disconnecting");
427 document
.getElementById("noVNC_transition_text").innerHTML
= _("Connecting...");
428 document
.documentElement
.classList
.add("noVNC_connecting");
432 document
.documentElement
.classList
.add("noVNC_connected");
433 if (rfb
&& rfb
.get_encrypt()) {
434 msg
= _("Connected (encrypted) to ") + UI
.desktopName
;
436 msg
= _("Connected (unencrypted) to ") + UI
.desktopName
;
440 case 'disconnecting':
441 UI
.connected
= false;
442 document
.getElementById("noVNC_transition_text").innerHTML
= _("Disconnecting...");
443 document
.documentElement
.classList
.add("noVNC_disconnecting");
446 UI
.showStatus(_("Disconnected"));
449 msg
= "Invalid UI state";
451 UI
.showStatus(msg
, 'error');
455 UI
.updateVisualState();
458 // Disable/enable controls depending on connection state
459 updateVisualState: function() {
460 //Util.Debug(">> updateVisualState");
461 document
.getElementById('noVNC_setting_encrypt').disabled
= UI
.connected
;
462 document
.getElementById('noVNC_setting_true_color').disabled
= UI
.connected
;
463 if (Util
.browserSupportsCursorURIs()) {
464 document
.getElementById('noVNC_setting_cursor').disabled
= UI
.connected
;
466 UI
.updateSetting('cursor', !Util
.isTouchDevice
);
467 document
.getElementById('noVNC_setting_cursor').disabled
= true;
470 UI
.enableDisableViewClip();
471 document
.getElementById('noVNC_setting_resize').disabled
= UI
.connected
;
472 document
.getElementById('noVNC_setting_shared').disabled
= UI
.connected
;
473 document
.getElementById('noVNC_setting_view_only').disabled
= UI
.connected
;
474 document
.getElementById('noVNC_setting_path').disabled
= UI
.connected
;
475 document
.getElementById('noVNC_setting_repeaterID').disabled
= UI
.connected
;
479 UI
.setMouseButton(1);
481 // Hide the controlbar after 2 seconds
482 UI
.closeControlbarTimeout
= setTimeout(UI
.closeControlbar
, 2000);
484 UI
.updateXvpButton(0);
488 // Hide input related buttons in view only mode
489 if (UI
.rfb
&& UI
.rfb
.get_view_only()) {
490 document
.getElementById('noVNC_keyboard_button')
491 .classList
.add('noVNC_hidden');
492 document
.getElementById('noVNC_toggle_extra_keys_button')
493 .classList
.add('noVNC_hidden');
495 document
.getElementById('noVNC_keyboard_button')
496 .classList
.remove('noVNC_hidden');
497 document
.getElementById('noVNC_toggle_extra_keys_button')
498 .classList
.remove('noVNC_hidden');
501 // State change disables viewport dragging.
502 // It is enabled (toggled) by direct click on the button
503 UI
.setViewDrag(false);
505 // State change also closes the password dialog
506 document
.getElementById('noVNC_password_dlg')
507 .classList
.remove('noVNC_open');
509 //Util.Debug("<< updateVisualState");
512 showStatus: function(text
, status_type
, time
) {
513 var statusElem
= document
.getElementById('noVNC_status');
515 clearTimeout(UI
.statusTimeout
);
517 if (typeof status_type
=== 'undefined') {
518 status_type
= 'normal';
521 statusElem
.classList
.remove("noVNC_status_normal",
523 "noVNC_status_error");
525 switch (status_type
) {
528 statusElem
.classList
.add("noVNC_status_warn");
531 statusElem
.classList
.add("noVNC_status_error");
536 statusElem
.classList
.add("noVNC_status_normal");
540 statusElem
.innerHTML
= text
;
541 statusElem
.classList
.add("noVNC_open");
543 // If no time was specified, show the status for 1.5 seconds
544 if (typeof time
=== 'undefined') {
548 // Error messages do not timeout
549 if (status_type
!== 'error') {
550 UI
.statusTimeout
= window
.setTimeout(UI
.hideStatus
, time
);
554 hideStatus: function() {
555 clearTimeout(UI
.statusTimeout
);
556 document
.getElementById('noVNC_status').classList
.remove("noVNC_open");
559 notification: function (rfb
, msg
, level
, options
) {
560 UI
.showStatus(msg
, level
);
563 activateControlbar: function(event
) {
564 clearTimeout(UI
.idleControlbarTimeout
);
565 // We manipulate the anchor instead of the actual control
566 // bar in order to avoid creating new a stacking group
567 document
.getElementById('noVNC_control_bar_anchor')
568 .classList
.remove("noVNC_idle");
569 UI
.idleControlbarTimeout
= window
.setTimeout(UI
.idleControlbar
, 2000);
572 idleControlbar: function() {
573 document
.getElementById('noVNC_control_bar_anchor')
574 .classList
.add("noVNC_idle");
577 keepControlbar: function() {
578 clearTimeout(UI
.closeControlbarTimeout
);
581 openControlbar: function() {
582 document
.getElementById('noVNC_control_bar')
583 .classList
.add("noVNC_open");
586 closeControlbar: function() {
588 document
.getElementById('noVNC_control_bar')
589 .classList
.remove("noVNC_open");
592 toggleControlbar: function() {
593 if (document
.getElementById('noVNC_control_bar')
594 .classList
.contains("noVNC_open")) {
595 UI
.closeControlbar();
601 toggleControlbarSide: function () {
602 // Temporarily disable animation to avoid weird movement
603 var bar
= document
.getElementById('noVNC_control_bar');
604 bar
.style
.transitionDuration
= '0s';
605 bar
.addEventListener('transitionend', function () { this.style
.transitionDuration
= ""; });
607 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
608 if (anchor
.classList
.contains("noVNC_right")) {
609 WebUtil
.writeSetting('controlbar_pos', 'left');
610 anchor
.classList
.remove("noVNC_right");
612 WebUtil
.writeSetting('controlbar_pos', 'right');
613 anchor
.classList
.add("noVNC_right");
616 // Consider this a movement of the handle
617 UI
.controlbarDrag
= true;
620 dragControlbarHandle: function (e
) {
621 if (!UI
.controlbarGrabbed
) return;
623 var ptr
= Util
.getPointerEvent(e
);
625 var anchor
= document
.getElementById('noVNC_control_bar_anchor');
626 if (ptr
.clientX
< (window
.innerWidth
* 0.1)) {
627 if (anchor
.classList
.contains("noVNC_right")) {
628 UI
.toggleControlbarSide();
630 } else if (ptr
.clientX
> (window
.innerWidth
* 0.9)) {
631 if (!anchor
.classList
.contains("noVNC_right")) {
632 UI
.toggleControlbarSide();
636 if (!UI
.controlbarDrag
) {
637 // The goal is to trigger on a certain physical width, the
638 // devicePixelRatio brings us a bit closer but is not optimal.
639 var dragThreshold
= 10 * (window
.devicePixelRatio
|| 1);
640 var dragDistance
= Math
.abs(ptr
.clientY
- UI
.controlbarMouseDownClientY
);
642 if (dragDistance
< dragThreshold
) return;
644 UI
.controlbarDrag
= true;
647 var eventY
= ptr
.clientY
- UI
.controlbarMouseDownOffsetY
;
649 UI
.moveControlbarHandle(eventY
);
654 UI
.activateControlbar();
657 // Move the handle but don't allow any position outside the bounds
658 moveControlbarHandle: function (viewportRelativeY
) {
659 var handle
= document
.getElementById("noVNC_control_bar_handle");
660 var handleHeight
= handle
.getBoundingClientRect().height
;
661 var controlbarBounds
= document
.getElementById("noVNC_control_bar")
662 .getBoundingClientRect();
665 // These heights need to be non-zero for the below logic to work
666 if (handleHeight
=== 0 || controlbarBounds
.height
=== 0) {
670 var newY
= viewportRelativeY
;
672 // Check if the coordinates are outside the control bar
673 if (newY
< controlbarBounds
.top
+ margin
) {
674 // Force coordinates to be below the top of the control bar
675 newY
= controlbarBounds
.top
+ margin
;
677 } else if (newY
> controlbarBounds
.top
+
678 controlbarBounds
.height
- handleHeight
- margin
) {
679 // Force coordinates to be above the bottom of the control bar
680 newY
= controlbarBounds
.top
+
681 controlbarBounds
.height
- handleHeight
- margin
;
684 // Corner case: control bar too small for stable position
685 if (controlbarBounds
.height
< (handleHeight
+ margin
* 2)) {
686 newY
= controlbarBounds
.top
+
687 (controlbarBounds
.height
- handleHeight
) / 2;
690 // The transform needs coordinates that are relative to the parent
691 var parentRelativeY
= newY
- controlbarBounds
.top
;
692 handle
.style
.transform
= "translateY(" + parentRelativeY
+ "px)";
695 updateControlbarHandle: function () {
696 // Since the control bar is fixed on the viewport and not the page,
697 // the move function expects coordinates relative the the viewport.
698 var handle
= document
.getElementById("noVNC_control_bar_handle");
699 var handleBounds
= handle
.getBoundingClientRect();
700 UI
.moveControlbarHandle(handleBounds
.top
);
703 controlbarHandleMouseUp: function(e
) {
704 if ((e
.type
== "mouseup") && (e
.button
!= 0)) return;
706 // mouseup and mousedown on the same place toggles the controlbar
707 if (UI
.controlbarGrabbed
&& !UI
.controlbarDrag
) {
708 UI
.toggleControlbar();
712 UI
.activateControlbar();
714 UI
.controlbarGrabbed
= false;
717 controlbarHandleMouseDown: function(e
) {
718 if ((e
.type
== "mousedown") && (e
.button
!= 0)) return;
720 var ptr
= Util
.getPointerEvent(e
);
722 var handle
= document
.getElementById("noVNC_control_bar_handle");
723 var bounds
= handle
.getBoundingClientRect();
725 WebUtil
.setCapture(handle
);
726 UI
.controlbarGrabbed
= true;
727 UI
.controlbarDrag
= false;
729 UI
.controlbarMouseDownClientY
= ptr
.clientY
;
730 UI
.controlbarMouseDownOffsetY
= ptr
.clientY
- bounds
.top
;
734 UI
.activateControlbar();
743 // Initial page load read/initialization of settings
744 initSetting: function(name
, defVal
) {
745 // Check Query string followed by cookie
746 var val
= WebUtil
.getConfigVar(name
);
748 val
= WebUtil
.readSetting(name
, defVal
);
750 UI
.updateSetting(name
, val
);
754 // Update cookie and form control setting. If value is not set, then
755 // updates from control to current cookie setting.
756 updateSetting: function(name
, value
) {
758 // Save the cookie for this session
759 if (typeof value
!== 'undefined') {
760 WebUtil
.writeSetting(name
, value
);
763 // Update the settings control
764 value
= UI
.getSetting(name
);
766 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
767 if (ctrl
.type
=== 'checkbox') {
768 ctrl
.checked
= value
;
770 } else if (typeof ctrl
.options
!== 'undefined') {
771 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
772 if (ctrl
.options
[i
].value
=== value
) {
773 ctrl
.selectedIndex
= i
;
778 /*Weird IE9 error leads to 'null' appearring
779 in textboxes instead of ''.*/
780 if (value
=== null) {
787 // Save control setting to cookie
788 saveSetting: function(name
) {
789 var val
, ctrl
= document
.getElementById('noVNC_setting_' + name
);
790 if (ctrl
.type
=== 'checkbox') {
792 } else if (typeof ctrl
.options
!== 'undefined') {
793 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
797 WebUtil
.writeSetting(name
, val
);
798 //Util.Debug("Setting saved '" + name + "=" + val + "'");
802 // Force a setting to be a certain value
803 forceSetting: function(name
, val
) {
804 UI
.updateSetting(name
, val
);
808 // Read form control compatible setting from cookie
809 getSetting: function(name
) {
810 var ctrl
= document
.getElementById('noVNC_setting_' + name
);
811 var val
= WebUtil
.readSetting(name
);
812 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
813 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
822 // Save/apply settings when 'Apply' button is pressed
823 settingsApply: function() {
824 //Util.Debug(">> settingsApply");
825 UI
.saveSetting('encrypt');
826 UI
.saveSetting('true_color');
827 if (Util
.browserSupportsCursorURIs()) {
828 UI
.saveSetting('cursor');
831 UI
.saveSetting('resize');
833 if (UI
.getSetting('resize') === 'downscale' || UI
.getSetting('resize') === 'scale') {
834 UI
.forceSetting('clip', false);
837 UI
.saveSetting('clip');
838 UI
.saveSetting('shared');
839 UI
.saveSetting('view_only');
840 UI
.saveSetting('path');
841 UI
.saveSetting('repeaterID');
842 UI
.saveSetting('stylesheet');
843 UI
.saveSetting('logging');
845 // Settings with immediate (non-connected related) effect
846 WebUtil
.selectStylesheet(UI
.getSetting('stylesheet'));
847 WebUtil
.init_logging(UI
.getSetting('logging'));
850 //Util.Debug("<< settingsApply");
859 closeAllPanels: function() {
860 UI
.closeSettingsPanel();
862 UI
.closeClipboardPanel();
863 UI
.closeConnectPanel();
873 openSettingsPanel: function() {
877 UI
.updateSetting('encrypt');
878 UI
.updateSetting('true_color');
879 if (Util
.browserSupportsCursorURIs()) {
880 UI
.updateSetting('cursor');
882 UI
.updateSetting('cursor', !Util
.isTouchDevice
);
883 document
.getElementById('noVNC_setting_cursor').disabled
= true;
885 UI
.updateSetting('clip');
886 UI
.updateSetting('resize');
887 UI
.updateSetting('shared');
888 UI
.updateSetting('view_only');
889 UI
.updateSetting('path');
890 UI
.updateSetting('repeaterID');
891 UI
.updateSetting('stylesheet');
892 UI
.updateSetting('logging');
894 document
.getElementById('noVNC_settings')
895 .classList
.add("noVNC_open");
896 document
.getElementById('noVNC_settings_button')
897 .classList
.add("noVNC_selected");
900 closeSettingsPanel: function() {
901 document
.getElementById('noVNC_settings')
902 .classList
.remove("noVNC_open");
903 document
.getElementById('noVNC_settings_button')
904 .classList
.remove("noVNC_selected");
907 // Toggle the settings menu:
908 // On open, settings are refreshed from saved cookies.
909 // On close, settings are applied
910 toggleSettingsPanel: function() {
911 if (document
.getElementById('noVNC_settings')
912 .classList
.contains("noVNC_open")) {
914 UI
.closeSettingsPanel();
916 UI
.openSettingsPanel();
926 openXvpPanel: function() {
930 document
.getElementById('noVNC_xvp')
931 .classList
.add("noVNC_open");
932 document
.getElementById('noVNC_xvp_button')
933 .classList
.add("noVNC_selected");
936 closeXvpPanel: function() {
937 document
.getElementById('noVNC_xvp')
938 .classList
.remove("noVNC_open");
939 document
.getElementById('noVNC_xvp_button')
940 .classList
.remove("noVNC_selected");
943 toggleXvpPanel: function() {
944 if (document
.getElementById('noVNC_xvp')
945 .classList
.contains("noVNC_open")) {
952 // Disable/enable XVP button
953 updateXvpButton: function(ver
) {
954 if (ver
>= 1 && !UI
.rfb
.get_view_only()) {
955 document
.getElementById('noVNC_xvp_button')
956 .classList
.remove("noVNC_hidden");
958 document
.getElementById('noVNC_xvp_button')
959 .classList
.add("noVNC_hidden");
960 // Close XVP panel if open
971 openClipboardPanel: function() {
975 document
.getElementById('noVNC_clipboard')
976 .classList
.add("noVNC_open");
977 document
.getElementById('noVNC_clipboard_button')
978 .classList
.add("noVNC_selected");
981 closeClipboardPanel: function() {
982 document
.getElementById('noVNC_clipboard')
983 .classList
.remove("noVNC_open");
984 document
.getElementById('noVNC_clipboard_button')
985 .classList
.remove("noVNC_selected");
988 toggleClipboardPanel: function() {
989 if (document
.getElementById('noVNC_clipboard')
990 .classList
.contains("noVNC_open")) {
991 UI
.closeClipboardPanel();
993 UI
.openClipboardPanel();
997 clipboardReceive: function(rfb
, text
) {
998 Util
.Debug(">> UI.clipboardReceive: " + text
.substr(0,40) + "...");
999 document
.getElementById('noVNC_clipboard_text').value
= text
;
1000 Util
.Debug("<< UI.clipboardReceive");
1003 clipboardClear: function() {
1004 document
.getElementById('noVNC_clipboard_text').value
= "";
1005 UI
.rfb
.clipboardPasteFrom("");
1008 clipboardSend: function() {
1009 var text
= document
.getElementById('noVNC_clipboard_text').value
;
1010 Util
.Debug(">> UI.clipboardSend: " + text
.substr(0,40) + "...");
1011 UI
.rfb
.clipboardPasteFrom(text
);
1012 Util
.Debug("<< UI.clipboardSend");
1021 openConnectPanel: function() {
1022 UI
.closeAllPanels();
1023 UI
.openControlbar();
1025 document
.getElementById('noVNC_connect_controls')
1026 .classList
.add("noVNC_open");
1027 document
.getElementById('noVNC_connect_controls_button')
1028 .classList
.add("noVNC_selected");
1030 document
.getElementById('noVNC_setting_host').focus();
1033 closeConnectPanel: function() {
1034 document
.getElementById('noVNC_connect_controls')
1035 .classList
.remove("noVNC_open");
1036 document
.getElementById('noVNC_connect_controls_button')
1037 .classList
.remove("noVNC_selected");
1039 UI
.saveSetting('host');
1040 UI
.saveSetting('port');
1041 UI
.saveSetting('token');
1042 //UI.saveSetting('password');
1045 toggleConnectPanel: function() {
1046 if (document
.getElementById('noVNC_connect_controls')
1047 .classList
.contains("noVNC_open")) {
1048 UI
.closeConnectPanel();
1050 UI
.openConnectPanel();
1054 connect: function() {
1055 var host
= document
.getElementById('noVNC_setting_host').value
;
1056 var port
= document
.getElementById('noVNC_setting_port').value
;
1057 var password
= document
.getElementById('noVNC_setting_password').value
;
1058 var token
= document
.getElementById('noVNC_setting_token').value
;
1059 var path
= document
.getElementById('noVNC_setting_path').value
;
1061 //if token is in path then ignore the new token variable
1063 path
= WebUtil
.injectParamIfMissing(path
, "token", token
);
1066 if ((!host
) || (!port
)) {
1067 var msg
= _("Must set host and port");
1069 UI
.showStatus(msg
, 'error');
1073 if (!UI
.initRFB()) return;
1075 UI
.closeAllPanels();
1077 UI
.rfb
.set_encrypt(UI
.getSetting('encrypt'));
1078 UI
.rfb
.set_true_color(UI
.getSetting('true_color'));
1079 UI
.rfb
.set_local_cursor(UI
.getSetting('cursor'));
1080 UI
.rfb
.set_shared(UI
.getSetting('shared'));
1081 UI
.rfb
.set_view_only(UI
.getSetting('view_only'));
1082 UI
.rfb
.set_repeaterID(UI
.getSetting('repeaterID'));
1084 UI
.rfb
.connect(host
, port
, password
, path
);
1087 disconnect: function() {
1088 UI
.closeAllPanels();
1089 UI
.rfb
.disconnect();
1091 // Restore the callback used for initial resize
1092 UI
.rfb
.set_onFBUComplete(UI
.initialResize
);
1094 // Don't display the connection settings until we're actually disconnected
1097 disconnectFinished: function (rfb
, reason
) {
1098 if (typeof reason
!== 'undefined') {
1099 UI
.showStatus(reason
, 'error');
1101 UI
.openConnectPanel();
1110 passwordRequired: function(rfb
, msg
) {
1112 document
.getElementById('noVNC_password_dlg')
1113 .classList
.add('noVNC_open');
1115 setTimeout(function () {
1116 document
.getElementById('noVNC_password_input').focus();
1119 if (typeof msg
=== 'undefined') {
1120 msg
= _("Password is required");
1123 UI
.showStatus(msg
, "warning");
1126 setPassword: function() {
1127 UI
.rfb
.sendPassword(document
.getElementById('noVNC_password_input').value
);
1128 document
.getElementById('noVNC_password_dlg')
1129 .classList
.remove('noVNC_open');
1139 toggleFullscreen: function() {
1140 if (document
.fullscreenElement
|| // alternative standard method
1141 document
.mozFullScreenElement
|| // currently working methods
1142 document
.webkitFullscreenElement
||
1143 document
.msFullscreenElement
) {
1144 if (document
.exitFullscreen
) {
1145 document
.exitFullscreen();
1146 } else if (document
.mozCancelFullScreen
) {
1147 document
.mozCancelFullScreen();
1148 } else if (document
.webkitExitFullscreen
) {
1149 document
.webkitExitFullscreen();
1150 } else if (document
.msExitFullscreen
) {
1151 document
.msExitFullscreen();
1154 if (document
.documentElement
.requestFullscreen
) {
1155 document
.documentElement
.requestFullscreen();
1156 } else if (document
.documentElement
.mozRequestFullScreen
) {
1157 document
.documentElement
.mozRequestFullScreen();
1158 } else if (document
.documentElement
.webkitRequestFullscreen
) {
1159 document
.documentElement
.webkitRequestFullscreen(Element
.ALLOW_KEYBOARD_INPUT
);
1160 } else if (document
.body
.msRequestFullscreen
) {
1161 document
.body
.msRequestFullscreen();
1164 UI
.enableDisableViewClip();
1165 UI
.updateFullscreenButton();
1168 updateFullscreenButton: function() {
1169 if (document
.fullscreenElement
|| // alternative standard method
1170 document
.mozFullScreenElement
|| // currently working methods
1171 document
.webkitFullscreenElement
||
1172 document
.msFullscreenElement
) {
1173 document
.getElementById('noVNC_fullscreen_button')
1174 .classList
.add("noVNC_selected");
1176 document
.getElementById('noVNC_fullscreen_button')
1177 .classList
.remove("noVNC_selected");
1187 // Apply remote resizing or local scaling
1188 applyResizeMode: function() {
1189 if (!UI
.rfb
) return;
1191 var screen
= UI
.screenSize();
1193 if (screen
&& UI
.connected
&& UI
.rfb
.get_display()) {
1195 var display
= UI
.rfb
.get_display();
1196 var resizeMode
= UI
.getSetting('resize');
1198 if (resizeMode
=== 'remote') {
1200 // Request changing the resolution of the remote display to
1201 // the size of the local browser viewport.
1203 // In order to not send multiple requests before the browser-resize
1204 // is finished we wait 0.5 seconds before sending the request.
1205 clearTimeout(UI
.resizeTimeout
);
1206 UI
.resizeTimeout
= setTimeout(function(){
1207 // Request a remote size covering the viewport
1208 if (UI
.rfb
.requestDesktopSize(screen
.w
, screen
.h
)) {
1209 Util
.Debug('Requested new desktop size: ' +
1210 screen
.w
+ 'x' + screen
.h
);
1214 } else if (resizeMode
=== 'scale' || resizeMode
=== 'downscale') {
1215 var downscaleOnly
= resizeMode
=== 'downscale';
1216 var scaleRatio
= display
.autoscale(screen
.w
, screen
.h
, downscaleOnly
);
1218 if (!UI
.rfb
.get_view_only()) {
1219 UI
.rfb
.get_mouse().set_scale(scaleRatio
);
1220 Util
.Debug('Scaling by ' + UI
.rfb
.get_mouse().get_scale());
1226 // Gets the the size of the available viewport in the browser window
1227 screenSize: function() {
1228 var screen
= document
.getElementById('noVNC_screen');
1230 // Hide the scrollbars until the size is calculated
1231 screen
.style
.overflow
= "hidden";
1233 var pos
= Util
.getPosition(screen
);
1237 screen
.style
.overflow
= "visible";
1239 if (isNaN(w
) || isNaN(h
)) {
1242 return {w
: w
, h
: h
};
1246 // Normally we only apply the current resize mode after a window resize
1247 // event. This means that when a new connection is opened, there is no
1248 // resize mode active.
1249 // We have to wait until the first FBU because this is where the client
1250 // will find the supported encodings of the server. Some calls later in
1251 // the chain is dependant on knowing the server-capabilities.
1252 initialResize: function(rfb
, fbu
) {
1253 UI
.applyResizeMode();
1254 // After doing this once, we remove the callback.
1255 UI
.rfb
.set_onFBUComplete(function() { });
1264 // Set and configure viewport clipping
1265 setViewClip: function(clip
) {
1266 UI
.updateSetting('clip', clip
);
1267 UI
.updateViewClip();
1270 // Update parameters that depend on the clip setting
1271 updateViewClip: function() {
1272 if (!UI
.rfb
) return;
1274 var display
= UI
.rfb
.get_display();
1275 var cur_clip
= display
.get_viewport();
1276 var new_clip
= UI
.getSetting('clip');
1278 if (cur_clip
!== new_clip
) {
1279 display
.set_viewport(new_clip
);
1282 var size
= UI
.screenSize();
1284 if (new_clip
&& size
) {
1285 // When clipping is enabled, the screen is limited to
1286 // the size of the browser window.
1287 display
.viewportChangeSize(size
.w
, size
.h
);
1291 // Handle special cases where clipping is forced on/off or locked
1292 enableDisableViewClip: function() {
1293 var resizeSetting
= document
.getElementById('noVNC_setting_resize');
1296 // Safari auto-hides the scrollbars which makes them
1297 // impossible to use in most cases
1298 UI
.setViewClip(true);
1299 document
.getElementById('noVNC_setting_clip').disabled
= true;
1300 } else if (resizeSetting
.value
=== 'downscale' || resizeSetting
.value
=== 'scale') {
1301 // Disable clipping if we are scaling
1302 UI
.setViewClip(false);
1303 document
.getElementById('noVNC_setting_clip').disabled
= true;
1304 } else if (document
.msFullscreenElement
) {
1305 // The browser is IE and we are in fullscreen mode.
1306 // - We need to force clipping while in fullscreen since
1307 // scrollbars doesn't work.
1308 var msg
= _("Forcing clipping mode since " +
1309 "scrollbars aren't supported " +
1310 "by IE in fullscreen");
1313 UI
.rememberedClipSetting
= UI
.getSetting('clip');
1314 UI
.setViewClip(true);
1315 document
.getElementById('noVNC_setting_clip').disabled
= true;
1316 } else if (document
.body
.msRequestFullscreen
&&
1317 UI
.rememberedClipSetting
!== null) {
1318 // Restore view clip to what it was before fullscreen on IE
1319 UI
.setViewClip(UI
.rememberedClipSetting
);
1320 document
.getElementById('noVNC_setting_clip').disabled
=
1321 UI
.connected
|| Util
.isTouchDevice
;
1323 document
.getElementById('noVNC_setting_clip').disabled
=
1324 UI
.connected
|| Util
.isTouchDevice
;
1325 if (Util
.isTouchDevice
) {
1326 UI
.setViewClip(true);
1337 toggleViewDrag: function() {
1338 if (!UI
.rfb
) return;
1340 var drag
= UI
.rfb
.get_viewportDrag();
1341 UI
.setViewDrag(!drag
);
1344 // Set the view drag mode which moves the viewport on mouse drags
1345 setViewDrag: function(drag
) {
1346 if (!UI
.rfb
) return;
1348 UI
.rfb
.set_viewportDrag(drag
);
1350 UI
.updateViewDrag();
1353 updateViewDrag: function() {
1354 var clipping
= false;
1356 if (!UI
.connected
) return;
1358 // Check if viewport drag is possible. It is only possible
1359 // if the remote display is clipping the client display.
1360 if (UI
.rfb
.get_display().get_viewport() &&
1361 UI
.rfb
.get_display().clippingDisplay()) {
1365 var viewDragButton
= document
.getElementById('noVNC_view_drag_button');
1368 UI
.rfb
.get_viewportDrag()) {
1369 // The size of the remote display is the same or smaller
1370 // than the client display. Make sure viewport drag isn't
1371 // active when it can't be used.
1372 UI
.rfb
.set_viewportDrag(false);
1375 if (UI
.rfb
.get_viewportDrag()) {
1376 viewDragButton
.classList
.add("noVNC_selected");
1378 viewDragButton
.classList
.remove("noVNC_selected");
1381 // Different behaviour for touch vs non-touch
1382 // The button is disabled instead of hidden on touch devices
1383 if (Util
.isTouchDevice
) {
1384 viewDragButton
.classList
.remove("noVNC_hidden");
1387 viewDragButton
.disabled
= false;
1389 viewDragButton
.disabled
= true;
1392 viewDragButton
.disabled
= false;
1395 viewDragButton
.classList
.remove("noVNC_hidden");
1397 viewDragButton
.classList
.add("noVNC_hidden");
1408 showVirtualKeyboard: function() {
1409 if (!Util
.isTouchDevice
) return;
1411 var input
= document
.getElementById('noVNC_keyboardinput');
1413 if (document
.activeElement
== input
) return;
1418 var l
= input
.value
.length
;
1419 // Move the caret to the end
1420 input
.setSelectionRange(l
, l
);
1421 } catch (err
) {} // setSelectionRange is undefined in Google Chrome
1424 hideVirtualKeyboard: function() {
1425 if (!Util
.isTouchDevice
) return;
1427 var input
= document
.getElementById('noVNC_keyboardinput');
1429 if (document
.activeElement
!= input
) return;
1434 toggleVirtualKeyboard: function () {
1435 if (document
.getElementById('noVNC_keyboard_button')
1436 .classList
.contains("noVNC_selected")) {
1437 UI
.hideVirtualKeyboard();
1439 UI
.showVirtualKeyboard();
1443 onfocusVirtualKeyboard: function(event
) {
1444 document
.getElementById('noVNC_keyboard_button')
1445 .classList
.add("noVNC_selected");
1448 onblurVirtualKeyboard: function(event
) {
1449 document
.getElementById('noVNC_keyboard_button')
1450 .classList
.remove("noVNC_selected");
1453 keepVirtualKeyboard: function(event
) {
1454 var input
= document
.getElementById('noVNC_keyboardinput');
1456 // Only prevent focus change if the virtual keyboard is active
1457 if (document
.activeElement
!= input
) {
1461 // Allow clicking on links
1462 if (event
.target
.tagName
=== "A") {
1466 // And form elements, except standard noVNC buttons
1467 if ((event
.target
.form
!== undefined) &&
1468 !event
.target
.classList
.contains("noVNC_button")) {
1472 event
.preventDefault();
1475 keyboardinputReset: function() {
1476 var kbi
= document
.getElementById('noVNC_keyboardinput');
1477 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
1478 UI
.lastKeyboardinput
= kbi
.value
;
1481 // When normal keyboard events are left uncought, use the input events from
1482 // the keyboardinput element instead and generate the corresponding key events.
1483 // This code is required since some browsers on Android are inconsistent in
1484 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1485 keyInput: function(event
) {
1487 if (!UI
.rfb
) return;
1489 var newValue
= event
.target
.value
;
1491 if (!UI
.lastKeyboardinput
) {
1492 UI
.keyboardinputReset();
1494 var oldValue
= UI
.lastKeyboardinput
;
1498 // Try to check caret position since whitespace at the end
1499 // will not be considered by value.length in some browsers
1500 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
1502 // selectionStart is undefined in Google Chrome
1503 newLen
= newValue
.length
;
1505 var oldLen
= oldValue
.length
;
1508 var inputs
= newLen
- oldLen
;
1510 backspaces
= -inputs
;
1515 // Compare the old string with the new to account for
1516 // text-corrections or other input that modify existing text
1518 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
1519 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
1520 inputs
= newLen
- i
;
1521 backspaces
= oldLen
- i
;
1526 // Send the key events
1527 for (i
= 0; i
< backspaces
; i
++) {
1528 UI
.rfb
.sendKey(KeyTable
.XK_BackSpace
);
1530 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1531 UI
.rfb
.sendKey(keysyms
.fromUnicode(newValue
.charCodeAt(i
)).keysym
);
1534 // Control the text content length in the keyboardinput element
1535 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1536 UI
.keyboardinputReset();
1537 } else if (newLen
< 1) {
1538 // There always have to be some text in the keyboardinput
1539 // element with which backspace can interact.
1540 UI
.keyboardinputReset();
1541 // This sometimes causes the keyboard to disappear for a second
1542 // but it is required for the android keyboard to recognize that
1543 // text has been added to the field
1544 event
.target
.blur();
1545 // This has to be ran outside of the input handler in order to work
1546 setTimeout(event
.target
.focus
.bind(event
.target
), 0);
1548 UI
.lastKeyboardinput
= newValue
;
1558 openExtraKeys: function() {
1559 UI
.closeAllPanels();
1560 UI
.openControlbar();
1562 document
.getElementById('noVNC_modifiers')
1563 .classList
.add("noVNC_open");
1564 document
.getElementById('noVNC_toggle_extra_keys_button')
1565 .classList
.add("noVNC_selected");
1568 closeExtraKeys: function() {
1569 document
.getElementById('noVNC_modifiers')
1570 .classList
.remove("noVNC_open");
1571 document
.getElementById('noVNC_toggle_extra_keys_button')
1572 .classList
.remove("noVNC_selected");
1575 toggleExtraKeys: function() {
1576 if(document
.getElementById('noVNC_modifiers')
1577 .classList
.contains("noVNC_open")) {
1578 UI
.closeExtraKeys();
1584 sendEsc: function() {
1585 UI
.rfb
.sendKey(KeyTable
.XK_Escape
);
1588 sendTab: function() {
1589 UI
.rfb
.sendKey(KeyTable
.XK_Tab
);
1592 toggleCtrl: function() {
1593 var btn
= document
.getElementById('noVNC_toggle_ctrl_button');
1594 if (btn
.classList
.contains("noVNC_selected")) {
1595 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, false);
1596 btn
.classList
.remove("noVNC_selected");
1598 UI
.rfb
.sendKey(KeyTable
.XK_Control_L
, true);
1599 btn
.classList
.add("noVNC_selected");
1603 toggleAlt: function() {
1604 var btn
= document
.getElementById('noVNC_toggle_alt_button');
1605 if (btn
.classList
.contains("noVNC_selected")) {
1606 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, false);
1607 btn
.classList
.remove("noVNC_selected");
1609 UI
.rfb
.sendKey(KeyTable
.XK_Alt_L
, true);
1610 btn
.classList
.add("noVNC_selected");
1614 sendCtrlAltDel: function() {
1615 UI
.rfb
.sendCtrlAltDel();
1624 setMouseButton: function(num
) {
1625 var view_only
= UI
.rfb
.get_view_only();
1626 if (UI
.rfb
&& !view_only
) {
1627 UI
.rfb
.get_mouse().set_touchButton(num
);
1630 var blist
= [0, 1,2,4];
1631 for (var b
= 0; b
< blist
.length
; b
++) {
1632 var button
= document
.getElementById('noVNC_mouse_button' +
1634 if (blist
[b
] === num
&& !view_only
) {
1635 button
.classList
.remove("noVNC_hidden");
1637 button
.classList
.add("noVNC_hidden");
1642 displayBlur: function() {
1643 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1644 UI
.rfb
.get_keyboard().set_focused(false);
1645 UI
.rfb
.get_mouse().set_focused(false);
1649 displayFocus: function() {
1650 if (UI
.rfb
&& !UI
.rfb
.get_view_only()) {
1651 UI
.rfb
.get_keyboard().set_focused(true);
1652 UI
.rfb
.get_mouse().set_focused(true);
1656 updateSessionSize: function(rfb
, width
, height
) {
1657 UI
.updateViewClip();
1658 UI
.updateViewDrag();
1661 updateDesktopName: function(rfb
, name
) {
1662 UI
.desktopName
= name
;
1663 // Display the desktop name in the document title
1664 document
.title
= name
+ " - noVNC";
1667 bell: function(rfb
) {
1668 if (WebUtil
.getConfigVar('bell', 'on') === 'on') {
1669 document
.getElementById('noVNC_bell').play();
1673 //Helper to add options to dropdown.
1674 addOption: function(selectbox
, text
, value
) {
1675 var optn
= document
.createElement("OPTION");
1678 selectbox
.options
.add(optn
);
1687 /* [module] UI.load(); */
1690 /* [module] export default UI; */