From 4b2ba27c91164ae45bb246890f872786c5e93fa9 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Fri, 7 Sep 2012 16:01:50 +0100 Subject: [PATCH] Add tunnel, httpendpoint and wsendpoint parameters to client.xhtml --- src/main/webapp/client.xhtml | 50 +++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) 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); -- 1.7.10.4