From e35f3bbd6341ec14396100b0bb0651ff7aa9334e Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Sat, 25 Dec 2021 22:24:09 -0500 Subject: [PATCH] GUACAMOLE-1402: Expose Client state enum values. --- .../src/main/webapp/modules/Client.js | 83 ++++++++++++++----- 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Client.js b/guacamole-common-js/src/main/webapp/modules/Client.js index 866714162..f3ac684d5 100644 --- a/guacamole-common-js/src/main/webapp/modules/Client.js +++ b/guacamole-common-js/src/main/webapp/modules/Client.js @@ -32,14 +32,7 @@ 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; @@ -132,8 +125,8 @@ Guacamole.Client = function(tunnel) { } function isConnected() { - return currentState == STATE_CONNECTED - || currentState == STATE_WAITING; + return currentState == Guacamole.Client.State.CONNECTED + || currentState == Guacamole.Client.State.WAITING; } /** @@ -1547,8 +1540,8 @@ Guacamole.Client = function(tunnel) { }); // 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) @@ -1653,10 +1646,10 @@ Guacamole.Client = function(tunnel) { 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) @@ -1665,7 +1658,7 @@ Guacamole.Client = function(tunnel) { // Send disconnect message and disconnect tunnel.sendMessage("disconnect"); tunnel.disconnect(); - setState(STATE_DISCONNECTED); + setState(Guacamole.Client.State.DISCONNECTED); } @@ -1684,13 +1677,13 @@ Guacamole.Client = function(tunnel) { */ this.connect = function(data) { - setState(STATE_CONNECTING); + setState(Guacamole.Client.State.CONNECTING); try { tunnel.connect(data); } catch (status) { - setState(STATE_IDLE); + setState(Guacamole.Client.State.IDLE); throw status; } @@ -1699,11 +1692,63 @@ Guacamole.Client = function(tunnel) { tunnel.sendMessage("nop"); }, 5000); - setState(STATE_WAITING); + setState(Guacamole.Client.State.WAITING); }; }; +/** + * All possible Guacamole Client states. + * + * @type {!Object.} + */ +Guacamole.Client.State = { + + /** + * The client is idle, with no active connection. + * + * @type number + */ + "IDLE" : 0, + + /** + * The client is in the process of establishing a connection. + * + * @type {!number} + */ + "CONNECTING" : 1, + + /** + * The client is waiting on further information or a remote server to + * establish the connection. + * + * @type {!number} + */ + "WAITING" : 2, + + /** + * The client is actively connected to a remote server. + * + * @type {!number} + */ + "CONNECTED" : 3, + + /** + * The client is in the process of disconnecting from the remote server. + * + * @type {!number} + */ + "DISCONNECTING" : 4, + + /** + * The client has completed the connection and is no longer connected. + * + * @type {!number} + */ + "DISCONNECTED" : 5 + +}; + /** * Map of all Guacamole binary raster operations to transfer functions. *