This is an automated email from the ASF dual-hosted git repository. mjumper pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/guacamole-client.git
commit c2f2defcba73ad7ad1e5c6608a3d7b91a11313c9 Merge: 1ea696888 9fe64a77b Author: Mike Jumper <[email protected]> AuthorDate: Sun Dec 11 13:23:06 2022 -0800 GUACAMOLE-1402: Merge proper API definitions of all possible client state values. .../src/main/webapp/modules/Client.js | 83 +++++++++++++++++----- .../frontend/src/app/client/types/ManagedClient.js | 14 ++-- 2 files changed, 71 insertions(+), 26 deletions(-) diff --cc guacamole-common-js/src/main/webapp/modules/Client.js index 2315ac306,f3ac684d5..815e9cddf --- a/guacamole-common-js/src/main/webapp/modules/Client.js +++ b/guacamole-common-js/src/main/webapp/modules/Client.js @@@ -32,46 -32,10 +32,39 @@@ Guacamole.Client = function(tunnel) var guac_client = this; - var STATE_IDLE = 0; - var STATE_CONNECTING = 1; - var STATE_WAITING = 2; - var STATE_CONNECTED = 3; - var STATE_DISCONNECTING = 4; - var STATE_DISCONNECTED = 5; - - var currentState = STATE_IDLE; + var currentState = Guacamole.Client.State.IDLE; var currentTimestamp = 0; - var pingInterval = null; + + /** + * The rough number of milliseconds to wait between sending keep-alive + * pings. This may vary depending on how frequently the browser allows + * timers to run, as well as how frequently the client receives messages + * from the server. + * + * @private + * @constant + * @type {!number} + */ + var KEEP_ALIVE_FREQUENCY = 5000; + + /** + * The current keep-alive ping timeout ID, if any. This will only be set + * upon connecting. + * + * @private + * @type {number} + */ + var keepAliveTimeout = null; + + /** + * The timestamp of the point in time that the last keep-live ping was + * sent, in milliseconds elapsed since midnight of January 1, 1970 UTC. + * + * @private + * @type {!number} + */ + var lastSentKeepAlive = 0; /** * Translation from Guacamole protocol line caps to Layer line caps. @@@ -1583,11 -1537,11 +1576,11 @@@ currentTimestamp = timestamp; } - }); + }, timestamp, frames); // If received first update, no longer waiting. - if (currentState === STATE_WAITING) - setState(STATE_CONNECTED); + if (currentState === Guacamole.Client.State.WAITING) + setState(Guacamole.Client.State.CONNECTED); // Call sync handler if defined if (guac_client.onsync) @@@ -1743,13 -1646,14 +1736,13 @@@ this.disconnect = function() { // Only attempt disconnection not disconnected. - if (currentState != STATE_DISCONNECTED - && currentState != STATE_DISCONNECTING) { + if (currentState != Guacamole.Client.State.DISCONNECTED + && currentState != Guacamole.Client.State.DISCONNECTING) { - setState(STATE_DISCONNECTING); + setState(Guacamole.Client.State.DISCONNECTING); - // Stop ping - if (pingInterval) - window.clearInterval(pingInterval); + // Stop sending keep-alive messages + stopKeepAlive(); // Send disconnect message and disconnect tunnel.sendMessage("disconnect"); @@@ -1783,11 -1687,12 +1776,11 @@@ throw status; } - // Ping every 5 seconds (ensure connection alive) - pingInterval = window.setInterval(function() { - tunnel.sendMessage("nop"); - }, 5000); + // Regularly send keep-alive ping to ensure the server knows we're + // still here, even if not active + scheduleKeepAlive(); - setState(STATE_WAITING); + setState(Guacamole.Client.State.WAITING); }; };
