GUACAMOLE-1402: Merge proper API definitions of all possible client state values.

This commit is contained in:
Mike Jumper
2022-12-11 13:23:06 -08:00
committed by GitHub
2 changed files with 71 additions and 26 deletions

View File

@@ -32,14 +32,7 @@ Guacamole.Client = function(tunnel) {
var guac_client = this; var guac_client = this;
var STATE_IDLE = 0; var currentState = Guacamole.Client.State.IDLE;
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 currentTimestamp = 0; var currentTimestamp = 0;
@@ -161,8 +154,8 @@ Guacamole.Client = function(tunnel) {
} }
function isConnected() { function isConnected() {
return currentState == STATE_CONNECTED return currentState == Guacamole.Client.State.CONNECTED
|| currentState == STATE_WAITING; || currentState == Guacamole.Client.State.WAITING;
} }
/** /**
@@ -1586,8 +1579,8 @@ Guacamole.Client = function(tunnel) {
}, timestamp, frames); }, timestamp, frames);
// If received first update, no longer waiting. // If received first update, no longer waiting.
if (currentState === STATE_WAITING) if (currentState === Guacamole.Client.State.WAITING)
setState(STATE_CONNECTED); setState(Guacamole.Client.State.CONNECTED);
// Call sync handler if defined // Call sync handler if defined
if (guac_client.onsync) if (guac_client.onsync)
@@ -1743,10 +1736,10 @@ Guacamole.Client = function(tunnel) {
this.disconnect = function() { this.disconnect = function() {
// Only attempt disconnection not disconnected. // Only attempt disconnection not disconnected.
if (currentState != STATE_DISCONNECTED if (currentState != Guacamole.Client.State.DISCONNECTED
&& currentState != STATE_DISCONNECTING) { && currentState != Guacamole.Client.State.DISCONNECTING) {
setState(STATE_DISCONNECTING); setState(Guacamole.Client.State.DISCONNECTING);
// Stop sending keep-alive messages // Stop sending keep-alive messages
stopKeepAlive(); stopKeepAlive();
@@ -1754,7 +1747,7 @@ Guacamole.Client = function(tunnel) {
// Send disconnect message and disconnect // Send disconnect message and disconnect
tunnel.sendMessage("disconnect"); tunnel.sendMessage("disconnect");
tunnel.disconnect(); tunnel.disconnect();
setState(STATE_DISCONNECTED); setState(Guacamole.Client.State.DISCONNECTED);
} }
@@ -1773,13 +1766,13 @@ Guacamole.Client = function(tunnel) {
*/ */
this.connect = function(data) { this.connect = function(data) {
setState(STATE_CONNECTING); setState(Guacamole.Client.State.CONNECTING);
try { try {
tunnel.connect(data); tunnel.connect(data);
} }
catch (status) { catch (status) {
setState(STATE_IDLE); setState(Guacamole.Client.State.IDLE);
throw status; throw status;
} }
@@ -1787,11 +1780,63 @@ Guacamole.Client = function(tunnel) {
// still here, even if not active // still here, even if not active
scheduleKeepAlive(); scheduleKeepAlive();
setState(STATE_WAITING); setState(Guacamole.Client.State.WAITING);
}; };
}; };
/**
* All possible Guacamole Client states.
*
* @type {!Object.<string, number>}
*/
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. * Map of all Guacamole binary raster operations to transfer functions.
* *

View File

@@ -427,25 +427,25 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
switch (clientState) { switch (clientState) {
// Idle // Idle
case 0: case Guacamole.Client.State.IDLE:
ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.setConnectionState(managedClient.clientState,
ManagedClientState.ConnectionState.IDLE); ManagedClientState.ConnectionState.IDLE);
break; break;
// Connecting // Connecting
case 1: case Guacamole.Client.State.CONNECTING:
ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.setConnectionState(managedClient.clientState,
ManagedClientState.ConnectionState.CONNECTING); ManagedClientState.ConnectionState.CONNECTING);
break; break;
// Connected + waiting // Connected + waiting
case 2: case Guacamole.Client.State.WAITING:
ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.setConnectionState(managedClient.clientState,
ManagedClientState.ConnectionState.WAITING); ManagedClientState.ConnectionState.WAITING);
break; break;
// Connected // Connected
case 3: case Guacamole.Client.State.CONNECTED:
ManagedClientState.setConnectionState(managedClient.clientState, ManagedClientState.setConnectionState(managedClient.clientState,
ManagedClientState.ConnectionState.CONNECTED); ManagedClientState.ConnectionState.CONNECTED);
@@ -461,9 +461,9 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
ManagedClient.updateThumbnail(managedClient); ManagedClient.updateThumbnail(managedClient);
break; break;
// Update history when disconnecting // Update history during disconnect phases
case 4: // Disconnecting case Guacamole.Client.State.DISCONNECTING:
case 5: // Disconnected case Guacamole.Client.State.DISCONNECTED:
ManagedClient.updateThumbnail(managedClient); ManagedClient.updateThumbnail(managedClient);
break; break;