Permalink
Browse files

Making onclose event fired by ws.close() asynchronous.

  • Loading branch information...
gimite committed Sep 13, 2010
1 parent 9e76637 commit 53b0887032a8422daf1e09e2867b271503034e34
Showing with 12 additions and 7 deletions.
  1. +12 −7 web_socket.js
View
@@ -117,16 +117,21 @@
};
WebSocket.prototype.close = function() {
- if (!this.__flash) return;
- this.readyState = this.__flash.getReadyState();
- if (this.readyState != WebSocket.OPEN) return;
- this.__flash.close();
+ var self = this;
+ if (!self.__flash) return;
+ self.readyState = self.__flash.getReadyState();
+ if (self.readyState != WebSocket.OPEN) return;
+ self.__flash.close();
// Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events
// which causes weird error:
// > You are trying to call recursively into the Flash Player which is not allowed.
- this.readyState = WebSocket.CLOSED;
- if (this.__timer) clearInterval(this.__timer);
- if (this.onclose) this.onclose();
+ self.readyState = WebSocket.CLOSED;
+ if (self.__timer) clearInterval(self.__timer);
+ if (self.onclose) {
+ // Make it asynchronous so that it looks more like an actual
+ // close event
+ setTimeout(self.onclose, 1);
+ }
};
/**

0 comments on commit 53b0887

Please sign in to comment.