From 97609c1bdbdc7d20ba549d1a39d883788efd9b14 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Mar 2012 15:53:54 -0800 Subject: [PATCH] Implement ChainedTunnel, which wraps an arbitrary list of tunnels, using each in order if a tunnel fails. --- src/main/resources/tunnel.js | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/main/resources/tunnel.js b/src/main/resources/tunnel.js index 79343da..835f9f5 100644 --- a/src/main/resources/tunnel.js +++ b/src/main/resources/tunnel.js @@ -464,6 +464,20 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { "https:": "wss:" }; + var status_code = { + 1000: "Connection closed normally.", + 1001: "Connection shut down.", + 1002: "Protocol error.", + 1003: "Invalid data.", + 1004: "[UNKNOWN, RESERVED]", + 1005: "No status code present.", + 1006: "Connection closed abnormally.", + 1007: "Inconsistent data type.", + 1008: "Policy violation.", + 1009: "Message too large.", + 1010: "Extension negotiation failed." + }; + var STATE_IDLE = 0; var STATE_CONNECTED = 1; var STATE_DISCONNECTED = 2; @@ -548,6 +562,14 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { currentState = STATE_CONNECTED; }; + socket.onclose = function(event) { + + // If connection closed abnormally, signal error. + if (event.code != 1000 && tunnel.onerror) + tunnel.onerror(status_code[event.code]); + + }; + socket.onerror = function(event) { // Call error handler @@ -625,3 +647,77 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { Guacamole.WebSocketTunnel.prototype = new Guacamole.Tunnel(); + +Guacamole.ChainedTunnel = function() { + + var chained_tunnel = this; + var current_tunnel = null; + + var connect_data; + var tunnels = []; + + // Load all tunnels into array + for (var i=0; i