Automatically ping every 5 seconds.

This commit is contained in:
Michael Jumper
2012-01-08 20:20:04 -08:00
parent b4ee710b6f
commit b4d135c3f1

View File

@@ -61,6 +61,9 @@ Guacamole.Client = function(display, tunnel) {
var currentState = STATE_IDLE; var currentState = STATE_IDLE;
var currentTimestamp = 0;
var pingInterval = null;
tunnel.onerror = function(message) { tunnel.onerror = function(message) {
if (guac_client.onerror) if (guac_client.onerror)
guac_client.onerror(message); guac_client.onerror(message);
@@ -400,8 +403,10 @@ Guacamole.Client = function(display, tunnel) {
layersToSync--; layersToSync--;
// Send sync response when layers are finished // Send sync response when layers are finished
if (layersToSync == 0) if (layersToSync == 0) {
tunnel.sendMessage("sync", timestamp); tunnel.sendMessage("sync", timestamp);
currentTimestamp = timestamp;
}
} }
@@ -418,8 +423,10 @@ Guacamole.Client = function(display, tunnel) {
// If all layers are ready, then we didn't install any hooks. // If all layers are ready, then we didn't install any hooks.
// Send sync message now, // Send sync message now,
if (layersToSync == 0) if (layersToSync == 0) {
tunnel.sendMessage("sync", timestamp); tunnel.sendMessage("sync", timestamp);
currentTimestamp = timestamp;
}
} }
@@ -442,9 +449,16 @@ Guacamole.Client = function(display, tunnel) {
&& currentState != STATE_DISCONNECTING) { && currentState != STATE_DISCONNECTING) {
setState(STATE_DISCONNECTING); setState(STATE_DISCONNECTING);
// Stop ping
if (pingInterval)
window.clearInterval(pingInterval);
// Send disconnect message and disconnect
tunnel.sendMessage("disconnect"); tunnel.sendMessage("disconnect");
tunnel.disconnect(); tunnel.disconnect();
setState(STATE_DISCONNECTED); setState(STATE_DISCONNECTED);
} }
}; };
@@ -461,6 +475,11 @@ Guacamole.Client = function(display, tunnel) {
throw e; throw e;
} }
// Ping every 5 seconds (ensure connection alive)
pingInterval = window.setInterval(function() {
tunnel.sendMessage("sync", currentTimestamp);
}, 5000);
setState(STATE_WAITING); setState(STATE_WAITING);
}; };