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 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.<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.
*