From: Alex Bligh Date: Fri, 7 Sep 2012 15:01:50 +0000 (+0100) Subject: Add tunnel, httpendpoint and wsendpoint parameters to client.xhtml X-Git-Url: http://git.alex.org.uk Add tunnel, httpendpoint and wsendpoint parameters to client.xhtml --- diff --git a/src/main/webapp/client.xhtml b/src/main/webapp/client.xhtml index b877981..afec1b4 100644 --- a/src/main/webapp/client.xhtml +++ b/src/main/webapp/client.xhtml @@ -117,16 +117,46 @@ 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);