mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-10 07:01:21 +00:00
GUAC-867: Add periodic keep-alive ping to ensure the session does not perish while a connection is active.
This commit is contained in:
@@ -86,6 +86,17 @@
|
||||
<url-pattern>/logout</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Session Keep-Alive Servlet -->
|
||||
<servlet>
|
||||
<description>Session keep-alive servlet.</description>
|
||||
<servlet-name>SessionKeepAlive</servlet-name>
|
||||
<servlet-class>org.glyptodon.guacamole.net.basic.SessionKeepAlive</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>SessionKeepAlive</servlet-name>
|
||||
<url-pattern>/keep-alive</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Clipboard State Servlet -->
|
||||
<servlet>
|
||||
<description>Clipboard state servlet.</description>
|
||||
|
@@ -195,10 +195,11 @@ GuacUI.Client = {
|
||||
},
|
||||
|
||||
/* Constants */
|
||||
|
||||
"KEYBOARD_AUTO_RESIZE_INTERVAL" : 30, /* milliseconds */
|
||||
"RECONNECT_PERIOD" : 15, /* seconds */
|
||||
"TEXT_INPUT_PADDING" : 128, /* characters */
|
||||
|
||||
"KEEP_ALIVE_INTERVAL" : 60000, /* milliseconds */
|
||||
"KEYBOARD_AUTO_RESIZE_INTERVAL" : 30, /* milliseconds */
|
||||
"RECONNECT_PERIOD" : 15, /* seconds */
|
||||
"TEXT_INPUT_PADDING" : 128, /* characters */
|
||||
"TEXT_INPUT_PADDING_CODEPOINT" : 0x200B,
|
||||
|
||||
/* Main application area */
|
||||
@@ -1014,6 +1015,11 @@ GuacUI.Client.connect = function() {
|
||||
connect_string += "&video=" + encodeURIComponent(mimetype);
|
||||
});
|
||||
|
||||
// Ping server every 10 seconds
|
||||
var session_keep_alive = window.setInterval(function _session_keep_alive() {
|
||||
GuacamoleService.KeepAlive.ping();
|
||||
}, GuacUI.Client.KEEP_ALIVE_INTERVAL);
|
||||
|
||||
// Show connection errors from tunnel
|
||||
tunnel.onerror = function(status) {
|
||||
var message = GuacUI.Client.tunnel_errors[status.code] || GuacUI.Client.tunnel_errors.DEFAULT;
|
||||
@@ -1021,10 +1027,20 @@ GuacUI.Client.connect = function() {
|
||||
GuacUI.Client.tunnel_auto_reconnect[status.code] && GuacUI.Client.RECONNECT_PERIOD);
|
||||
};
|
||||
|
||||
// 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.");
|
||||
|
||||
// Handle disconnect
|
||||
if (state === Guacamole.Tunnel.State.CLOSED) {
|
||||
|
||||
// No need for a keep-alive ping if the tunnel is closed
|
||||
window.clearInterval(session_keep_alive);
|
||||
|
||||
// Notify of disconnections (if not already notified of something else)
|
||||
if (!GuacUI.Client.visibleStatus)
|
||||
GuacUI.Client.showStatus("Disconnected",
|
||||
"You have been disconnected. Reload the page to reconnect.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Connect
|
||||
|
@@ -1438,3 +1438,26 @@ GuacamoleService.Clipboard = {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Collection of service functions which deal with the session keep-alive. Each
|
||||
* function makes an explicit HTTP query to the server. In the case of the
|
||||
* keep-alive ping, no response is expected, and any received response is
|
||||
* ignored.
|
||||
*/
|
||||
GuacamoleService.KeepAlive = {
|
||||
|
||||
"ping" : function(parameters) {
|
||||
|
||||
// Construct request URL
|
||||
var ping_url = "keep-alive";
|
||||
if (parameters) ping_url += "?" + parameters;
|
||||
|
||||
// Send keep-alive "ping"
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", ping_url, true);
|
||||
xhr.send(null);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user