vadimpronin / guacamole-lite

Node.js library for creating Guacamole-compatible servers. Guacamole is a RDP/VNC/SSH/Telnet client for HTML5 browsers.
Apache License 2.0
250 stars 78 forks source link

About size of screen #14

Closed Dshufeng closed 6 years ago

Dshufeng commented 6 years ago

Hi: When I try to resize the picture, but it not works. My params is ws://192.168.1.115:8081/?token=token&width=1080&height=1920&dpi=32. I can see the picture but can't resize it. thank you.

vadimpronin commented 6 years ago

Do you see the picture of the same size you requested in your parameters? I mean when you request &width=1080&height=1920 do you see the picture 1080x1920 or of a different size?

Dshufeng commented 6 years ago

The picture is Default size when I change any params . And I use VNC protocol, is that the reason ?

vadimpronin commented 6 years ago

Looks like it's a limitation of VNC protocol. Here's one of the answers I found in another group:

Unfortunately, the VNC protocol itself does not define any mechanism for the connecting client to indicate the desired screen size. The size of the display is dictated entirely by the VNC server, and while Guacamole always receives the size of your browser window when you connect (and updated sizes if you resize the window), there is no way for it to communicate that size to the VNC server. The best you can achieve is to manually adjust the display by using the "xrandr" command within the VNC session after you connect.

Dshufeng commented 6 years ago

Oh.Thank you. It looks like I need to find other ways to solve it.

ptorrent commented 4 years ago

You can correct this by using scale on client interface

stormeyes commented 3 years ago

Three years pass and vnc still not support it.... anyone knows how to solve this problem?

ptorrent commented 3 years ago

merry christmas

var client  = client = new Guacamole.Client(new Guacamole.WebSocketTunnel("/guacamole/tunnel"));
$wrapper =client.getDisplay().getElement()

function initialize(){
var scale  = 1
var pixel_density = window.devicePixelRatio || 1;
var optimal_dpi = pixel_density * 96;
var optimal_width  = document.body.clientWidth //* pixel_density;
var optimal_height = document.body.clientHeight// * pixel_density;
if(!optimal_width){
    //case when size == 0 (wrapper not visible)
    return setTimeout(function(){
        initialize(comm)
    },1000)
}

$wrapper.style.position     = 'absolute'
$wrapper.style.left         = '50%'
$wrapper.style.top          = '50%'
$wrapper.style.transform    = 'translate(-50%,-50%)';
client.connect(encodeURI('token={{token}}&width='+optimal_width+'&height='+optimal_height+'&dpi='+optimal_dpi))
client.onstatechange = function(state){
    var STATE_IDLE          = 0;
    var STATE_CONNECTING    = 1;
    var STATE_WAITING       = 2;
    var STATE_CONNECTED     = 3;
    var STATE_DISCONNECTING = 4;
    var STATE_DISCONNECTED  = 5;
    if(state == 3){
        scale   = Math.min(optimal_height / $wrapper.clientHeight, optimal_width / $wrapper.clientWidth)

        $wrapper.style.transform = 'translate(-50%,-50%) scale('+scale+')'
    }
}
var touch = new Guacamole.Mouse.Touchscreen(client.getDisplay().getElement()); // or Guacamole.Touchscreen
var mouse = new Guacamole.Mouse(client.getDisplay().getElement());
    mouse.onmousedown = mouse.onmouseup = touch.onmousedown = touch.onmouseup  =  function(mouseState){
    console.log('mouseState',mouseState)
        client.sendMouseState(mouseState);
    }
    touch.onmousemove = mouse.onmousemove =  function(mouseState) {
        height  = $wrapper.clientHeight  
        width   = $wrapper.clientWidth 
        scale   = scale == Infinity ? 1 : scale 
        mouseState.x /= scale 
        mouseState.y /= scale 
        mouseState.x += width / 2
        mouseState.y += height / 2
        client.sendMouseState(mouseState);
    };
    // Keyboard
    var keyboard = new Guacamole.Keyboard(document);

    keyboard.onkeydown = function (keysym) {
        client.sendKeyEvent(1, keysym);
    };

    keyboard.onkeyup = function (keysym) {
        client.sendKeyEvent(0, keysym);
    };
}
stormeyes commented 3 years ago

@ptorrent thank u :)