Browse Source

gimite/web-socket-js issue #35: async onclose.

Filed this bug about this issue:
http://github.com/gimite/web-socket-js/issues#issue/35

To work around the flash "recursive call" problem, WebSocket.as has
the onclose event disabled in the close() call and the javascript half
of the close() call does the onclose() call instead. This is fine, but
it needs to be asynchronous to act more like what happens with
a normal WebSockets object. The current behavior is that the onclose()
method is called inline (synchronously) when the close() is called and
this inconsistency make state handling more difficult.
Joel Martin 15 years ago
parent
commit
071f2818a8
1 changed files with 5 additions and 1 deletions
  1. 5 1
      include/web-socket-js/web_socket.js

+ 5 - 1
include/web-socket-js/web_socket.js

@@ -126,7 +126,11 @@
     // > You are trying to call recursively into the Flash Player which is not allowed.
     // > You are trying to call recursively into the Flash Player which is not allowed.
     this.readyState = WebSocket.CLOSED;
     this.readyState = WebSocket.CLOSED;
     if (this.__timer) clearInterval(this.__timer);
     if (this.__timer) clearInterval(this.__timer);
-    if (this.onclose) this.onclose();
+    if (this.onclose) {
+        // Make it asynchronous so that it looks more like an actual
+        // close event
+        setTimeout(this.onclose, 1);
+    }
   };
   };
 
 
   /**
   /**