You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/05/28 03:07:53 UTC

[1/6] guacamole-client git commit: GUACAMOLE-567: Add HTTP and WebSocket translation functions to Guacamole.Status.Code.

Repository: guacamole-client
Updated Branches:
  refs/heads/master f5266fdde -> c988975ec


GUACAMOLE-567: Add HTTP and WebSocket translation functions to Guacamole.Status.Code.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/a1e59b9d
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/a1e59b9d
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/a1e59b9d

Branch: refs/heads/master
Commit: a1e59b9d3aa9b7fda49b9eb5e081700f46580b97
Parents: 1710c31
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Dec 10 17:46:11 2017 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Sun May 27 12:28:28 2018 -0700

----------------------------------------------------------------------
 .../src/main/webapp/modules/Status.js           | 84 ++++++++++++++++++++
 1 file changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a1e59b9d/guacamole-common-js/src/main/webapp/modules/Status.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Status.js b/guacamole-common-js/src/main/webapp/modules/Status.js
index ceadaa6..3acfd63 100644
--- a/guacamole-common-js/src/main/webapp/modules/Status.js
+++ b/guacamole-common-js/src/main/webapp/modules/Status.js
@@ -232,3 +232,87 @@ Guacamole.Status.Code = {
     "CLIENT_TOO_MANY": 0x031D
 
 };
+
+/**
+ * Returns the Guacamole protocol status code which most closely
+ * represents the given HTTP status code.
+ *
+ * @param {Number} status
+ *     The HTTP status code to translate into a Guacamole protocol status
+ *     code.
+ *
+ * @returns {Number}
+ *     The Guacamole protocol status code which most closely represents the
+ *     given HTTP status code.
+ */
+Guacamole.Status.Code.fromHTTPCode = function fromHTTPCode(status) {
+
+    // Translate status codes with known equivalents
+    switch (status) {
+
+        // HTTP 400 - Bad request
+        case 400:
+            return Guacamole.Status.Code.CLIENT_BAD_REQUEST;
+
+        // HTTP 403 - Forbidden
+        case 403:
+            return Guacamole.Status.Code.CLIENT_FORBIDDEN;
+
+        // HTTP 404 - Resource not found
+        case 404:
+            return Guacamole.Status.Code.RESOURCE_NOT_FOUND;
+
+        // HTTP 429 - Too many requests
+        case 429:
+            return Guacamole.Status.Code.CLIENT_TOO_MANY;
+
+        // HTTP 503 - Server unavailable
+        case 503:
+            return Guacamole.Status.Code.SERVER_BUSY;
+
+    }
+
+    // Default all other codes to generic internal error
+    return Guacamole.Status.Code.SERVER_ERROR;
+
+};
+
+/**
+ * Returns the Guacamole protocol status code which most closely
+ * represents the given WebSocket status code.
+ *
+ * @param {Number} code
+ *     The WebSocket status code to translate into a Guacamole protocol
+ *     status code.
+ *
+ * @returns {Number}
+ *     The Guacamole protocol status code which most closely represents the
+ *     given WebSocket status code.
+ */
+Guacamole.Status.Code.fromWebSocketCode = function fromWebSocketCode(code) {
+
+    // Translate status codes with known equivalents
+    switch (code) {
+
+        // Successful disconnect (no error)
+        case 1000: // Normal Closure
+            return Guacamole.Status.Code.SUCCESS;
+
+        // Codes which indicate the server is not reachable
+        case 1006: // Abnormal Closure (also signalled by JavaScript when the connection cannot be opened in the first place)
+        case 1015: // TLS Handshake
+            return Guacamole.Status.Code.UPSTREAM_NOT_FOUND;
+
+        // Codes which indicate the server is reachable but busy/unavailable
+        case 1001: // Going Away
+        case 1012: // Service Restart
+        case 1013: // Try Again Later
+        case 1014: // Bad Gateway
+            return Guacamole.Status.Code.UPSTREAM_UNAVAILABLE;
+
+    }
+
+    // Default all other codes to generic internal error
+    return Guacamole.Status.Code.SERVER_ERROR;
+
+};


[4/6] guacamole-client git commit: GUACAMOLE-567: Warn user when tunnel enters "UNSTABLE" state.

Posted by vn...@apache.org.
GUACAMOLE-567: Warn user when tunnel enters "UNSTABLE" state.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/1ed22401
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/1ed22401
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/1ed22401

Branch: refs/heads/master
Commit: 1ed22401bbc2b1b076f49190530dbcf61bd4809f
Parents: e6f3665
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Dec 10 20:28:35 2017 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Sun May 27 17:09:24 2018 -0700

----------------------------------------------------------------------
 .../app/client/controllers/clientController.js  | 12 +++++++
 .../app/client/styles/connection-warning.css    | 36 ++++++++++++++++++++
 .../webapp/app/client/templates/client.html     |  5 +++
 .../webapp/app/client/types/ManagedClient.js    | 12 +++++++
 .../app/client/types/ManagedClientState.js      | 11 +++++-
 guacamole/src/main/webapp/translations/en.json  |  1 +
 6 files changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1ed22401/guacamole/src/main/webapp/app/client/controllers/clientController.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/controllers/clientController.js b/guacamole/src/main/webapp/app/client/controllers/clientController.js
index af1d726..ffbe3c5 100644
--- a/guacamole/src/main/webapp/app/client/controllers/clientController.js
+++ b/guacamole/src/main/webapp/app/client/controllers/clientController.js
@@ -626,6 +626,18 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
 
     };
 
+    /**
+     * Returns whether the current connection has been flagged as unstable due
+     * to an apparent network disruption.
+     *
+     * @returns {Boolean}
+     *     true if the current connection has been flagged as unstable, false
+     *     otherwise.
+     */
+    $scope.isConnectionUnstable = function isConnectionUnstable() {
+        return $scope.client && $scope.client.clientState.connectionState === ManagedClientState.ConnectionState.UNSTABLE;
+    };
+
     // Show status dialog when connection status changes
     $scope.$watch('client.clientState.connectionState', function clientStateChanged(connectionState) {
 

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1ed22401/guacamole/src/main/webapp/app/client/styles/connection-warning.css
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/styles/connection-warning.css b/guacamole/src/main/webapp/app/client/styles/connection-warning.css
new file mode 100644
index 0000000..eec3e07
--- /dev/null
+++ b/guacamole/src/main/webapp/app/client/styles/connection-warning.css
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#connection-warning {
+
+    position: absolute;
+    right: 0.25em;
+    top: 0.25em;
+    z-index: 20;
+
+    max-width: 100%;
+    max-height: 3in;
+
+    border: 1px solid rgba(0,0,0,0.5);
+    box-shadow: 1px 1px 2px rgba(0,0,0,0.25);
+    background: #FFE;
+    padding: 0.5em;
+    font-size: .8em;
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1ed22401/guacamole/src/main/webapp/app/client/templates/client.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/templates/client.html b/guacamole/src/main/webapp/app/client/templates/client.html
index 054cbcf..ad85f23 100644
--- a/guacamole/src/main/webapp/app/client/templates/client.html
+++ b/guacamole/src/main/webapp/app/client/templates/client.html
@@ -36,6 +36,11 @@
         <guac-file-transfer-manager client="client"></guac-file-transfer-manager>
     </div>
 
+    <!-- Connection stability warning -->
+    <div id="connection-warning" ng-show="isConnectionUnstable()">
+        {{'CLIENT.TEXT_CLIENT_STATUS_UNSTABLE' | translate}}
+    </div>
+
     <!-- Menu -->
     <div class="menu" ng-class="{open: menu.shown}" id="guac-menu">
         <div class="menu-content" ng-if="menu.shown">

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1ed22401/guacamole/src/main/webapp/app/client/types/ManagedClient.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/types/ManagedClient.js b/guacamole/src/main/webapp/app/client/types/ManagedClient.js
index e998445..09c96a9 100644
--- a/guacamole/src/main/webapp/app/client/types/ManagedClient.js
+++ b/guacamole/src/main/webapp/app/client/types/ManagedClient.js
@@ -346,6 +346,18 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
                             ManagedClientState.ConnectionState.CONNECTING);
                         break;
 
+                    // Connection is established
+                    case Guacamole.Tunnel.State.OPEN:
+                        ManagedClientState.setConnectionState(managedClient.clientState,
+                            ManagedClientState.ConnectionState.CONNECTED);
+                        break;
+
+                    // Connection is established but misbehaving
+                    case Guacamole.Tunnel.State.UNSTABLE:
+                        ManagedClientState.setConnectionState(managedClient.clientState,
+                            ManagedClientState.ConnectionState.UNSTABLE);
+                        break;
+
                     // Connection has closed
                     case Guacamole.Tunnel.State.CLOSED:
                         ManagedClientState.setConnectionState(managedClient.clientState,

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1ed22401/guacamole/src/main/webapp/app/client/types/ManagedClientState.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/types/ManagedClientState.js b/guacamole/src/main/webapp/app/client/types/ManagedClientState.js
index d77013f..1a26b0d 100644
--- a/guacamole/src/main/webapp/app/client/types/ManagedClientState.js
+++ b/guacamole/src/main/webapp/app/client/types/ManagedClientState.js
@@ -88,12 +88,21 @@ angular.module('client').factory('ManagedClientState', [function defineManagedCl
         /**
          * The Guacamole connection has been successfully established, and
          * initial graphical data has been received.
-         * 
+         *
          * @type String
          */
         CONNECTED : "CONNECTED",
 
         /**
+         * The Guacamole connection has been successfully established, but the
+         * network connection seems unstable. The connection may perform poorly
+         * or disconnect.
+         * 
+         * @type String
+         */
+        UNSTABLE : "UNSTABLE",
+
+        /**
          * The Guacamole connection has terminated successfully. No errors are
          * indicated.
          * 

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1ed22401/guacamole/src/main/webapp/translations/en.json
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/translations/en.json b/guacamole/src/main/webapp/translations/en.json
index ca8acb8..cd57e39 100644
--- a/guacamole/src/main/webapp/translations/en.json
+++ b/guacamole/src/main/webapp/translations/en.json
@@ -137,6 +137,7 @@
         "TEXT_CLIENT_STATUS_IDLE"         : "Idle.",
         "TEXT_CLIENT_STATUS_CONNECTING"   : "Connecting to Guacamole...",
         "TEXT_CLIENT_STATUS_DISCONNECTED" : "You have been disconnected.",
+        "TEXT_CLIENT_STATUS_UNSTABLE"     : "The network connection to the Guacamole server appears unstable.",
         "TEXT_CLIENT_STATUS_WAITING"      : "Connected to Guacamole. Waiting for response...",
         "TEXT_RECONNECT_COUNTDOWN"        : "Reconnecting in {REMAINING} {REMAINING, plural, one{second} other{seconds}}...",
         "TEXT_FILE_TRANSFER_PROGRESS"     : "{PROGRESS} {UNIT, select, b{B} kb{KB} mb{MB} gb{GB} other{}}",


[3/6] guacamole-client git commit: GUACAMOLE-567: Add UNSTABLE tunnel status. Mark tunnel as UNSTABLE if no data has been received in a reasonable amount of time, but the tunnel is technically still open.

Posted by vn...@apache.org.
GUACAMOLE-567: Add UNSTABLE tunnel status. Mark tunnel as UNSTABLE if no data has been received in a reasonable amount of time, but the tunnel is technically still open.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/e6f36659
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/e6f36659
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/e6f36659

Branch: refs/heads/master
Commit: e6f36659954653271495ee2c12cd80469a2ee63a
Parents: ca98d07
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Dec 10 20:22:22 2017 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Sun May 27 15:43:41 2018 -0700

----------------------------------------------------------------------
 .../src/main/webapp/modules/Tunnel.js           | 75 ++++++++++++++++++--
 1 file changed, 69 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/e6f36659/guacamole-common-js/src/main/webapp/modules/Tunnel.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Tunnel.js b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
index 63e27c5..52bd20a 100644
--- a/guacamole-common-js/src/main/webapp/modules/Tunnel.js
+++ b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
@@ -84,12 +84,23 @@ Guacamole.Tunnel = function() {
      * The maximum amount of time to wait for data to be received, in
      * milliseconds. If data is not received within this amount of time,
      * the tunnel is closed with an error. The default value is 15000.
-     * 
+     *
      * @type {Number}
      */
     this.receiveTimeout = 15000;
 
     /**
+     * The amount of time to wait for data to be received before considering
+     * the connection to be unstable, in milliseconds. If data is not received
+     * within this amount of time, the tunnel status is updated to warn that
+     * the connection appears unresponsive and may close. The default value is
+     * 1500.
+     * 
+     * @type {Number}
+     */
+    this.unstableThreshold = 1500;
+
+    /**
      * The UUID uniquely identifying this tunnel. If not yet known, this will
      * be null.
      *
@@ -165,7 +176,15 @@ Guacamole.Tunnel.State = {
      * 
      * @type {Number}
      */
-    "CLOSED": 2
+    "CLOSED": 2,
+
+    /**
+     * The connection is open, but communication through the tunnel appears to
+     * be disrupted, and the connection may close as a result.
+     *
+     * @type {Number}
+     */
+    "UNSTABLE" : 3
 
 };
 
@@ -220,6 +239,14 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
     var receive_timeout = null;
 
     /**
+     * The current connection stability timeout ID, if any.
+     *
+     * @private
+     * @type {Number}
+     */
+    var unstableTimeout = null;
+
+    /**
      * Additional headers to be sent in tunnel requests. This dictionary can be
      * populated with key/value header pairs to pass information such as authentication
      * tokens, etc.
@@ -253,14 +280,24 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
      */
     function reset_timeout() {
 
-        // Get rid of old timeout (if any)
+        // Get rid of old timeouts (if any)
         window.clearTimeout(receive_timeout);
+        window.clearTimeout(unstableTimeout);
+
+        // Clear unstable status
+        if (tunnel.state === Guacamole.Tunnel.State.UNSTABLE)
+            tunnel.setState(Guacamole.Tunnel.State.OPEN);
 
-        // Set new timeout
+        // Set new timeout for tracking overall connection timeout
         receive_timeout = window.setTimeout(function () {
             close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout."));
         }, tunnel.receiveTimeout);
 
+        // Set new timeout for tracking suspected connection instability
+        unstableTimeout = window.setTimeout(function() {
+            tunnel.setState(Guacamole.Tunnel.State.UNSTABLE);
+        }, tunnel.unstableThreshold);
+
     }
 
     /**
@@ -274,6 +311,10 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
      */
     function close_tunnel(status) {
 
+        // Get rid of old timeouts (if any)
+        window.clearTimeout(receive_timeout);
+        window.clearTimeout(unstableTimeout);
+
         // Ignore if already closed
         if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
             return;
@@ -683,6 +724,14 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
     var receive_timeout = null;
 
     /**
+     * The current connection stability timeout ID, if any.
+     *
+     * @private
+     * @type {Number}
+     */
+    var unstableTimeout = null;
+
+    /**
      * The WebSocket protocol corresponding to the protocol used for the current
      * location.
      * @private
@@ -733,14 +782,24 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
      */
     function reset_timeout() {
 
-        // Get rid of old timeout (if any)
+        // Get rid of old timeouts (if any)
         window.clearTimeout(receive_timeout);
+        window.clearTimeout(unstableTimeout);
+
+        // Clear unstable status
+        if (tunnel.state === Guacamole.Tunnel.State.UNSTABLE)
+            tunnel.setState(Guacamole.Tunnel.State.OPEN);
 
-        // Set new timeout
+        // Set new timeout for tracking overall connection timeout
         receive_timeout = window.setTimeout(function () {
             close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout."));
         }, tunnel.receiveTimeout);
 
+        // Set new timeout for tracking suspected connection instability
+        unstableTimeout = window.setTimeout(function() {
+            tunnel.setState(Guacamole.Tunnel.State.UNSTABLE);
+        }, tunnel.unstableThreshold);
+
     }
 
     /**
@@ -754,6 +813,10 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
      */
     function close_tunnel(status) {
 
+        // Get rid of old timeouts (if any)
+        window.clearTimeout(receive_timeout);
+        window.clearTimeout(unstableTimeout);
+
         // Ignore if already closed
         if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
             return;


[5/6] guacamole-client git commit: GUACAMOLE-567: Clean up style of connection stability warning. Add warning icon.

Posted by vn...@apache.org.
GUACAMOLE-567: Clean up style of connection stability warning. Add warning icon.

Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/6ea24261
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/6ea24261
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/6ea24261

Branch: refs/heads/master
Commit: 6ea24261aef0da111151faf4b9cff70bd607a6de
Parents: 1ed2240
Author: Michael Jumper <mj...@apache.org>
Authored: Sun May 27 15:27:17 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Sun May 27 17:09:24 2018 -0700

----------------------------------------------------------------------
 .../app/client/styles/connection-warning.css    |  28 ++++++++++++++++---
 guacamole/src/main/webapp/images/warning.png    | Bin 0 -> 1059 bytes
 2 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/6ea24261/guacamole/src/main/webapp/app/client/styles/connection-warning.css
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/client/styles/connection-warning.css b/guacamole/src/main/webapp/app/client/styles/connection-warning.css
index eec3e07..87af0a8 100644
--- a/guacamole/src/main/webapp/app/client/styles/connection-warning.css
+++ b/guacamole/src/main/webapp/app/client/styles/connection-warning.css
@@ -21,16 +21,36 @@
 
     position: absolute;
     right: 0.25em;
-    top: 0.25em;
+    bottom: 0.25em;
     z-index: 20;
 
+    width: 3in;
     max-width: 100%;
-    max-height: 3in;
+    min-height: 1em;
 
-    border: 1px solid rgba(0,0,0,0.5);
+    border-left: 2em solid #FA0;
     box-shadow: 1px 1px 2px rgba(0,0,0,0.25);
     background: #FFE;
-    padding: 0.5em;
+    padding: 0.5em 0.75em;
     font-size: .8em;
 
 }
+
+#connection-warning::before {
+
+    content: ' ';
+    display: block;
+    position: absolute;
+    left: -2em;
+    top: 0;
+
+    width: 1.25em;
+    height: 100%;
+    margin: 0 0.375em;
+
+    background: url('images/warning.png');
+    background-size: contain;
+    background-position: center;
+    background-repeat: no-repeat;
+
+}

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/6ea24261/guacamole/src/main/webapp/images/warning.png
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/images/warning.png b/guacamole/src/main/webapp/images/warning.png
new file mode 100644
index 0000000..1933417
Binary files /dev/null and b/guacamole/src/main/webapp/images/warning.png differ


[6/6] guacamole-client git commit: GUACAMOLE-567: Merge warn if network connection appears unstable.

Posted by vn...@apache.org.
GUACAMOLE-567: Merge warn if network connection appears unstable.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/c988975e
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/c988975e
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/c988975e

Branch: refs/heads/master
Commit: c988975ec0a9c642b1989e78c2325de2625b0910
Parents: f5266fd 6ea2426
Author: Nick Couchman <vn...@apache.org>
Authored: Sun May 27 23:07:12 2018 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Sun May 27 23:07:12 2018 -0400

----------------------------------------------------------------------
 .../src/main/webapp/modules/Status.js           |  84 ++++++++++
 .../src/main/webapp/modules/Tunnel.js           | 159 ++++++++++++-------
 .../app/client/controllers/clientController.js  |  12 ++
 .../app/client/styles/connection-warning.css    |  56 +++++++
 .../webapp/app/client/templates/client.html     |   5 +
 .../webapp/app/client/types/ManagedClient.js    |  12 ++
 .../app/client/types/ManagedClientState.js      |  11 +-
 guacamole/src/main/webapp/images/warning.png    | Bin 0 -> 1059 bytes
 guacamole/src/main/webapp/translations/en.json  |   1 +
 9 files changed, 280 insertions(+), 60 deletions(-)
----------------------------------------------------------------------



[2/6] guacamole-client git commit: GUACAMOLE-567: Rely on HTTP or WebSocket status code to determine error if Guacamole-specific reason is missing. Default to server unreachable.

Posted by vn...@apache.org.
GUACAMOLE-567: Rely on HTTP or WebSocket status code to determine error if Guacamole-specific reason is missing. Default to server unreachable.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/ca98d07b
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/ca98d07b
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/ca98d07b

Branch: refs/heads/master
Commit: ca98d07b4abe8f37a0d8eb51bd4a4043cbc2c3d1
Parents: a1e59b9
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Dec 10 16:56:19 2017 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Sun May 27 12:29:10 2018 -0700

----------------------------------------------------------------------
 .../src/main/webapp/modules/Tunnel.js           | 84 ++++++++------------
 1 file changed, 31 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/ca98d07b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Tunnel.js b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
index c8f8502..63e27c5 100644
--- a/guacamole-common-js/src/main/webapp/modules/Tunnel.js
+++ b/guacamole-common-js/src/main/webapp/modules/Tunnel.js
@@ -382,10 +382,23 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
 
     function handleHTTPTunnelError(xmlhttprequest) {
 
+        // Pull status code directly from headers provided by Guacamole
         var code = parseInt(xmlhttprequest.getResponseHeader("Guacamole-Status-Code"));
-        var message = xmlhttprequest.getResponseHeader("Guacamole-Error-Message");
+        if (code) {
+            var message = xmlhttprequest.getResponseHeader("Guacamole-Error-Message");
+            close_tunnel(new Guacamole.Status(code, message));
+        }
+
+        // Failing that, derive a Guacamole status code from the HTTP status
+        // code provided by the browser
+        else if (xmlhttprequest.status)
+            close_tunnel(new Guacamole.Status(
+                Guacamole.Status.Code.fromHTTPCode(xmlhttprequest.status),
+                    xmlhttprequest.statusText));
 
-        close_tunnel(new Guacamole.Status(code, message));
+        // Otherwise, assume server is unreachable
+        else
+            close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_NOT_FOUND));
 
     }
 
@@ -808,13 +821,22 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
         };
 
         socket.onclose = function(event) {
-            close_tunnel(new Guacamole.Status(parseInt(event.reason), event.reason));
+
+            // Pull status code directly from closure reason provided by Guacamole
+            if (event.reason)
+                close_tunnel(new Guacamole.Status(parseInt(event.reason), event.reason));
+
+            // Failing that, derive a Guacamole status code from the WebSocket
+            // status code provided by the browser
+            else if (event.code)
+                close_tunnel(new Guacamole.Status(Guacamole.Status.Code.fromWebSocketCode(event.code)));
+
+            // Otherwise, assume server is unreachable
+            else
+                close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_NOT_FOUND));
+
         };
         
-        socket.onerror = function(event) {
-            close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SERVER_ERROR, event.data));
-        };
-
         socket.onmessage = function(event) {
 
             reset_timeout();
@@ -1141,51 +1163,6 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
         }
     }
 
-    /**
-     * Returns the Guacamole protocol status code which most closely
-     * represents the given HTTP status code.
-     *
-     * @private
-     * @param {Number} httpStatus
-     *     The HTTP status code to translate into a Guacamole protocol status
-     *     code.
-     *
-     * @returns {Number}
-     *     The Guacamole protocol status code which most closely represents the
-     *     given HTTP status code.
-     */
-    var getGuacamoleStatusCode = function getGuacamoleStatusCode(httpStatus) {
-
-        // Translate status codes with known equivalents
-        switch (httpStatus) {
-
-            // HTTP 400 - Bad request
-            case 400:
-                return Guacamole.Status.Code.CLIENT_BAD_REQUEST;
-
-            // HTTP 403 - Forbidden
-            case 403:
-                return Guacamole.Status.Code.CLIENT_FORBIDDEN;
-
-            // HTTP 404 - Resource not found
-            case 404:
-                return Guacamole.Status.Code.RESOURCE_NOT_FOUND;
-
-            // HTTP 429 - Too many requests
-            case 429:
-                return Guacamole.Status.Code.CLIENT_TOO_MANY;
-
-            // HTTP 503 - Server unavailable
-            case 503:
-                return Guacamole.Status.Code.SERVER_BUSY;
-
-        }
-
-        // Default all other codes to generic internal error
-        return Guacamole.Status.Code.SERVER_ERROR;
-
-    };
-
     this.sendMessage = function sendMessage(elements) {
         // Do nothing
     };
@@ -1248,7 +1225,8 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
 
             // Fail if file could not be downloaded via HTTP
             if (tunnel.onerror)
-                tunnel.onerror(new Guacamole.Status(getGuacamoleStatusCode(xhr.status), xhr.statusText));
+                tunnel.onerror(new Guacamole.Status(
+                    Guacamole.Status.Code.fromHTTPCode(xhr.status), xhr.statusText));
 
             tunnel.disconnect();
         };