summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--WebSocketMain.swfbin175845 -> 175928 bytes
-rw-r--r--WebSocketMainInsecure.zipbin166515 -> 166736 bytes
-rw-r--r--flash-src/.gitignore1
-rw-r--r--flash-src/build.properties.sample2
-rwxr-xr-xflash-src/build.sh6
-rw-r--r--flash-src/build.xml65
-rw-r--r--flash-src/net/gimite/websocket/IWebSocketLogger.as (renamed from flash-src/IWebSocketLogger.as)5
-rw-r--r--flash-src/net/gimite/websocket/WebSocket.as (renamed from flash-src/WebSocket.as)2
-rw-r--r--flash-src/net/gimite/websocket/WebSocketEvent.as (renamed from flash-src/WebSocketEvent.as)2
-rw-r--r--flash-src/net/gimite/websocket/WebSocketMain.as (renamed from flash-src/WebSocketMain.as)2
-rw-r--r--flash-src/net/gimite/websocket/WebSocketMainInsecure.as (renamed from flash-src/WebSocketMainInsecure.as)4
-rw-r--r--web_socket.js41
13 files changed, 103 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 80e8f7a..ecf5763 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
test.html
+WebSocket.swc
diff --git a/WebSocketMain.swf b/WebSocketMain.swf
index 5c8ab83..657c762 100644
--- a/WebSocketMain.swf
+++ b/WebSocketMain.swf
Binary files differ
diff --git a/WebSocketMainInsecure.zip b/WebSocketMainInsecure.zip
index e996b94..560a8d4 100644
--- a/WebSocketMainInsecure.zip
+++ b/WebSocketMainInsecure.zip
Binary files differ
diff --git a/flash-src/.gitignore b/flash-src/.gitignore
new file mode 100644
index 0000000..56fb545
--- /dev/null
+++ b/flash-src/.gitignore
@@ -0,0 +1 @@
+build.properties
diff --git a/flash-src/build.properties.sample b/flash-src/build.properties.sample
new file mode 100644
index 0000000..6ae8786
--- /dev/null
+++ b/flash-src/build.properties.sample
@@ -0,0 +1,2 @@
+# Point this to your Flex SDK directory.
+FLEX_HOME=/usr/local/share/flex_sdk_4
diff --git a/flash-src/build.sh b/flash-src/build.sh
index 598674a..0fb02a5 100755
--- a/flash-src/build.sh
+++ b/flash-src/build.sh
@@ -1,10 +1,12 @@
#!/bin/sh
+# A script to build WebSocketMain.swf and WebSocketMainInsecure.zip.
+
# You need Flex 4 SDK:
# http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
-mxmlc -static-link-runtime-shared-libraries -target-player=10.0.0 -output=../WebSocketMain.swf WebSocketMain.as &&
-mxmlc -static-link-runtime-shared-libraries -output=../WebSocketMainInsecure.swf WebSocketMainInsecure.as &&
+mxmlc -static-link-runtime-shared-libraries -target-player=10.0.0 -output=../WebSocketMain.swf -source-path=. net/gimite/websocket/WebSocketMain.as &&
+mxmlc -static-link-runtime-shared-libraries -output=../WebSocketMainInsecure.swf -source-path=. net/gimite/websocket/WebSocketMainInsecure.as &&
cd .. &&
zip WebSocketMainInsecure.zip WebSocketMainInsecure.swf &&
rm WebSocketMainInsecure.swf
diff --git a/flash-src/build.xml b/flash-src/build.xml
new file mode 100644
index 0000000..967ff89
--- /dev/null
+++ b/flash-src/build.xml
@@ -0,0 +1,65 @@
+<!--
+ Ant build file which provides Yet another way (other than build.sh) to build SWF files.
+
+ You need to copy build.properties.sample to build.properties and change FLEX_HOME
+ for your environment.
+-->
+
+<?xml version="1.0" encoding="utf-8"?>
+<project name="ant" basedir="." default="swf">
+
+<property file="build.properties" /><!-- set sdk -->
+<echo message="Using SDK version: ${FLEX_HOME}" />
+<!-- do not change next 2 lines, it adds needed task to ant -->
+<property name="FLEXTASKS" value="${FLEX_HOME}/ant/lib/flexTasks.jar"/>
+<taskdef resource="flexTasks.tasks" classpath="${FLEXTASKS}"/>
+
+<target name="swf">
+ <delete file="../WebSocketMain.swf"/>
+ <mxmlc file="net/gimite/websocket/WebSocketMain.as"
+ output="../WebSocketMain.swf"
+ incremental="false"
+ strict="true"
+ accessible="false"
+ fork="true"
+ static-link-runtime-shared-libraries="true">
+ <optimize>true</optimize>
+ <target-player>10</target-player>
+ <raw-metadata></raw-metadata>
+ <source-path path-element="."/>
+ </mxmlc>
+</target>
+
+<target name="swfInsecure">
+ <delete file="../WebSocketMainInsecure.swf" />
+ <mxmlc file="net/gimite/websocket/WebSocketMainInsecure.as"
+ output="../WebSocketMainInsecure.swf"
+ incremental="false"
+ strict="true"
+ accessible="false"
+ fork="true"
+ static-link-runtime-shared-libraries="true">
+ <optimize>true</optimize>
+ <target-player>10</target-player>
+ <raw-metadata></raw-metadata>
+ <source-path path-element="."/>
+ </mxmlc>
+</target>
+
+<target name="swc" ><!-- for pure .as -->
+ <delete file="../WebSocket.swc" />
+ <compc output="../WebSocket.swc"
+ incremental="false"
+ strict="true"
+ accessible="false"
+ fork="true"
+ static-link-runtime-shared-libraries="true">
+ <optimize>true</optimize>
+ <raw-metadata></raw-metadata>
+ <include-sources dir="." includes="**/*.as"/>
+ <source-path path-element="."/>
+ </compc>
+</target>
+
+</project>
+ \ No newline at end of file
diff --git a/flash-src/IWebSocketLogger.as b/flash-src/net/gimite/websocket/IWebSocketLogger.as
index 24f4ef7..c3384f3 100644
--- a/flash-src/IWebSocketLogger.as
+++ b/flash-src/net/gimite/websocket/IWebSocketLogger.as
@@ -1,4 +1,7 @@
-package {
+// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
+// License: New BSD License
+
+package net.gimite.websocket {
public interface IWebSocketLogger {
function log(message:String):void;
diff --git a/flash-src/WebSocket.as b/flash-src/net/gimite/websocket/WebSocket.as
index 43b274a..f043b60 100644
--- a/flash-src/WebSocket.as
+++ b/flash-src/net/gimite/websocket/WebSocket.as
@@ -3,7 +3,7 @@
// Reference: http://dev.w3.org/html5/websockets/
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
-package {
+package net.gimite.websocket {
import com.adobe.net.proxies.RFC2817Socket;
import com.gsolo.encryption.MD5;
diff --git a/flash-src/WebSocketEvent.as b/flash-src/net/gimite/websocket/WebSocketEvent.as
index 598eeb2..aa17cac 100644
--- a/flash-src/WebSocketEvent.as
+++ b/flash-src/net/gimite/websocket/WebSocketEvent.as
@@ -1,4 +1,4 @@
-package {
+package net.gimite.websocket {
import flash.events.Event;
diff --git a/flash-src/WebSocketMain.as b/flash-src/net/gimite/websocket/WebSocketMain.as
index 1bf3d7e..28cd66d 100644
--- a/flash-src/WebSocketMain.as
+++ b/flash-src/net/gimite/websocket/WebSocketMain.as
@@ -3,7 +3,7 @@
// Reference: http://dev.w3.org/html5/websockets/
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
-package {
+package net.gimite.websocket {
import flash.display.Sprite;
import flash.external.ExternalInterface;
diff --git a/flash-src/WebSocketMainInsecure.as b/flash-src/net/gimite/websocket/WebSocketMainInsecure.as
index ea377be..e845839 100644
--- a/flash-src/WebSocketMainInsecure.as
+++ b/flash-src/net/gimite/websocket/WebSocketMainInsecure.as
@@ -3,9 +3,9 @@
// Reference: http://dev.w3.org/html5/websockets/
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
-package {
+package net.gimite.websocket {
-import flash.system.*;
+import flash.system.Security;
public class WebSocketMainInsecure extends WebSocketMain {
diff --git a/web_socket.js b/web_socket.js
index 6d3a2d4..7c18745 100644
--- a/web_socket.js
+++ b/web_socket.js
@@ -5,26 +5,25 @@
(function() {
- if (window.WebSocket) return;
+ if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) return;
- if (!window.WebSocketLogger || !window.WebSocketLogger.log || !window.WebSocketLogger.error) {
- var temp_console = window.console;
- if (!temp_console || !temp_console.log || !temp_console.error) {
- temp_console = {log: function(){ }, error: function(){ }};
- }
- window.WebSocketLogger = {
- log: function(msg) { if (window.WEB_SOCKET_DEBUG) temp_console.log(msg) },
- error: function(msg) { if (window.WEB_SOCKET_DEBUG) temp_console.error(msg) }
- }
+ var logger;
+ if (window.WEB_SOCKET_LOGGER) {
+ logger = WEB_SOCKET_LOGGER;
+ } else if (window.console && window.console.log && window.console.error) {
+ // In some environment, console is defined but console.log or console.error is missing.
+ logger = window.console;
+ } else {
+ logger = {log: function(){ }, error: function(){ }};
}
// swfobject.hasFlashPlayerVersion("10.0.0") doesn't work with Gnash.
if (!swfobject.getFlashPlayerVersion().major >= 10) {
- window.WebSocketLogger.error("Flash Player >= 10.0.0 is required.");
+ logger.error("Flash Player >= 10.0.0 is required.");
return;
}
if (location.protocol == "file:") {
- window.WebSocketLogger.error(
+ logger.error(
"WARNING: web-socket-js doesn't work in file:///... URL " +
"unless you set Flash Security Settings properly. " +
"Open the page via Web server i.e. http://...");
@@ -229,18 +228,20 @@
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
}
if (!window.WEB_SOCKET_SWF_LOCATION) {
- window.WebSocketLogger.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
+ logger.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
return;
}
- if (!WEB_SOCKET_SWF_LOCATION.match(/(^|\/)WebSocketMainInsecure\.swf(\?.*)?$/) &&
+ if (!window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR &&
+ !WEB_SOCKET_SWF_LOCATION.match(/(^|\/)WebSocketMainInsecure\.swf(\?.*)?$/) &&
WEB_SOCKET_SWF_LOCATION.match(/^\w+:\/\/([^\/]+)/)) {
var swfHost = RegExp.$1;
if (location.host != swfHost) {
- window.WebSocketLogger.error(
+ logger.error(
"[WebSocket] You must host HTML and WebSocketMain.swf in the same host " +
"('" + location.host + "' != '" + swfHost + "'). " +
"See also 'How to host HTML file and SWF file in different domains' section " +
- "in README.md.");
+ "in README.md. If you use WebSocketMainInsecure.swf, you can suppress this message " +
+ "by WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true;");
}
}
var container = document.createElement("div");
@@ -276,7 +277,7 @@
null,
function(e) {
if (!e.success) {
- window.WebSocketLogger.error("[WebSocket] swfobject.embedSWF failed");
+ logger.error("[WebSocket] swfobject.embedSWF failed");
}
});
};
@@ -313,7 +314,7 @@
WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
}
} catch (e) {
- window.WebSocketLogger.error(e);
+ logger.error(e);
}
}, 0);
return true;
@@ -321,12 +322,12 @@
// Called by Flash.
WebSocket.__log = function(message) {
- window.WebSocketLogger.log(decodeURIComponent(message));
+ logger.log(decodeURIComponent(message));
};
// Called by Flash.
WebSocket.__error = function(message) {
- window.WebSocketLogger.error(decodeURIComponent(message));
+ logger.error(decodeURIComponent(message));
};
WebSocket.__addTask = function(task) {