Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 53b0887032a8422daf1e09e2867b271503034e34 1 parent 9e76637
@gimite gimite authored
Showing with 12 additions and 7 deletions.
  1. +12 −7 web_socket.js
View
19 web_socket.js
@@ -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);
+ }
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.