diff options
author | Hiroshi Ichikawa <gimite@gmail.com> | 2011-09-03 02:32:24 -0700 |
---|---|---|
committer | Hiroshi Ichikawa <gimite@gmail.com> | 2011-09-03 02:32:24 -0700 |
commit | 6b8dcbe94f7f9cc0594bcdabdd51d677135f0274 (patch) | |
tree | dc1e987b993769437d47fb1e8d9e396baed758b8 | |
parent | 80c91d84bc3e84f684f53172e8eb7cad81795fb1 (diff) | |
parent | 406208b9b97d5e01e91d109bb92eece5b075a16f (diff) | |
download | web-socket-js-6b8dcbe94f7f9cc0594bcdabdd51d677135f0274.tar.gz |
Merge pull request #88 from kanaka/master
init/close fix.
-rw-r--r-- | web_socket.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/web_socket.js b/web_socket.js index 5397332..947a637 100644 --- a/web_socket.js +++ b/web_socket.js @@ -51,8 +51,9 @@ } // Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc. // Otherwise, when onopen fires immediately, onopen is called before it is set. - setTimeout(function() { + self.__createTask = setTimeout(function() { WebSocket.__addTask(function() { + self.__createTask = null; WebSocket.__flash.create( self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null); }); @@ -89,6 +90,12 @@ * Close this web socket gracefully. */ WebSocket.prototype.close = function() { + if (this.__createTask) { + clearTimeout(this.__createTask); + this.__createTask = null; + this.readyState = WebSocket.CLOSED; + return; + } if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) { return; } |