Permalink
Browse files

Merge branch 'master' of http://github.com/gimite/web-socket-js

Conflicts:
	WebSocketMain.swf
  • Loading branch information...
2 parents 6c6981c + 8e46ce3 commit 86ad23efe2d2df9ba1ee7dd2354b2b8eb5e3d057 @Vagabond committed Sep 23, 2010
View
@@ -362,7 +362,7 @@ FABridge.prototype =
// accepts a type structure, returns a constructed type
addTypeDataToCache: function(typeData)
{
- newType = new ASProxy(this, typeData.name);
+ var newType = new ASProxy(this, typeData.name);
var accessors = typeData.accessors;
for (var i = 0; i < accessors.length; i++)
{
View
@@ -84,6 +84,17 @@ The AS3 Socket class doesn't implement this mechanism, which renders it useless
The class RFC2817Socket (by Christian Cantrell) effectively lets us implement this, as long as the proxy settings are known and provided by the interface that instantiates the WebSocket. As such, if you want to support proxied conncetions, you'll have to supply this information to the WebSocket constructor when Flash is being used. One way to go about it would be to ask the user for proxy settings information if the initial connection fails.
+* How to host HTML file and SWF file in different domains
+
+By default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain.
+
+WARNING: If you use the method below, HTML files in ANY domains can send arbitrary TCP data to your WebSocket server, regardless of configuration in Flash socket policy file. Arbitrary TCP data means that they can even fake request headers including Origin and Cookie.
+
+- Unzip WebSocketMainInsecure.zip to extract WebSocketMainInsecure.swf.
+- Put WebSocketMainInsecure.swf on your server, instead of WebSocketMain.swf.
+- In JavaScript, set WEB_SOCKET_SWF_LOCATION to URL of your WebSocketMainInsecure.swf.
+
+
* How to build WebSocketMain.swf
Install Flex 4 SDK:
View
Binary file not shown.
View
Binary file not shown.
View
@@ -138,9 +138,11 @@ public class WebSocket extends EventDispatcher {
main.log("close");
dataQueue = [];
try {
- socket.writeByte(0xff);
- socket.writeByte(0x00);
- socket.flush();
+ if (readyState == OPEN) {
+ socket.writeByte(0xff);
+ socket.writeByte(0x00);
+ socket.flush();
+ }
socket.close();
} catch (ex:Error) { }
readyState = CLOSED;
@@ -1,7 +1,7 @@
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
// License: New BSD License
// Reference: http://dev.w3.org/html5/websockets/
-// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-31
+// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
package {
@@ -0,0 +1,19 @@
+// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
+// License: New BSD License
+// Reference: http://dev.w3.org/html5/websockets/
+// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
+
+package {
+
+import flash.system.*;
+
+public class WebSocketMainInsecure extends WebSocketMain {
+
+ public function WebSocketMainInsecure() {
+ Security.allowDomain("*");
+ super();
+ }
+
+}
+
+}
View
@@ -3,4 +3,8 @@
# You need Flex 4 SDK:
# http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
-mxmlc -static-link-runtime-shared-libraries -output=../WebSocketMain.swf WebSocketMain.as
+mxmlc -static-link-runtime-shared-libraries -output=../WebSocketMain.swf WebSocketMain.as &&
+mxmlc -static-link-runtime-shared-libraries -output=../WebSocketMainInsecure.swf WebSocketMainInsecure.as &&
+cd .. &&
+zip WebSocketMainInsecure.zip WebSocketMainInsecure.swf &&
+rm WebSocketMainInsecure.swf
View
@@ -17,7 +17,9 @@
WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
// Set this to dump debug message from Flash to console.log:
WEB_SOCKET_DEBUG = true;
-
+
+ // Everything below is the same as using standard WebSocket.
+
var ws;
function init() {
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.CLOSED || self.readyState == WebSocket.CLOSING) 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);
+ }
};
/**
@@ -326,7 +331,7 @@
swfobject.embedSWF(
WEB_SOCKET_SWF_LOCATION, "webSocketFlash",
"1" /* width */, "1" /* height */, "9.0.0" /* SWF version */,
- null, {bridgeName: "webSocket"}, {hasPriority: true}, null,
+ null, {bridgeName: "webSocket"}, {hasPriority: true, allowScriptAccess: "always"}, null,
function(e) {
if (!e.success) console.error("[WebSocket] swfobject.embedSWF failed");
}

0 comments on commit 86ad23e

Please sign in to comment.