Add tunnel, httpendpoint and wsendpoint parameters to client.xhtml
authorAlex Bligh <alex@alex.org.uk>
Fri, 7 Sep 2012 15:01:50 +0000 (16:01 +0100)
committerAlex Bligh <alex@alex.org.uk>
Fri, 7 Sep 2012 15:02:44 +0000 (16:02 +0100)
src/main/webapp/client.xhtml

index b877981..afec1b4 100644 (file)
 
                     var tunnel;
 
-                    // If WebSocket available, try to use it.
-                    if (window.WebSocket)
-                        tunnel = new Guacamole.ChainedTunnel(
-                            new Guacamole.WebSocketTunnel("websocket-tunnel"),
-                            new Guacamole.HTTPTunnel("tunnel")
-                        );
-
-                    // If no WebSocket, then use HTTP.
-                    else
-                        tunnel = new Guacamole.HTTPTunnel("tunnel")
+                    function getParameter (paramName, defaultValue) {
+                       var regex = new RegExp('[?][^#]*' + paramName + '=([^&#]*)');
+                       if (typeof defaultValue === 'undefined') {
+                           defaultValue = null;
+                       }
+                       return (window.location.href.match(regex) || ['', defaultValue])[1];
+                    }
+
+                    var tunneltype = getParameter("tunnel");
+                    var wsendpoint = getParameter("wsendpoint", "websocket-tunnel");
+                    var httpendpoint = getParameter("httpendpoint", "tunnel");
+
+                    switch (tunneltype) {
+                      case 'http':
+                        tunnel = new Guacamole.HTTPTunnel(httpendpoint);
+                        break;
+                      case 'ws':
+                        if (window.WebSocket)
+                            tunnel = new Guacamole.WebSocketTunnel(wsendpoint);
+                        break;
+                      case 'chained':
+                        if (window.WebSocket)
+                            tunnel = new Guacamole.ChainedTunnel(
+                                new Guacamole.WebSocketTunnel(wsendpoint),
+                                new Guacamole.HTTPTunnel(httpendpoint)
+                            );
+                        break;
+                      default:
+                        // Try to guess what tunnel we are using
+                        // If WebSocket available, try to use it.
+                        if (window.WebSocket)
+                            tunnel = new Guacamole.ChainedTunnel(
+                                new Guacamole.WebSocketTunnel(wsendpoint),
+                                new Guacamole.HTTPTunnel(httpendpoint)
+                            );
+                        // If no WebSocket, then use HTTP.
+                        else
+                            tunnel = new Guacamole.HTTPTunnel(httpendpoint);
+                        break;
+                    }
 
                     // Instantiate client
                     var guac = new Guacamole.Client(tunnel);