diff --git a/guacamole-common-js/src/main/webapp/modules/Client.js b/guacamole-common-js/src/main/webapp/modules/Client.js index 2315ac306..815e9cddf 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; @@ -161,8 +154,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; } /** @@ -1586,8 +1579,8 @@ Guacamole.Client = function(tunnel) { }, 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,10 +1736,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 sending keep-alive messages stopKeepAlive(); @@ -1754,7 +1747,7 @@ Guacamole.Client = function(tunnel) { // Send disconnect message and disconnect tunnel.sendMessage("disconnect"); tunnel.disconnect(); - setState(STATE_DISCONNECTED); + setState(Guacamole.Client.State.DISCONNECTED); } @@ -1773,13 +1766,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; } @@ -1787,11 +1780,63 @@ Guacamole.Client = function(tunnel) { // still here, even if not active scheduleKeepAlive(); - 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. * diff --git a/guacamole/src/main/frontend/src/app/client/types/ManagedClient.js b/guacamole/src/main/frontend/src/app/client/types/ManagedClient.js index fb7c8474e..bb21dca13 100644 --- a/guacamole/src/main/frontend/src/app/client/types/ManagedClient.js +++ b/guacamole/src/main/frontend/src/app/client/types/ManagedClient.js @@ -427,25 +427,25 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector', switch (clientState) { // Idle - case 0: + case Guacamole.Client.State.IDLE: ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.ConnectionState.IDLE); break; // Connecting - case 1: + case Guacamole.Client.State.CONNECTING: ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.ConnectionState.CONNECTING); break; // Connected + waiting - case 2: + case Guacamole.Client.State.WAITING: ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.ConnectionState.WAITING); break; // Connected - case 3: + case Guacamole.Client.State.CONNECTED: ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.ConnectionState.CONNECTED); @@ -461,9 +461,9 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector', ManagedClient.updateThumbnail(managedClient); break; - // Update history when disconnecting - case 4: // Disconnecting - case 5: // Disconnected + // Update history during disconnect phases + case Guacamole.Client.State.DISCONNECTING: + case Guacamole.Client.State.DISCONNECTED: ManagedClient.updateThumbnail(managedClient); break;