GUACAMOLE-1402: Expose Client state enum values.

This commit is contained in:
Virtually Nick
2021-12-25 22:24:09 -05:00
parent e64013059d
commit e35f3bbd63

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;
var pingInterval = null; var pingInterval = null;
@@ -132,8 +125,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;
} }
/** /**
@@ -1547,8 +1540,8 @@ Guacamole.Client = function(tunnel) {
}); });
// 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)
@@ -1653,10 +1646,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 ping // Stop ping
if (pingInterval) if (pingInterval)
@@ -1665,7 +1658,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);
} }
@@ -1684,13 +1677,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;
} }
@@ -1699,11 +1692,63 @@ Guacamole.Client = function(tunnel) {
tunnel.sendMessage("nop"); tunnel.sendMessage("nop");
}, 5000); }, 5000);
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.
* *