Move resize handling in to RFB object

Makes the API simpler and makes it easier for other frontends to
get this functionality.
This commit is contained in:
Pierre Ossman
2017-11-24 15:25:23 +01:00
parent 898cd32c07
commit 9b84f51685
11 changed files with 691 additions and 533 deletions

View File

@@ -80,24 +80,8 @@
import RFB from './core/rfb.js';
var rfb;
var doneInitialResize;
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 initialResize() {
if (doneInitialResize) return;
UIresize();
doneInitialResize = true;
}
function updateDesktopName(e) {
desktopName = e.detail.name;
}
@@ -150,7 +134,6 @@
function connected(e) {
document.getElementById('sendCtrlAltDelButton').disabled = false;
doneInitialResize = false;
if (WebUtil.getConfigVar('encrypt',
(window.location.protocol === "https:"))) {
status("Connected (encrypted) to " + desktopName, "normal");
@@ -169,16 +152,6 @@
}
}
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 updatePowerButtons() {
var powerbuttons;
powerbuttons = document.getElementById('noVNC_power_buttons');
@@ -247,16 +220,17 @@
}
url += '/' + path;
rfb = new RFB(document.getElementById('noVNC_canvas'), url,
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(); initialResize(); });
rfb.addEventListener("capabilities", function () { updatePowerButtons(); });
rfb.addEventListener("credentialsrequired", credentials);
rfb.addEventListener("desktopname", updateDesktopName);
rfb.resizeSession = WebUtil.getConfigVar('resize', false);
})();
</script>
</head>
@@ -278,9 +252,5 @@
</span>
</div>
</div>
<canvas id="noVNC_canvas" width="0" height="0">
Canvas not supported.
</canvas>
</body>
</html>