From f183e2958652377c19e227e9372d7c47432abd26 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 21 Mar 2014 18:22:12 -0700 Subject: [PATCH] GUAC-558: Fix calls to onerror handler, switch to corresponding close_tunnel() prototype. --- .../src/main/webapp/modules/Tunnel.js | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Tunnel.js b/guacamole-common-js/src/main/webapp/modules/Tunnel.js index 11ccb16ed..5a607edc9 100644 --- a/guacamole-common-js/src/main/webapp/modules/Tunnel.js +++ b/guacamole-common-js/src/main/webapp/modules/Tunnel.js @@ -159,11 +159,10 @@ Guacamole.HTTPTunnel = function(tunnelURL) { * an error status. * * @private - * @param {Number} guac_code The Guacamole status code related to the - * closure. - * @param {String} message A human-readable message for debugging. + * @param {Guacamole.Status} status The status causing the connection to + * close; */ - function close_tunnel(guac_code, message) { + function close_tunnel(status) { // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) @@ -175,8 +174,8 @@ Guacamole.HTTPTunnel = function(tunnelURL) { tunnel.onstatechange(tunnel.state); // If connection closed abnormally, signal error. - if (guac_code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) - tunnel.onerror(guac_code, message); + if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) + tunnel.onerror(status); } @@ -494,7 +493,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // If failure, throw error if (connect_xmlhttprequest.status !== 200) { var status = getHTTPTunnelErrorStatus(connect_xmlhttprequest); - close_tunnel(status.code, status.message); + close_tunnel(status); return; } @@ -517,7 +516,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { }; this.disconnect = function() { - close_tunnel(Guacamole.Status.Code.SUCCESS, "Manually closed."); + close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SUCCESS, "Manually closed.")); }; }; @@ -594,11 +593,10 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { * an error status. * * @private - * @param {Number} guac_code The Guacamole status code related to the - * closure. - * @param {String} message A human-readable message for debugging. + * @param {Guacamole.Status} status The status causing the connection to + * close; */ - function close_tunnel(guac_code, message) { + function close_tunnel(status) { // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) @@ -610,8 +608,8 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { tunnel.onstatechange(tunnel.state); // If connection closed abnormally, signal error. - if (guac_code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) - tunnel.onerror(guac_code, message); + if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) + tunnel.onerror(status); socket.close(); @@ -666,11 +664,11 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { }; socket.onclose = function(event) { - close_tunnel(parseInt(event.reason), event.reason); + close_tunnel(new Guacamole.Status(parseInt(event.reason), event.reason)); }; socket.onerror = function(event) { - close_tunnel(Guacamole.Status.Code.SERVER_ERROR, event.data); + close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SERVER_ERROR, event.data)); }; socket.onmessage = function(event) { @@ -700,7 +698,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { // If no period, incomplete instruction. else - close_tunnel(Guacamole.Status.Code.SERVER_ERROR, "Incomplete instruction."); + close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SERVER_ERROR, "Incomplete instruction.")); // We now have enough data for the element. Parse. var element = message.substring(startIndex, elementEnd); @@ -735,7 +733,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { }; this.disconnect = function() { - close_tunnel(Guacamole.Status.Code.SUCCESS, "Manually closed."); + close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SUCCESS, "Manually closed.")); }; };