Fix jsdoc, add missing documentation.
[guacamole-common-js.git] / src / main / resources / tunnel.js
index f44110d..4f75ea3 100644 (file)
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Guacamole namespace
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
 var Guacamole = Guacamole || {};
 
 /**
@@ -104,6 +107,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
 
     /**
      * Reference to this HTTP tunnel.
+     * @private
      */
     var tunnel = this;
 
@@ -142,6 +146,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
          * Converts the given value to a length/string pair for use as an
          * element in a Guacamole instruction.
          * 
+         * @private
          * @param value The value to convert.
          * @return {String} The converted value. 
          */
@@ -207,10 +212,28 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
 
         var status = xmlhttprequest.status;
 
-        if (status >= 200 && status <= 299) return "Success";
-        if (status >= 400 && status <= 499) return "Unauthorized";
-        if (status >= 500 && status <= 599) return "Connection lost";
-
+        // Special cases
+        if (status == 0)   return "Disconnected";
+        if (status == 200) return "Success";
+        if (status == 403) return "Unauthorized";
+        if (status == 404) return "Connection closed"; /* While it may be more
+                                                        * accurate to say the
+                                                        * connection does not
+                                                        * exist, it is confusing
+                                                        * to the user.
+                                                        * 
+                                                        * In general, this error
+                                                        * will only happen when
+                                                        * the tunnel does not
+                                                        * exist, which happens
+                                                        * after the connection
+                                                        * is closed and the
+                                                        * tunnel is detached.
+                                                        */
+        // Internal server errors
+        if (status >= 500 && status <= 599) return "Server error";
+
+        // Otherwise, unknown
         return "Unknown error";
 
     }
@@ -466,17 +489,20 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
 
     /**
      * Reference to this WebSocket tunnel.
+     * @private
      */
     var tunnel = this;
 
     /**
      * The WebSocket used by this tunnel.
+     * @private
      */
     var socket = null;
 
     /**
      * The WebSocket protocol corresponding to the protocol used for the current
      * location.
+     * @private
      */
     var ws_protocol = {
         "http:":  "ws:",
@@ -550,6 +576,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
          * Converts the given value to a length/string pair for use as an
          * element in a Guacamole instruction.
          * 
+         * @private
          * @param value The value to convert.
          * @return {String} The converted value. 
          */
@@ -682,23 +709,27 @@ Guacamole.ChainedTunnel = function(tunnel_chain) {
 
     /**
      * Reference to this chained tunnel.
+     * @private
      */
     var chained_tunnel = this;
 
     /**
      * The currently wrapped tunnel, if any.
+     * @private
      */
     var current_tunnel = null;
 
     /**
      * Data passed in via connect(), to be used for
      * wrapped calls to other tunnels' connect() functions.
+     * @private
      */
     var connect_data;
 
     /**
      * Array of all tunnels passed to this ChainedTunnel through the
      * constructor arguments.
+     * @private
      */
     var tunnels = [];
 
@@ -707,7 +738,10 @@ Guacamole.ChainedTunnel = function(tunnel_chain) {
         tunnels.push(arguments[i]);
 
     /**
-     * Sets the current tunnel
+     * Sets the current tunnel.
+     * 
+     * @private
+     * @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
      */
     function attach(tunnel) {