cedrozor / myrtille

A native HTML4 / HTML5 Remote Desktop Protocol and SSH client
https://www.myrtille.io
Apache License 2.0
1.79k stars 375 forks source link

Auto Scaling issue #291

Open flamingwitch opened 3 years ago

flamingwitch commented 3 years ago

Hi,

I use the connection service to create a connectionid for launching applications remote app style and construct a URL that is hosted in an iframe to display the remote app. I have scaling on (config.js), websockets are installed and functional on the server where myrtille is hosted. When my window and iframe are resized I can trace through that a message does get sent to resize through the myrtille code (websockets.js) but resizing just doesn't seem to happen.

If I enable the toolbar and click Scale ON that works. I notice when I inspect the page that the startMyrtille function call onload looks like the following when I load through my url:

startMyrtille( 'CONNECTING', getToggleCookie((parent != null && window.name != '' ? window.name + '_' : '') + 'stat'), getToggleCookie((parent != null && window.name != '' ? window.name + '_' : '') + 'debug'), getToggleCookie((parent != null && window.name != '' ? window.name + '_' : '') + 'browser'), 'null', 1887, 969, 'RDP', false);

While when I toggle the Scale ON button in looks like: startMyrtille( 'CONNECTED', getToggleCookie((parent != null && window.name != '' ? window.name + '_' : '') + 'stat'), getToggleCookie((parent != null && window.name != '' ? window.name + '_' : '') + 'debug'), getToggleCookie((parent != null && window.name != '' ? window.name + '_' : '') + 'browser'), 'SCALE', 1887, 969, 'RDP', false);

Am I possibily missing a setting somewhere?

cedrozor commented 3 years ago

Hi, when you say that you have scaling on into config.js, did you changed the default config:

var defaultResize = browserResizeEnum.NONE; by var defaultResize = browserResizeEnum.SCALE;?

flamingwitch commented 3 years ago

yes defaultResize is set to SCALE

cedrozor commented 3 years ago

You mentioned that Myrtille runs in an iframe in the page. When you resize the browser, and thus the page, is the iframe also resized? in other words, do you have the iframe size relative to the page, as it's done here:

https://github.com/cedrozor/myrtille/blob/7393ace7c84dda2ddbc68005cd2e0b4561ed40af/Myrtille.Admin.Web/css/iframe.css#L41-L46

https://github.com/cedrozor/myrtille/blob/7393ace7c84dda2ddbc68005cd2e0b4561ed40af/Myrtille.Admin.Web/Default.aspx#L47-L48

https://github.com/cedrozor/myrtille/blob/7393ace7c84dda2ddbc68005cd2e0b4561ed40af/Myrtille.Admin.Web/Default.aspx.cs#L66-L87

flamingwitch commented 3 years ago

Yes the iframe itself does resize. I followed your example in the Admin.Web project as best as I could. I'm using .net core and tag helpers, but this is where I created the iframe tag. idString is the id and name on the iframe, model.uri is the properly formatted url like you have in your example with a CID generated by calling the connection service. The remoteappiframe class has width and height of 100%.

            //create iframe to hold remote session
           var idString = "remoteappframe1";
            output.TagName = "iframe";
            output.Attributes.SetAttribute("id", idString);
            output.Attributes.SetAttribute("name", idString);
            //get connection id from URI
            var uri = new Uri(model.Uri);
            var queryDictionary = System.Web.HttpUtility.ParseQueryString(uri.Query);
            var cid = queryDictionary["cid"];

            //add connection id cookie to preventing triggering new connection on reloads
            if (Request.Cookies[idString] == null)
            {
                var cookieHeader = new SetCookieHeaderValue(($"{idString}_cid"), cid)
                {
                    Path = "/"
                };
                Response.Headers[HeaderNames.SetCookie] = StringValues.Concat(Response.Headers[HeaderNames.SetCookie], cookieHeader.ToString());

                cookieHeader = new SetCookieHeaderValue(($"{idString}"), uri.GetLeftPart(UriPartial.Path))
                {
                    Path = "/"
                };
                Response.Headers[HeaderNames.SetCookie] = StringValues.Concat(Response.Headers[HeaderNames.SetCookie], cookieHeader.ToString());

                output.Attributes.SetAttribute("src", model.Uri);
            }
            else
            {
                output.Attributes.SetAttribute("src", $"{uri.GetLeftPart(UriPartial.Path)}?fid={idString}");
            }

            output.Attributes.Add("class", "remoteappiframe");
            output.Attributes.SetAttribute("frameBorder", 0);
            output.Attributes.SetAttribute("data-disconnecturl", $"{uri.GetLeftPart(UriPartial.Path)}api/Disconnection/Disconnect?connectionId={cid}");`

As I mentioned in my initial question scaling seems to work fine if I click the SCALE ON button on the toolbar, but scaling does not seem to be on by default, despite setting it in as default in config.js. I was hoping I was missing a setting somewhere else.

cedrozor commented 3 years ago

Thanks for the details. Did you tried with websockets disabled (HTML5 button OFF into the toolbar or websockets disabled into config.js). Indeed, I modified the websocket.js code into 2.9.2 to allow load-balancing over multiple websockets, the auto-scaling issue may be a side effect.

It will also be easier to track the xmlhttp traffic into the devtools (SendInputs.aspx requests) and check the differences between the scale button and the default value of scale into config.js.

flamingwitch commented 3 years ago

Sorry, I tried changing the config.js to use LONGPOLLING and I thought at first that it had worked, but apparently not. Seems like the same behaviour

flamingwitch commented 3 years ago

Hi again,

Just wanted to say I took it out of the iframe and everything works as expected. Seems to be something to do with the iframe, it doesn't seem to go from connecting to connected like it does outside of the iframe or when clicking on the Scale button in the toolbar. Maybe I'll just skip the iframe at this rate :)

cedrozor commented 3 years ago

Glad that you had it working! I will re-check the resize logic in the context of an iframe.