Skip to content

Commit

Permalink
Auto-resize fix for twitchintheshell#6
Browse files Browse the repository at this point in the history
This change should allow the VNC window to resize to the size of it's
parent div when ever the window is resized, or when the vnc window
itself is resized. Therefore, this fixes twitchintheshell#6.

Based off of
https://github.com/jakozaur/noVNC/blob/master/meteor/novnc.js#L56 since
it was the original code that resized the window (and I don't know
meteor or noVnc really well).

Signed-off-by: Colton Wolkins (Ogre) <[email protected]>
  • Loading branch information
TheTechmage committed Nov 6, 2015
1 parent 622dd3e commit 4ffc652
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions twitch-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@ var CommandLog = new Meteor.Collection("commandlog");
var Ad = new Meteor.Collection("ad");

if (Meteor.isClient) {

function vnc_resize(rfb, width, height) {

if(typeof width != 'undefined' && typeof height != 'undefined')
rfb.get_display().resize(width, height)
if(rfb === undefined)
rfb = NoVnc.rfb
var scale = 1;
var esize = {
width: document.getElementById("vnc").offsetWidth,
height: document.getElementById("vnc").offsetHeight
}
var ssize = {
width: rfb._fb_width,
height: rfb._fb_height,
real_width: rfb._fb_width * rfb.get_display().get_scale(),
real_height: rfb._fb_height * rfb.get_display().get_scale()
}
if(esize.width - ssize.width <= esize.height - ssize.height && ssize.height * esize.width/ssize.width < esize.height) {
scale = esize.width / ssize.width
}
else {
scale = esize.height / ssize.height
}
if (scale > 1) scale = 1.0;
rfb.get_display().set_scale(scale)
rfb.get_mouse().set_scale(scale)
NoVnc.size.set({width: ssize.width * scale, height: ssize.height * scale})
}
NoVnc.rfb.set_onFBResize(vnc_resize)
window.addEventListener("resize", vnc_resize)

Session.set("cpu", []);

Expand Down

0 comments on commit 4ffc652

Please sign in to comment.