mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-558: Fix calls to onerror handler, switch to corresponding close_tunnel() prototype.
This commit is contained in:
@@ -159,11 +159,10 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
|
|||||||
* an error status.
|
* an error status.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Number} guac_code The Guacamole status code related to the
|
* @param {Guacamole.Status} status The status causing the connection to
|
||||||
* closure.
|
* close;
|
||||||
* @param {String} message A human-readable message for debugging.
|
|
||||||
*/
|
*/
|
||||||
function close_tunnel(guac_code, message) {
|
function close_tunnel(status) {
|
||||||
|
|
||||||
// Ignore if already closed
|
// Ignore if already closed
|
||||||
if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
|
if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
|
||||||
@@ -175,8 +174,8 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
|
|||||||
tunnel.onstatechange(tunnel.state);
|
tunnel.onstatechange(tunnel.state);
|
||||||
|
|
||||||
// If connection closed abnormally, signal error.
|
// If connection closed abnormally, signal error.
|
||||||
if (guac_code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror)
|
if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror)
|
||||||
tunnel.onerror(guac_code, message);
|
tunnel.onerror(status);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,7 +493,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
|
|||||||
// If failure, throw error
|
// If failure, throw error
|
||||||
if (connect_xmlhttprequest.status !== 200) {
|
if (connect_xmlhttprequest.status !== 200) {
|
||||||
var status = getHTTPTunnelErrorStatus(connect_xmlhttprequest);
|
var status = getHTTPTunnelErrorStatus(connect_xmlhttprequest);
|
||||||
close_tunnel(status.code, status.message);
|
close_tunnel(status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +516,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.disconnect = function() {
|
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.
|
* an error status.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Number} guac_code The Guacamole status code related to the
|
* @param {Guacamole.Status} status The status causing the connection to
|
||||||
* closure.
|
* close;
|
||||||
* @param {String} message A human-readable message for debugging.
|
|
||||||
*/
|
*/
|
||||||
function close_tunnel(guac_code, message) {
|
function close_tunnel(status) {
|
||||||
|
|
||||||
// Ignore if already closed
|
// Ignore if already closed
|
||||||
if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
|
if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
|
||||||
@@ -610,8 +608,8 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|||||||
tunnel.onstatechange(tunnel.state);
|
tunnel.onstatechange(tunnel.state);
|
||||||
|
|
||||||
// If connection closed abnormally, signal error.
|
// If connection closed abnormally, signal error.
|
||||||
if (guac_code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror)
|
if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror)
|
||||||
tunnel.onerror(guac_code, message);
|
tunnel.onerror(status);
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
|
||||||
@@ -666,11 +664,11 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
socket.onclose = function(event) {
|
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) {
|
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) {
|
socket.onmessage = function(event) {
|
||||||
@@ -700,7 +698,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|||||||
|
|
||||||
// If no period, incomplete instruction.
|
// If no period, incomplete instruction.
|
||||||
else
|
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.
|
// We now have enough data for the element. Parse.
|
||||||
var element = message.substring(startIndex, elementEnd);
|
var element = message.substring(startIndex, elementEnd);
|
||||||
@@ -735,7 +733,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.disconnect = function() {
|
this.disconnect = function() {
|
||||||
close_tunnel(Guacamole.Status.Code.SUCCESS, "Manually closed.");
|
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SUCCESS, "Manually closed."));
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user