<link rel="icon" sizes="144x144" type="image/png" href="app/images/icons/novnc-144x144.png">
<link rel="icon" sizes="152x152" type="image/png" href="app/images/icons/novnc-152x152.png">
<link rel="icon" sizes="192x192" type="image/png" href="app/images/icons/novnc-192x192.png">
+ <!-- Firefox currently mishandles SVG, see #1419039
<link rel="icon" sizes="any" type="image/svg+xml" href="app/images/icons/novnc-icon.svg">
+ -->
<!-- Repeated last so that legacy handling will pick this -->
<link rel="icon" sizes="16x16" type="image/png" href="app/images/icons/novnc-16x16.png">
import RFB from './core/rfb.js';
var rfb;
- var resizeTimeout;
var desktopName;
- function UIresize() {
- if (WebUtil.getConfigVar('resize', false)) {
- var innerW = window.innerWidth;
- var innerH = window.innerHeight;
- var controlbarH = document.getElementById('noVNC_status_bar').offsetHeight;
- if (innerW !== undefined && innerH !== undefined)
- rfb.requestDesktopSize(innerW, innerH - controlbarH);
- }
- }
- function FBUComplete(rfb, fbu) {
- UIresize();
- rfb.set_onFBUComplete(function() { });
+ function updateDesktopName(e) {
+ desktopName = e.detail.name;
}
- function updateDesktopName(rfb, name) {
- desktopName = name;
- }
- function passwordRequired(rfb, msg) {
- if (typeof msg === 'undefined') {
- msg = 'Password Required: ';
- }
+ function credentials(e) {
var html;
var form = document.createElement('form');
- form.style = 'margin-bottom: 0px';
- form.innerHTML = '<label></label>'
- form.innerHTML += '<input type=password size=10 id="password_input" class="noVNC_status">';
+ form.innerHTML = '<label></label>';
+ form.innerHTML += '<input type=password size=10 id="password_input">';
form.onsubmit = setPassword;
// bypass status() because it sets text content
document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
document.getElementById('noVNC_status').innerHTML = '';
document.getElementById('noVNC_status').appendChild(form);
- document.getElementById('noVNC_status').querySelector('label').textContent = msg;
+ document.getElementById('noVNC_status').querySelector('label').textContent = 'Password Required: ';
}
function setPassword() {
- rfb.sendPassword(document.getElementById('password_input').value);
+ rfb.sendCredentials({ password: document.getElementById('password_input').value });
return false;
}
function sendCtrlAltDel() {
rfb.sendCtrlAltDel();
return false;
}
- function xvpShutdown() {
- rfb.xvpShutdown();
+ function machineShutdown() {
+ rfb.machineShutdown();
return false;
}
- function xvpReboot() {
- rfb.xvpReboot();
+ function machineReboot() {
+ rfb.machineReboot();
return false;
}
- function xvpReset() {
- rfb.xvpReset();
+ function machineReset() {
+ rfb.machineReset();
return false;
}
function status(text, level) {
default:
level = "warn";
}
- document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_" + level);
+ document.getElementById('noVNC_status_bar').className = "noVNC_status_" + level;
document.getElementById('noVNC_status').textContent = text;
}
- function updateState(rfb, state, oldstate) {
- var cad = document.getElementById('sendCtrlAltDelButton');
- switch (state) {
- case 'connecting':
- status("Connecting", "normal");
- break;
- case 'connected':
- if (rfb && rfb.get_encrypt()) {
- status("Connected (encrypted) to " +
- desktopName, "normal");
- } else {
- status("Connected (unencrypted) to " +
- desktopName, "normal");
- }
- break;
- case 'disconnecting':
- status("Disconnecting", "normal");
- break;
- case 'disconnected':
- status("Disconnected", "normal");
- break;
- default:
- status(state, "warn");
- break;
- }
- if (state === 'connected') {
- cad.disabled = false;
+ function connected(e) {
+ document.getElementById('sendCtrlAltDelButton').disabled = false;
+ if (WebUtil.getConfigVar('encrypt',
+ (window.location.protocol === "https:"))) {
+ status("Connected (encrypted) to " + desktopName, "normal");
} else {
- cad.disabled = true;
- xvpInit(0);
+ status("Connected (unencrypted) to " + desktopName, "normal");
}
-
}
- function disconnected(rfb, reason) {
- if (typeof(reason) !== 'undefined') {
- status(reason, "error");
+
+ function disconnected(e) {
+ document.getElementById('sendCtrlAltDelButton').disabled = true;
+ updatePowerButtons();
+ if (e.detail.clean) {
+ status("Disconnected", "normal");
+ } else {
+ status("Something went wrong, connection is closed", "error");
}
}
- function notification(rfb, msg, level, options) {
- status(msg, level);
- }
-
- window.onresize = function () {
- // When the window has been resized, wait until the size remains
- // the same for 0.5 seconds before sending the request for changing
- // the resolution of the session
- clearTimeout(resizeTimeout);
- resizeTimeout = setTimeout(function(){
- UIresize();
- }, 500);
- };
- function xvpInit(ver) {
- var xvpbuttons;
- xvpbuttons = document.getElementById('noVNC_xvp_buttons');
- if (ver >= 1) {
- xvpbuttons.style.display = 'inline';
+ function updatePowerButtons() {
+ var powerbuttons;
+ powerbuttons = document.getElementById('noVNC_power_buttons');
+ if (rfb.capabilities.power) {
+ powerbuttons.className= "noVNC_shown";
} else {
- xvpbuttons.style.display = 'none';
+ powerbuttons.className = "noVNC_hidden";
}
}
- document.getElementById('sendCtrlAltDelButton').style.display = "inline";
document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
- document.getElementById('xvpShutdownButton').onclick = xvpShutdown;
- document.getElementById('xvpRebootButton').onclick = xvpReboot;
- document.getElementById('xvpResetButton').onclick = xvpReset;
+ document.getElementById('machineShutdownButton').onclick = machineShutdown;
+ document.getElementById('machineRebootButton').onclick = machineReboot;
+ document.getElementById('machineResetButton').onclick = machineReset;
WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
document.title = WebUtil.getConfigVar('title', 'noVNC');
(function() {
+ status("Connecting", "normal");
+
if ((!host) || (!port)) {
status('Must specify host and port in URL', 'error');
}
- try {
- rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
- 'encrypt': WebUtil.getConfigVar('encrypt',
- (window.location.protocol === "https:")),
- 'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
- 'local_cursor': WebUtil.getConfigVar('cursor', true),
- 'shared': WebUtil.getConfigVar('shared', true),
- 'view_only': WebUtil.getConfigVar('view_only', false),
- 'onNotification': notification,
- 'onUpdateState': updateState,
- 'onDisconnected': disconnected,
- 'onXvpInit': xvpInit,
- 'onPasswordRequired': passwordRequired,
- 'onFBUComplete': FBUComplete,
- 'onDesktopName': updateDesktopName});
- } catch (exc) {
- status('Unable to create RFB client -- ' + exc, 'error');
- return; // don't continue trying to connect
+ var url;
+
+ if (WebUtil.getConfigVar('encrypt',
+ (window.location.protocol === "https:"))) {
+ url = 'wss';
+ } else {
+ url = 'ws';
}
- rfb.connect(host, port, password, path);
+ url += '://' + host;
+ if(port) {
+ url += ':' + port;
+ }
+ url += '/' + path;
+
+ rfb = new RFB(document.body, url,
+ { repeaterID: WebUtil.getConfigVar('repeaterID', ''),
+ shared: WebUtil.getConfigVar('shared', true),
+ credentials: { password: password } });
+ rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
+ rfb.addEventListener("connect", connected);
+ rfb.addEventListener("disconnect", disconnected);
+ rfb.addEventListener("capabilities", function () { updatePowerButtons(); });
+ rfb.addEventListener("credentialsrequired", credentials);
+ rfb.addEventListener("desktopname", updateDesktopName);
+ rfb.scaleViewport = WebUtil.getConfigVar('scale', false);
+ rfb.resizeSession = WebUtil.getConfigVar('resize', false);
})();
</script>
</head>
<body>
- <div id="noVNC_status_bar" style="margin-top: 0px;">
- <table border=0 width="100%"><tr>
- <td><div id="noVNC_status" style="position: relative; height: auto;">
- Loading
- </div></td>
- <td width="1%"><div id="noVNC_buttons">
- <input type=button value="Send CtrlAltDel"
- id="sendCtrlAltDelButton">
- <span id="noVNC_xvp_buttons">
- <input type=button value="Shutdown"
- id="xvpShutdownButton">
- <input type=button value="Reboot"
- id="xvpRebootButton">
- <input type=button value="Reset"
- id="xvpResetButton">
- </span>
- </div></td>
- </tr></table>
+ <div id="noVNC_status_bar">
+ <div id="noVNC_left_dummy_elem"></div>
+ <div id="noVNC_status">Loading</div>
+ <div id="noVNC_buttons">
+ <input type=button value="Send CtrlAltDel"
+ id="sendCtrlAltDelButton" class="noVNC_shown">
+ <span id="noVNC_power_buttons" class="noVNC_hidden">
+ <input type=button value="Shutdown"
+ id="machineShutdownButton">
+ <input type=button value="Reboot"
+ id="machineRebootButton">
+ <input type=button value="Reset"
+ id="machineResetButton">
+ </span>
+ </div>
</div>
- <canvas id="noVNC_canvas" width="0" height="0">
- Canvas not supported.
- </canvas>
-
</body>
</html>