web-socket-js event fixes.
When using web-socket-js, the onopen event may happen inline so the caller may not have time to set onopen before the event fires. In this case set a short timeout and try again. In particular this affects Opera most of the time. Also, to get around Opera event droppings, always read the readyState directly instead of relying on the local readyState variable to be correct (which it isn't if stateChange event were dropped).
This commit is contained in:
parent
6713418413
commit
9479c72083
|
@ -36,8 +36,16 @@
|
|||
WebSocket.__flash.create(url, protocol, proxyHost || null, proxyPort || 0, headers || null);
|
||||
|
||||
self.__flash.addEventListener("open", function(fe) {
|
||||
console.log("web-socket.js open");
|
||||
try {
|
||||
if (self.onopen) self.onopen();
|
||||
if (self.onopen) {
|
||||
self.onopen();
|
||||
} else {
|
||||
// If "open" comes back in the same thread, then the
|
||||
// caller will not have set the onopen handler yet.
|
||||
setTimeout(function () {
|
||||
if (self.onopen) { self.onopen(); } }, 10);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.toString());
|
||||
}
|
||||
|
@ -95,6 +103,7 @@
|
|||
}
|
||||
|
||||
WebSocket.prototype.send = function(data) {
|
||||
this.readyState = this.__flash.getReadyState();
|
||||
if (!this.__flash || this.readyState == WebSocket.CONNECTING) {
|
||||
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
||||
}
|
||||
|
@ -109,6 +118,7 @@
|
|||
|
||||
WebSocket.prototype.close = function() {
|
||||
if (!this.__flash) return;
|
||||
this.readyState = this.__flash.getReadyState();
|
||||
if (this.readyState != WebSocket.OPEN) return;
|
||||
this.__flash.close();
|
||||
// Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events
|
||||
|
|
Loading…
Reference in New Issue