diff options
Diffstat (limited to 'web_socket.js')
-rw-r--r-- | web_socket.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/web_socket.js b/web_socket.js index 8503cc2..6cbafd5 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; } @@ -142,7 +149,7 @@ events[i](event); } var handler = this["on" + event.type]; - if (handler) handler(event); + if (handler) handler.apply(this, [event]); }; /** |