From ac7bdbc22fd9a0f150479321ebe7e01f8d448a74 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Sat, 11 Sep 2010 13:52:49 -0500 Subject: [PATCH] web-socket-js (issue #37): close() when connecting Filed this issue for this bug: http://github.com/gimite/web-socket-js/issues/issue/37 Right now the close() call only calls __flash.close() if readyState is OPEN. But it should really call close any time that readyState is not CLOSED or CLOSING. The case I ran into is when I want to do the following: 1. make a test connection 2. tell the server to setup for a connection 3. connect again I call close on the test connection, but since it is ignored when CONNECTING, it eventually times out with a error. But by that time I have already issued a new connection, it causes the new connection to fail. close() should cancel CONNECTING state too. --- include/web-socket-js/web_socket.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/web-socket-js/web_socket.js b/include/web-socket-js/web_socket.js index 1f040d56..fec2ab2a 100755 --- a/include/web-socket-js/web_socket.js +++ b/include/web-socket-js/web_socket.js @@ -119,7 +119,10 @@ WebSocket.prototype.close = function() { if (!this.__flash) return; this.readyState = this.__flash.getReadyState(); - if (this.readyState != WebSocket.OPEN) return; + if ((this.readyState === WebSocket.CLOSED) || + (this.readState === WebSocket.CLOSING)) { + return; + } this.__flash.close(); // Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events // which causes weird error: