Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 53b0887032a8422daf1e09e2867b271503034e34 1 parent 9e76637
Hiroshi Ichikawa gimite authored

Showing 1 changed file with 12 additions and 7 deletions. Show diff stats Hide diff stats

  1. +12 7 web_socket.js
19 web_socket.js
@@ -117,16 +117,21 @@
117 117 };
118 118
119 119 WebSocket.prototype.close = function() {
120   - if (!this.__flash) return;
121   - this.readyState = this.__flash.getReadyState();
122   - if (this.readyState != WebSocket.OPEN) return;
123   - this.__flash.close();
  120 + var self = this;
  121 + if (!self.__flash) return;
  122 + self.readyState = self.__flash.getReadyState();
  123 + if (self.readyState != WebSocket.OPEN) return;
  124 + self.__flash.close();
124 125 // Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events
125 126 // which causes weird error:
126 127 // > You are trying to call recursively into the Flash Player which is not allowed.
127   - this.readyState = WebSocket.CLOSED;
128   - if (this.__timer) clearInterval(this.__timer);
129   - if (this.onclose) this.onclose();
  128 + self.readyState = WebSocket.CLOSED;
  129 + if (self.__timer) clearInterval(self.__timer);
  130 + if (self.onclose) {
  131 + // Make it asynchronous so that it looks more like an actual
  132 + // close event
  133 + setTimeout(self.onclose, 1);
  134 + }
130 135 };
131 136
132 137 /**

0 comments on commit 53b0887

Please sign in to comment.
Something went wrong with that request. Please try again.