mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-10-28 07:33:08 +00:00
GUAC-544: Implement reconnect via GuacUI.Client.connect() function. Can be called again to reinitialize the UI and reconnect.
This commit is contained in:
@@ -76,81 +76,7 @@
|
||||
// Start connect after control returns from onload (allow browser
|
||||
// to consider the page loaded).
|
||||
window.onload = function() {
|
||||
window.setTimeout(function() {
|
||||
|
||||
var tunnel;
|
||||
|
||||
// If WebSocket available, try to use it.
|
||||
if (window.WebSocket)
|
||||
tunnel = new Guacamole.ChainedTunnel(
|
||||
new Guacamole.WebSocketTunnel("websocket-tunnel"),
|
||||
new Guacamole.HTTPTunnel("tunnel")
|
||||
);
|
||||
|
||||
// If no WebSocket, then use HTTP.
|
||||
else
|
||||
tunnel = new Guacamole.HTTPTunnel("tunnel");
|
||||
|
||||
// Instantiate client
|
||||
var guac = new Guacamole.Client(tunnel);
|
||||
|
||||
// Add client to UI
|
||||
guac.getDisplay().className = "software-cursor";
|
||||
GuacUI.Client.display.appendChild(guac.getDisplay());
|
||||
|
||||
// Tie UI to client
|
||||
GuacUI.Client.attach(guac);
|
||||
|
||||
// Calculate optimal width/height for display
|
||||
var pixel_density = window.devicePixelRatio || 1;
|
||||
var optimal_dpi = pixel_density * 96;
|
||||
var optimal_width = window.innerWidth * pixel_density;
|
||||
var optimal_height = window.innerHeight * pixel_density;
|
||||
|
||||
// Scale width/height to be at least 600x600
|
||||
if (optimal_width < 600 || optimal_height < 600) {
|
||||
var scale = Math.max(600 / optimal_width, 600 / optimal_height);
|
||||
optimal_width = optimal_width * scale;
|
||||
optimal_height = optimal_height * scale;
|
||||
}
|
||||
|
||||
// Get entire query string, and pass to connect().
|
||||
// Normally, only the "id" parameter is required, but
|
||||
// all parameters should be preserved and passed on for
|
||||
// the sake of authentication.
|
||||
|
||||
var connect_string =
|
||||
window.location.search.substring(1)
|
||||
+ "&width=" + Math.floor(optimal_width)
|
||||
+ "&height=" + Math.floor(optimal_height)
|
||||
+ "&dpi=" + Math.floor(optimal_dpi);
|
||||
|
||||
// Add audio mimetypes to connect_string
|
||||
GuacUI.Audio.supported.forEach(function(mimetype) {
|
||||
connect_string += "&audio=" + encodeURIComponent(mimetype);
|
||||
});
|
||||
|
||||
// Add video mimetypes to connect_string
|
||||
GuacUI.Video.supported.forEach(function(mimetype) {
|
||||
connect_string += "&video=" + encodeURIComponent(mimetype);
|
||||
});
|
||||
|
||||
// Show connection errors from tunnel
|
||||
tunnel.onerror = function(status) {
|
||||
var message = GuacUI.Client.tunnel_errors[status.code] || GuacUI.Client.tunnel_errors.DEFAULT;
|
||||
GuacUI.Client.showError("Connection Error", message);
|
||||
};
|
||||
|
||||
// Notify of disconnections (if not already notified of something else)
|
||||
tunnel.onstatechange = function(state) {
|
||||
if (state === Guacamole.Tunnel.State.CLOSED && !GuacUI.Client.visibleStatus)
|
||||
GuacUI.Client.showStatus("Disconnected", "You have been disconnected. Reload the page to reconnect.");
|
||||
};
|
||||
|
||||
// Connect
|
||||
guac.connect(connect_string);
|
||||
|
||||
}, 0);
|
||||
window.setTimeout(GuacUI.Client.connect, 0);
|
||||
};
|
||||
|
||||
/* ]]> */ </script>
|
||||
|
||||
Reference in New Issue
Block a user