Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some cleanup.

Pulling messages from JavaScript instead of pushing from Flash, to keep message order.
Merging WebSocketController to WebSocket.
  • Loading branch information...
commit 978e31ce6ff15926391b616667c4e4370bbac800 1 parent 0591d5d
@gimite gimite authored
View
BIN  WebSocketMain.swf 100755 → 100644
Binary file not shown
View
BIN  WebSocketMainInsecure.zip
Binary file not shown
View
45 flash-src/WebSocket.as
@@ -24,7 +24,6 @@ import mx.core.*;
import mx.events.*;
import mx.utils.*;
-[Event(name="event", type="flash.events.Event")]
public class WebSocket extends EventDispatcher {
private static var CONNECTING:int = 0;
@@ -32,8 +31,7 @@ public class WebSocket extends EventDispatcher {
private static var CLOSING:int = 2;
private static var CLOSED:int = 3;
- private var socketId : Number;
-
+ private var id:int;
private var rawSocket:Socket;
private var tlsSocket:TLSSocket;
private var tlsConfig:TLSConfig;
@@ -54,11 +52,11 @@ public class WebSocket extends EventDispatcher {
private var expectedDigest:String;
public function WebSocket(
- main:WebSocketMain, webSocketId : Number, url:String, protocol:String,
+ main:WebSocketMain, id:int, url:String, protocol:String,
proxyHost:String = null, proxyPort:int = 0,
headers:String = null) {
this.main = main;
- this.socketId = webSocketId;
+ this.id = id;
initNoiseChars();
this.url = url;
var m:Array = url.match(/^(\w+):\/\/([^\/:]+)(:(\d+))?(\/.*)?$/);
@@ -106,19 +104,17 @@ public class WebSocket extends EventDispatcher {
}
/**
- * socketId accessor
- * @return This WebSocket's ID.
- */
- public function get webSocketId() : Number {
- return this.socketId;
+ * @return This WebSocket's ID.
+ */
+ public function getId():int {
+ return this.id;
}
/**
- * readyState accessor
- * @return this WebSocket's readyState.
- */
- public function get readOnly_readyState() : int {
- return this.readyState;
+ * @return this WebSocket's readyState.
+ */
+ public function getReadyState():int {
+ return this.readyState;
}
public function send(encData:String):int {
@@ -140,10 +136,10 @@ public class WebSocket extends EventDispatcher {
}
}
- public function close():void {
+ public function close(isError:Boolean = false):void {
main.log("close");
try {
- if (readyState == OPEN) {
+ if (readyState == OPEN && !isError) {
socket.writeByte(0xff);
socket.writeByte(0x00);
socket.flush();
@@ -151,7 +147,7 @@ public class WebSocket extends EventDispatcher {
socket.close();
} catch (ex:Error) { }
readyState = CLOSED;
- this.dispatchEvent(new WebSocketEvent(WebSocketEvent.CLOSE));
+ this.dispatchEvent(new WebSocketEvent(isError ? "error" : "close"));
}
private function onSocketConnect(event:Event):void {
@@ -198,7 +194,7 @@ public class WebSocket extends EventDispatcher {
private function onSocketClose(event:Event):void {
main.log("closed");
readyState = CLOSED;
- this.dispatchEvent(new WebSocketEvent(WebSocketEvent.CLOSE));
+ this.dispatchEvent(new WebSocketEvent("close"));
}
private function onSocketIoError(event:IOErrorEvent):void {
@@ -224,12 +220,9 @@ public class WebSocket extends EventDispatcher {
}
private function onError(message:String):void {
- var state:int = readyState;
- if (state == CLOSED) return;
+ if (readyState == CLOSED) return;
main.error(message);
-
- this.dispatchEvent(new WebSocketEvent(WebSocketEvent.ERROR, encodeURIComponent(message)));
- close();
+ close(readyState != CONNECTING);
}
private function onSocketData(event:ProgressEvent):void {
@@ -264,7 +257,7 @@ public class WebSocket extends EventDispatcher {
removeBufferBefore(pos + 1);
pos = -1;
readyState = OPEN;
- this.dispatchEvent(new WebSocketEvent(WebSocketEvent.OPEN));
+ this.dispatchEvent(new WebSocketEvent("open"));
}
} else {
if (buffer[pos] == 0xff && pos > 0) {
@@ -274,7 +267,7 @@ public class WebSocket extends EventDispatcher {
}
var data:String = readUTFBytes(buffer, 1, pos - 1);
main.log("received: " + data);
- this.dispatchEvent(new WebSocketEvent(WebSocketEvent.MESSAGE, encodeURIComponent(data)));
+ this.dispatchEvent(new WebSocketEvent("message", encodeURIComponent(data)));
removeBufferBefore(pos + 1);
pos = -1;
} else if (pos == 1 && buffer[0] == 0xff && buffer[1] == 0x00) { // closing
View
65 flash-src/WebSocketEvent.as
@@ -1,32 +1,33 @@
-package
-{
- import flash.events.Event;
-
- /**
- * This class represents a generic websocket event. It contains the standard "type"
- * parameter as well as a "message" parameter.
- */
- public class WebSocketEvent extends Event
- {
- public static const OPEN : String = "open";
- public static const CLOSE : String = "close";
- public static const MESSAGE : String = "message";
- public static const ERROR : String = "error";
-
- public var message : String;
-
- public function WebSocketEvent(type:String, inMessage:String=null, bubbles:Boolean=false, cancelable:Boolean=false)
- {
- super(type, bubbles, cancelable);
- this.message = inMessage;
- }
-
- public override function clone() : Event {
- return new WebSocketEvent(this.type, this.message, this.bubbles, this.cancelable);
- }
-
- public override function toString() : String {
- return "WebSocketEvent: " + this.type + ": " + this.message;
- }
- }
-}
+package {
+
+import flash.events.Event;
+
+/**
+ * This class represents a generic websocket event. It contains the standard "type"
+ * parameter as well as a "message" parameter.
+ */
+public class WebSocketEvent extends Event {
+
+ public static const OPEN:String = "open";
+ public static const CLOSE:String = "close";
+ public static const MESSAGE:String = "message";
+ public static const ERROR:String = "error";
+
+ public var message:String;
+
+ public function WebSocketEvent(
+ type:String, message:String = null, bubbles:Boolean = false, cancelable:Boolean = false) {
+ super(type, bubbles, cancelable);
+ this.message = message;
+ }
+
+ public override function clone():Event {
+ return new WebSocketEvent(this.type, this.message, this.bubbles, this.cancelable);
+ }
+
+ public override function toString():String {
+ return "WebSocketEvent: " + this.type + ": " + this.message;
+ }
+}
+
+}
View
288 flash-src/WebSocketMain.as
@@ -4,148 +4,148 @@
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
package {
-
- import bridge.JSBridge;
-
- import flash.display.Sprite;
- import flash.system.Security;
- import flash.utils.setTimeout;
-
- import mx.utils.URLUtil;
-
- public class WebSocketMain extends Sprite {
-
- private var callerUrl:String;
- private var debug:Boolean = false;
- private var manualPolicyFileLoaded:Boolean = false;
- private var jsBridge : JSBridge;
- private var webSockets : Array;
- private var eventQueue : Array;
-
- public function WebSocketMain() {
- this.jsBridge = new JSBridge(this);
- webSockets = new Array();
- eventQueue = new Array();
- jsBridge.flashInitialized();
- }
-
- /*************
- * Initialization / Utility methods
- */
-
- public function setCallerUrl(url:String):void {
- callerUrl = url;
- }
-
- public function setDebug(val:Boolean):void {
- debug = val;
- }
-
- public function getOrigin():String {
- return (URLUtil.getProtocol(this.callerUrl) + "://" +
- URLUtil.getServerNameWithPort(this.callerUrl)).toLowerCase();
- }
-
- public function getCallerHost():String {
- return URLUtil.getServerName(this.callerUrl);
- }
-
- private function loadDefaultPolicyFile(wsUrl:String):void {
- var policyUrl:String = "xmlsocket://" + URLUtil.getServerName(wsUrl) + ":843";
- log("policy file: " + policyUrl);
- Security.loadPolicyFile(policyUrl);
- }
-
- public function loadManualPolicyFile(policyUrl:String):void {
- log("policy file: " + policyUrl);
- Security.loadPolicyFile(policyUrl);
- manualPolicyFileLoaded = true;
- }
-
- public function log(message:String):void {
- if (debug) {
- jsBridge.log(message);
- }
- }
-
- public function error(message:String):void {
- jsBridge.error(message);
- }
-
- public function fatal(message:String):void {
- jsBridge.error(message);
- }
-
- private function parseEvent(event : WebSocketEvent) : Object {
- var eventObj : Object = new Object();
- var webSocket : WebSocket = event.target as WebSocket;
- eventObj.type = event.type;
- eventObj.webSocketId = webSocket.webSocketId;
- eventObj.readyState = webSocket.readOnly_readyState;
- if (event.message !== null) {
- eventObj.message = event.message;
- }
- return eventObj;
- }
-
- /**
- * Socket interface
- */
- public function create(
- webSocketId : Number,
- url:String, protocol:String,
- proxyHost:String = null, proxyPort:int = 0,
- headers:String = null):void {
- if (!manualPolicyFileLoaded) {
- loadDefaultPolicyFile(url);
- }
- var newSocket : WebSocket = new WebSocket(this, webSocketId, url, protocol, proxyHost, proxyPort, headers);
- newSocket.addEventListener(WebSocketEvent.OPEN, onSocketEvent);
- newSocket.addEventListener(WebSocketEvent.CLOSE, onSocketEvent);
- newSocket.addEventListener(WebSocketEvent.ERROR, onSocketEvent);
- newSocket.addEventListener(WebSocketEvent.MESSAGE, onSocketEvent);
- webSockets[webSocketId] = newSocket;
- }
-
- public function send(webSocketId : Number, encData : String) : int {
- var webSocket : WebSocket = webSockets[webSocketId];
- return webSocket.send(encData);
- }
-
- public function close(webSocketId : Number) : void {
- var webSocket : WebSocket = webSockets[webSocketId];
- webSocket.close();
- }
-
-
- /****************
- * Socket event handler
- */
- public function onSocketEvent(event : WebSocketEvent) : void {
- var eventObj : Object = parseEvent(event);
- eventQueue.push(eventObj);
- setTimeout(processEvents, 1);
- }
-
- /**
- * Process our event queue. If javascript is unresponsive, set
- * a timeout and try again.
- */
- public function processEvents() : void {
- var eventObj : Object;
- var success : Boolean;
- while (eventQueue.length > 0) {
- eventObj = eventQueue[0];
- success = jsBridge.sendEvent(eventObj);
- if (!success) {
- setTimeout(processEvents, 500);
- break;
- } else {
- eventQueue.shift();
- }
- }
- }
-
- }
-
+
+import bridge.JSBridge;
+
+import flash.display.Sprite;
+import flash.system.Security;
+import flash.utils.setTimeout;
+
+import mx.utils.URLUtil;
+
+public class WebSocketMain extends Sprite {
+
+ private var callerUrl:String;
+ private var debug:Boolean = false;
+ private var manualPolicyFileLoaded:Boolean = false;
+ private var jsBridge:JSBridge;
+ private var webSockets:Array;
+ private var eventQueue:Array;
+
+ public function WebSocketMain() {
+ this.jsBridge = new JSBridge(this);
+ webSockets = [];
+ eventQueue = [];
+ jsBridge.flashInitialized();
+ }
+
+ /*************
+ * Initialization / Utility methods
+ */
+
+ public function setCallerUrl(url:String):void {
+ callerUrl = url;
+ }
+
+ public function setDebug(val:Boolean):void {
+ debug = val;
+ }
+
+ public function getOrigin():String {
+ return (URLUtil.getProtocol(this.callerUrl) + "://" +
+ URLUtil.getServerNameWithPort(this.callerUrl)).toLowerCase();
+ }
+
+ public function getCallerHost():String {
+ return URLUtil.getServerName(this.callerUrl);
+ }
+
+ private function loadDefaultPolicyFile(wsUrl:String):void {
+ var policyUrl:String = "xmlsocket://" + URLUtil.getServerName(wsUrl) + ":843";
+ log("policy file: " + policyUrl);
+ Security.loadPolicyFile(policyUrl);
+ }
+
+ public function loadManualPolicyFile(policyUrl:String):void {
+ log("policy file: " + policyUrl);
+ Security.loadPolicyFile(policyUrl);
+ manualPolicyFileLoaded = true;
+ }
+
+ public function log(message:String):void {
+ if (debug) {
+ jsBridge.log(message);
+ }
+ }
+
+ public function error(message:String):void {
+ jsBridge.error(message);
+ }
+
+ public function fatal(message:String):void {
+ jsBridge.error(message);
+ throw message;
+ }
+
+ private function parseEvent(event:WebSocketEvent):Object {
+ var webSocket:WebSocket = event.target as WebSocket;
+ var eventObj:Object = {};
+ eventObj.type = event.type;
+ eventObj.webSocketId = webSocket.getId();
+ eventObj.readyState = webSocket.getReadyState();
+ if (event.message !== null) {
+ eventObj.message = event.message;
+ }
+ return eventObj;
+ }
+
+ /**
+ * Socket interface
+ */
+ public function create(
+ webSocketId:int,
+ url:String, protocol:String,
+ proxyHost:String = null, proxyPort:int = 0,
+ headers:String = null):void {
+ if (!manualPolicyFileLoaded) {
+ loadDefaultPolicyFile(url);
+ }
+ var newSocket:WebSocket = new WebSocket(
+ this, webSocketId, url, protocol, proxyHost, proxyPort, headers);
+ newSocket.addEventListener("open", onSocketEvent);
+ newSocket.addEventListener("close", onSocketEvent);
+ newSocket.addEventListener("error", onSocketEvent);
+ newSocket.addEventListener("message", onSocketEvent);
+ webSockets[webSocketId] = newSocket;
+ }
+
+ public function send(webSocketId:int, encData:String):int {
+ var webSocket:WebSocket = webSockets[webSocketId];
+ return webSocket.send(encData);
+ }
+
+ public function close(webSocketId:int):void {
+ var webSocket:WebSocket = webSockets[webSocketId];
+ webSocket.close();
+ }
+
+ public function receiveEvents():Object {
+ var result:Object = eventQueue;
+ eventQueue = [];
+ return result;
+ }
+
+ /****************
+ * Socket event handler
+ */
+ public function onSocketEvent(event:WebSocketEvent):void {
+ var eventObj:Object = parseEvent(event);
+ eventQueue.push(eventObj);
+ processEvents();
+ }
+
+ /**
+ * Process our event queue. If javascript is unresponsive, set
+ * a timeout and try again.
+ */
+ public function processEvents():void {
+ if (eventQueue.length == 0) return;
+ var success:Boolean = jsBridge.fireEvent();
+ if (!success) {
+ setTimeout(processEvents, 500);
+ }
+ }
+
+}
+
}
View
253 flash-src/bridge/JSBridge.as
@@ -1,127 +1,130 @@
-package bridge
-{
- import flash.external.ExternalInterface;
- import flash.utils.setTimeout;
+package bridge {
+
+import flash.external.ExternalInterface;
+import flash.utils.setTimeout;
+
+/**
+ * This class provides a central location for ExternalInterface
+ * communication between flash and javascript.
+ */
+public class JSBridge {
+
+ private var controller:WebSocketMain;
+ /**
+ * Class constructor.
+ */
+ public function JSBridge(controller:WebSocketMain)
+ {
+ ExternalInterface.addCallback("setCallerUrl", onSetCallerUrl);
+ ExternalInterface.addCallback("setDebug", onSetDebug);
+ ExternalInterface.addCallback("create", onCreate);
+ ExternalInterface.addCallback("send", onSend);
+ ExternalInterface.addCallback("close", onClose);
+ ExternalInterface.addCallback("loadFlashPolicyFile", onLoadFlashPolicyFile);
+ ExternalInterface.addCallback("receiveEvents", onReceiveEvents);
+
+ this.controller = controller;
+ }
+
+ /******************
+ * Inbound calls from javascript
+ ******************/
+
+ /**
+ * Set the url that this websocket is being opened from.
+ * @param callerUrl The url that hosts the web socket request.
+ */
+ public function onSetCallerUrl(callerUrl:String):void {
+ controller.setCallerUrl(callerUrl);
+ }
+
+ /**
+ * Set the debugging state.
+ * @param debug True for debugging, false otherwise.
+ */
+ public function onSetDebug(debug:Boolean):void {
+ controller.setDebug(debug);
+ }
+
+ /**
+ * Create a new websocket.
+ * @param webSocketId Internal id for the new web socket.
+ * @param url URL of the new socket.
+ * @param protocol Protocol for the new socket.
+ * @param proxyHost Host for the new socket.
+ * @param proxyPort Port for the new socket.
+ * @param headers Headers to include in socket communications.
+ */
+ public function onCreate(
+ webSocketId:Number, url:String, protocol:String,
+ proxyHost:String, proxyPort:Number, headers:String):void {
+ controller.create(webSocketId, url, protocol, proxyHost, proxyPort, headers);
+ }
+
+ /**
+ * Send the passed data to through the identified socket.
+ * @param webSocketId Internal id for the target socket.
+ * @param data The data to send through the socket.
+ */
+ public function onSend(webSocketId:Number, data:String):int {
+ return controller.send(webSocketId, data);
+ }
+
+ /**
+ * Close the identified socket.
+ * @param webSocketId Internal id for the target socket.
+ */
+ public function onClose(webSocketId:Number):void {
+ controller.close(webSocketId);
+ }
+
+ /**
+ * Load a flash security policy file with the passed url.
+ * @param policyUrl The url for the policy file to load.
+ */
+ public function onLoadFlashPolicyFile(policyUrl:String):void {
+ setTimeout(controller.loadManualPolicyFile, 1, policyUrl);
+ }
+
+ public function onReceiveEvents():Object {
+ return controller.receiveEvents();
+ }
+
+ /******************
+ * Outbound calls to javascript
+ ******************/
+ /**
+ * Send a log message to javascript.
+ * @param message The log message.
+ */
+ public function log(message:String):void {
+ ExternalInterface.call("WebSocket.__log", encodeURIComponent("[WebSocket] " + message));
+ }
+
+ /**
+ * Send an error message to javascript.
+ * @param message The error message.
+ */
+ public function error(message:String):void {
+ ExternalInterface.call("WebSocket.__error", encodeURIComponent("[WebSocket] " + message));
+ }
+
+ /**
+ * Alert javascript that flash has been initialized and is ready
+ * for communication.
+ */
+ public function flashInitialized():void {
+ ExternalInterface.call("WebSocket.__onFlashInitialized");
+ }
+
+ /**
+ * Notifies JavaScript that some event was fired.
+ * @returns True if javascript acknowledges receipt of the message, returns
+ * false if javascript is unresponsive.
+ */
+ public function fireEvent():Boolean {
+ return ExternalInterface.call("WebSocket.__onFlashEvent") ? true : false;
+ }
+}
- /**
- * This class provides a central location for ExternalInterface
- * communication between flash and javascript.
- */
- public class JSBridge
- {
- private var controller : WebSocketMain;
- /**
- * Class constructor.
- */
- public function JSBridge(webSocketMainRef : WebSocketMain)
- {
- ExternalInterface.addCallback("setCallerUrl", onSetCallerUrl);
- ExternalInterface.addCallback("setDebug", onSetDebug);
- ExternalInterface.addCallback("createWebSocket", onCreateWebSocket);
- ExternalInterface.addCallback("send", onSend);
- ExternalInterface.addCallback("close", onClose);
- ExternalInterface.addCallback("loadFlashPolicyFile", onLoadFlashPolicyFile);
-
- controller = webSocketMainRef;
- }
-
- /******************
- * Inbound calls from javascript
- ******************/
-
- /**
- * Set the url that this websocket is being opened from.
- * @param callerUrl The url that hosts the web socket request.
- */
- public function onSetCallerUrl(callerUrl : String) : void {
- controller.setCallerUrl(callerUrl);
- }
-
- /**
- * Set the debugging state.
- * @param debug True for debugging, false otherwise.
- */
- public function onSetDebug(debug : Boolean) : void {
- controller.setDebug(debug);
- }
-
- /**
- * Create a new websocket.
- * @param webSocketId Internal id for the new web socket.
- * @param url URL of the new socket.
- * @param protocol Protocol for the new socket.
- * @param proxyHost Host for the new socket.
- * @param proxyPort Port for the new socket.
- * @param headers Headers to include in socket communications.
- */
- public function onCreateWebSocket(webSocketId : Number, url : String, protocol : String, proxyHost : String, proxyPort : Number, headers : String) : void {
- controller.create(webSocketId, url, protocol, proxyHost, proxyPort, headers);
- }
-
- /**
- * Send the passed data to through the identified socket.
- * @param webSocketId Internal id for the target socket.
- * @param data The data to send through the socket.
- */
- public function onSend(webSocketId : Number, data : String) : int {
- return controller.send(webSocketId, data);
- }
-
- /**
- * Close the identified socket.
- * @param webSocketId Internal id for the target socket.
- */
- public function onClose(webSocketId : Number) : void {
- controller.close(webSocketId);
- }
-
- /**
- * Load a flash security policy file with the passed url.
- * @param policyUrl The url for the policy file to load.
- */
- public function onLoadFlashPolicyFile(policyUrl : String) : void {
- setTimeout(controller.loadManualPolicyFile, 1, policyUrl);
- }
-
- /******************
- * Outbound calls to javascript
- ******************/
- /**
- * Send a log message to javascript.
- * @param message The log message.
- */
- public function log(message:String) : void {
- setTimeout(ExternalInterface.call, 1, "webSocketLog", encodeURIComponent("[WebSocket] " + message));
- }
-
- /**
- * Send an error message to javascript.
- * @param message The error message.
- */
- public function error(message:String) : void {
- setTimeout(ExternalInterface.call, 1, "webSocketError", encodeURIComponent("[WebSocket] " + message));
- }
-
- /**
- * Alert javascript that flash has been initialized and is ready
- * for communication.
- */
- public function flashInitialized() : void {
- ExternalInterface.call("wsController.flashInitialized");
- }
-
- /**
- * Send a WebSocket message to javascript.
- * @param eventObj A base Object containing the message addressing and contents:
- * {webSocketId : event source socket,
- * type : event type ["open" | "close" | "error" | "message"],
- * readyState : current ready state of the source socket,
- * message : encoded message string
- * @returns True if javascript acknowledges receipt of the message, returns
- * false if javascript is unresponsive.
- */
- public function sendEvent(eventObj : Object) : Boolean {
- return ExternalInterface.call("wsController.flashEvent", eventObj) as Boolean;
- }
- }
}
View
0  sample.html 100755 → 100644
File mode changed
View
832 web_socket.js 100755 → 100644
@@ -23,497 +23,391 @@
"Open the page via Web server i.e. http://...");
}
+ /**
+ * This class represents a faux web socket.
+ * @param {string} url
+ * @param {string} protocol
+ * @param {string} proxyHost
+ * @param {int} proxyPort
+ * @param {string} headers
+ */
WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
var self = this;
+ self.__id = WebSocket.__nextId++;
+ WebSocket.__instances[self.__id] = self;
self.readyState = WebSocket.CONNECTING;
self.bufferedAmount = 0;
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
// Otherwise, when onopen fires immediately, onopen is called before it is set.
setTimeout(function() {
WebSocket.__addTask(function() {
- self.__createFlash(url, protocol, proxyHost, proxyPort, headers);
+ WebSocket.__flash.create(
+ self.__id, url, protocol, proxyHost || null, proxyPort || 0, headers || null);
});
}, 0);
};
-
- WebSocketController = function() {
- this._webSockets = {};
- this._initializing = false;
- this._initialized = false;
- this._currentWebSocketId = 0;
- this._flashObj = null;
- };
-
- /**
- * Load and initialize the flash
- * mock web socket.
- */
- WebSocketController.prototype.init = function() {
- if (this._initialized || this._initializing) {
- return;
- }
- this._initializing = true;
-
- if (WebSocket.__swfLocation) {
- // For backword compatibility.
- window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
- }
- if (!window.WEB_SOCKET_SWF_LOCATION) {
- console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
- return;
- }
- var container = document.createElement("div");
- container.id = "webSocketContainer";
- // Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
- // Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
- // But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
- // Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
- // the best we can do as far as we know now.
- container.style.position = "absolute";
- if (this.__isFlashLite()) {
- container.style.left = "0px";
- container.style.top = "0px";
- } else {
- container.style.left = "-100px";
- container.style.top = "-100px";
- }
- var holder = document.createElement("div");
- holder.id = "webSocketFlash";
- container.appendChild(holder);
- document.body.appendChild(container);
- // See this article for hasPriority:
- // http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
- swfobject.embedSWF(
- WEB_SOCKET_SWF_LOCATION,
- "webSocketFlash",
- "1" /* width */,
- "1" /* height */,
- "10.0.0" /* SWF version */,
- null,
- null,
- {hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
- null,
- function(e) {
- if (!e.success) {
- console.error("[WebSocket] swfobject.embedSWF failed");
- }
- });
- };
-
- /**
- * Called by flash to notify js that it's fully loaded and ready
- * for communication.
- */
- WebSocketController.prototype.flashInitialized = function() {
- //We need to set a timeout here to avoid round-trip calls
- //to flash during the initialization process.
- setTimeout(function() {
- wsController._onFlashInitialized();
- }, 0);
- };
-
- /**
- * Method called once flash is ready for communication.
- */
- WebSocketController.prototype._onFlashInitialized = function() {
- var webSocket;
-
- this._initialized = true;
- this._flashObj = document.getElementById('webSocketFlash');
- this._flashObj.setCallerUrl(location.href);
- this._flashObj.setDebug(!!window.WEB_SOCKET_DEBUG);
-
- //If we have any policy files waiting to be loaded, load them.
- if (this._policyUrls) {
- var i = this._policyUrls.length;
- while (i-->0) {
- this._flashObj.loadFlashPolicyFile(this._policyUrls[i]);
- }
- }
-
- //If we have any websockets ready to go, initialize them.
- for (var webSocketId in this._webSockets) {
- webSocket = this._webSockets[webSocketId];
- this._flashObj.createWebSocket(webSocketId, webSocket.url, webSocket.protocol, webSocket.proxyHost, webSocket.proxyPort, webSocket.headers);
- }
- };
-
- /**
- * Create a new websocket instance in flash and send the new web socket id back
- * to the caller.
- * @param {WebSocket} webSocket The websocket instance handling this web socket.
- * @return {int} The new flash web socket id.
- */
- WebSocketController.prototype.createFlashWebSocket = function(webSocket) {
- var webSocketId = this._currentWebSocketId++;
-
- this._webSockets[webSocketId] = webSocket;
-
- //If the flash component has been initialized, open the web socket connection
- if (this._initialized) {
- this._flashObj.createWebSocket(webSocketId, webSocket.url, webSocket.protocol, webSocket.proxyHost, webSocket.proxyPort, webSocket.headers);
- } else if (!this._initializing) {
- //Load flash swf and initialize
- this.init();
- }
-
- return webSocketId;
- };
-
- /**
- * Send data through the flash socket.
- * @param {int} socketId ID of the web socket to use.
- * @param {string} data Data to send.
- */
- WebSocketController.prototype.send = function(socketId, data) {
- return this._flashObj.send(socketId, data);
- };
-
-
- /**
- * Close the flash socket.
- * @param {int} socketId ID of the web socket to use.
- */
- WebSocketController.prototype.close = function(socketId) {
- return this._flashObj.close(socketId);
- };
-
- /**
- * Test if the browser is running flash lite.
- * @return {boolean} True if flash lite is running, false otherwise.
- */
- WebSocketController.prototype.__isFlashLite = function() {
- if (!window.navigator || !window.navigator.mimeTypes) {
- return false;
- }
- var mimeType = window.navigator.mimeTypes['application/x-shockwave-flash'];
- if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
- return false;
- }
- return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
- };
-
- /**
- * Called by flash to dispatch an event to a web socket.
- * @param {object} eventObj A web socket event dispatched from flash.
- */
- WebSocketController.prototype.flashEvent = function(eventObj) {
- var socketId = eventObj.webSocketId,
- wsEvent = new WebSocketEvent();
-
- wsEvent.initEvent(eventObj.type, true, true);
- wsEvent.readyState = eventObj.readyState;
- wsEvent.message = eventObj.message;
-
- setTimeout(function() {
- wsController.dispatchEvent(socketId, wsEvent);
- }, 0);
-
- return true;
- };
-
- WebSocketController.prototype.dispatchEvent = function(webSocketId, wsEvent) {
- this._webSockets[webSocketId].__handleEvent(wsEvent);
- };
-
- /**
- * Load a new flash security policy file.
- * @param {string} url
- */
- WebSocketController.prototype.loadFlashPolicyFile = function(url){
- if (this._initialized) {
- this._flashObj.loadFlashPolicyFile(url);
- }
- else {
- this._policyUrls = this._policyUrls || [];
- this._policyUrls.push(url);
- }
- };
-
-
-
-
-
- /**
- * This class represents a faux web socket.
- * @param {string} url
- * @param {string} protocol
- * @param {string} proxyHost
- * @param {int} proxyPort
- * @param {string} headers
- */
- WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
- this.url = url;
- this.protocol = protocol;
- this.proxyHost = proxyHost;
- this.headers = headers;
-
- this.readyState = WebSocket.CONNECTING;
- this.bufferedAmount = 0;
- this._socketId = wsController.createFlashWebSocket(this);
- };
- /**
- * Send data to the web socket.
- * @param {string} data The data to send to the socket.
- * @return {boolean} True for success, false for failure.
- */
- WebSocket.prototype.send = function(data) {
- if (this.readyState == WebSocket.CONNECTING) {
- throw "INVALID_STATE_ERR: Web Socket connection has not been established";
- }
- // We use encodeURIComponent() here, because FABridge doesn't work if
- // the argument includes some characters. We don't use escape() here
- // because of this:
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
- // But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
- // preserve all Unicode characters either e.g. "\uffff" in Firefox.
- // Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
- // additional testing.
- var result = wsController.send(this._socketId, encodeURIComponent(data));
- if (result < 0) { // success
- return true;
- } else {
- this.bufferedAmount += result;
- return false;
- }
- };
-
- /**
- * Close this web socket gracefully.
- */
- WebSocket.prototype.close = function() {
- if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
- return;
- }
- this.readyState = WebSocket.CLOSING;
- wsController.close(this._socketId);
- };
+ /**
+ * Send data to the web socket.
+ * @param {string} data The data to send to the socket.
+ * @return {boolean} True for success, false for failure.
+ */
+ WebSocket.prototype.send = function(data) {
+ if (this.readyState == WebSocket.CONNECTING) {
+ throw "INVALID_STATE_ERR: Web Socket connection has not been established";
+ }
+ // We use encodeURIComponent() here, because FABridge doesn't work if
+ // the argument includes some characters. We don't use escape() here
+ // because of this:
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
+ // But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
+ // preserve all Unicode characters either e.g. "\uffff" in Firefox.
+ // Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
+ // additional testing.
+ var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
+ if (result < 0) { // success
+ return true;
+ } else {
+ this.bufferedAmount += result;
+ return false;
+ }
+ };
- /**
- * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
- *
- * @param {string} type
- * @param {function} listener
- * @param {boolean} useCapture !NB Not implemented yet
- * @return void
- */
- WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
- if (!('__events' in this)) {
- this.__events = {};
- }
- if (!(type in this.__events)) {
- this.__events[type] = [];
- if ('function' == typeof this['on' + type]) {
- this.__events[type].defaultHandler = this['on' + type];
- this['on' + type] = this.__createEventHandler(this, type);
- }
- }
- this.__events[type].push(listener);
- };
+ /**
+ * Close this web socket gracefully.
+ */
+ WebSocket.prototype.close = function() {
+ if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
+ return;
+ }
+ this.readyState = WebSocket.CLOSING;
+ WebSocket.__flash.close(this.__id);
+ };
- /**
- * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
- *
- * @param {string} type
- * @param {function} listener
- * @param {boolean} useCapture NB! Not implemented yet
- * @return void
- */
- WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
- if (!('__events' in this)) {
- this.__events = {};
- }
- if (!(type in this.__events)) return;
- for (var i = this.__events.length; i > -1; --i) {
- if (listener === this.__events[type][i]) {
- this.__events[type].splice(i, 1);
- break;
- }
- }
- };
+ /**
+ * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
+ *
+ * @param {string} type
+ * @param {function} listener
+ * @param {boolean} useCapture !NB Not implemented yet
+ * @return void
+ */
+ WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
+ if (!('__events' in this)) {
+ this.__events = {};
+ }
+ if (!(type in this.__events)) {
+ this.__events[type] = [];
+ if ('function' == typeof this['on' + type]) {
+ this.__events[type].defaultHandler = this['on' + type];
+ this['on' + type] = this.__createEventHandler(this, type);
+ }
+ }
+ this.__events[type].push(listener);
+ };
- /**
- * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
- *
- * @param {WebSocketEvent} event
- * @return void
- */
- WebSocket.prototype.dispatchEvent = function(event) {
- if (!('__events' in this)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
- if (!(event.type in this.__events)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
-
- for (var i = 0, l = this.__events[event.type].length; i < l; ++ i) {
- this.__events[event.type][i](event);
- if (event.cancelBubble) break;
- }
-
- if (false !== event.returnValue &&
- 'function' == typeof this.__events[event.type].defaultHandler)
- {
- this.__events[event.type].defaultHandler(event);
- }
- };
+ /**
+ * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
+ *
+ * @param {string} type
+ * @param {function} listener
+ * @param {boolean} useCapture NB! Not implemented yet
+ * @return void
+ */
+ WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
+ if (!('__events' in this)) {
+ this.__events = {};
+ }
+ if (!(type in this.__events)) return;
+ for (var i = this.__events.length; i > -1; --i) {
+ if (listener === this.__events[type][i]) {
+ this.__events[type].splice(i, 1);
+ break;
+ }
+ }
+ };
- /**
- * Handle an event from flash. Do any websocket-specific
- * handling before passing the event off to the event handlers.
- * @param {Object} event
- */
- WebSocket.prototype.__handleEvent = function(event) {
- // Gets events using receiveEvents() instead of getting it from event object
- // of Flash event. This is to make sure to keep message order.
- // It seems sometimes Flash events don't arrive in the same order as they are sent.
- if (event.readyState >= 0) {
- this.readyState = event.readyState;
- }
-
- try {
- if (event.type == "open" && this.onopen) {
- this.onopen();
- } else if (event.type == "close" && this.onclose) {
- this.onclose();
- } else if (event.type == "error" && this.onerror) {
- this.onerror(event);
- } else if (event.type == "message") {
- if (this.onmessage) {
- var data = decodeURIComponent(event.message);
- var e;
- if (window.MessageEvent && !window.opera) {
- e = document.createEvent("MessageEvent");
- e.initMessageEvent("message", false, false, data, null, null, window, null);
- } else {
- // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
- e = {data: data};
- }
- this.onmessage(e);
- }
-
- } else {
- throw "unknown event type: " + event.type;
- }
- } catch (e) {
- console.error(e.toString());
- }
- };
+ /**
+ * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
+ *
+ * @param {WebSocketEvent} event
+ * @return void
+ */
+ WebSocket.prototype.dispatchEvent = function(event) {
+ if (!('__events' in this)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
+ if (!(event.type in this.__events)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
- /**
- * @param {object} object
- * @param {string} type
- */
- WebSocket.prototype.__createEventHandler = function(object, type) {
- return function(data) {
- var event = new WebSocketEvent();
- event.initEvent(type, true, true);
- event.target = event.currentTarget = object;
- for (var key in data) {
- event[key] = data[key];
- }
- object.dispatchEvent(event, arguments);
- };
- };
-
- /**
- * Load the specified flash security policy file.
- * NOTE: This should be called prior to instantiating any WebSockets.
- * @param {string} url URL to the remote policy file.
- */
- WebSocket.loadFlashPolicyFile = function(url) {
- wsController.loadFlashPolicyFile(url);
- };
+ for (var i = 0, l = this.__events[event.type].length; i < l; ++ i) {
+ this.__events[event.type][i](event);
+ if (event.cancelBubble) break;
+ }
+
+ if (false !== event.returnValue &&
+ 'function' == typeof this.__events[event.type].defaultHandler)
+ {
+ this.__events[event.type].defaultHandler(event);
+ }
+ };
- /**
- * Define the WebSocket readyState enumeration.
- */
- WebSocket.CONNECTING = 0;
- WebSocket.OPEN = 1;
- WebSocket.CLOSING = 2;
- WebSocket.CLOSED = 3;
+ /**
+ * Handle an event from flash. Do any websocket-specific
+ * handling before passing the event off to the event handlers.
+ * @param {Object} event
+ */
+ WebSocket.prototype.__handleEvent = function(event) {
+ if ("readyState" in event) {
+ this.readyState = event.readyState;
+ }
+
+ try {
+ if (event.type == "open" && this.onopen) {
+ this.onopen();
+ } else if (event.type == "close" && this.onclose) {
+ this.onclose();
+ } else if (event.type == "error" && this.onerror) {
+ this.onerror(event);
+ } else if (event.type == "message") {
+ if (this.onmessage) {
+ var data = decodeURIComponent(event.message);
+ var e;
+ if (window.MessageEvent && !window.opera) {
+ e = document.createEvent("MessageEvent");
+ e.initMessageEvent("message", false, false, data, null, null, window, null);
+ } else {
+ // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
+ e = {data: data};
+ }
+ this.onmessage(e);
+ }
+
+ } else {
+ throw "unknown event type: " + event.type;
+ }
+ } catch (e) {
+ console.error(e.toString());
+ }
+ };
+
+ /**
+ * @param {object} object
+ * @param {string} type
+ */
+ WebSocket.prototype.__createEventHandler = function(object, type) {
+ return function(data) {
+ var event = new WebSocketEvent();
+ event.initEvent(type, true, true);
+ event.target = event.currentTarget = object;
+ for (var key in data) {
+ event[key] = data[key];
+ }
+ object.dispatchEvent(event, arguments);
+ };
+ };
- /**
- * Basic implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface">DOM 2 EventInterface</a>}
- *
- * @class
- * @constructor
- */
- function WebSocketEvent(){}
-
- /**
- * @type int WebSocket state enumeration
- */
- WebSocketEvent.prototype.readyState = -1;
-
- /**
- * @type string message received from the flash socket.
- */
- WebSocketEvent.prototype.message = null;
-
- /**
- *
- * @type boolean
- */
- WebSocketEvent.prototype.cancelable = true;
-
- /**
- *
- * @type boolean
- */
- WebSocketEvent.prototype.cancelBubble = false;
-
- /**
- *
- * @return void
- */
- WebSocketEvent.prototype.preventDefault = function() {
- if (this.cancelable) {
- this.returnValue = false;
- }
- };
-
- /**
- *
- * @return void
- */
- WebSocketEvent.prototype.stopPropagation = function() {
- this.cancelBubble = true;
- };
+ /**
+ * Define the WebSocket readyState enumeration.
+ */
+ WebSocket.CONNECTING = 0;
+ WebSocket.OPEN = 1;
+ WebSocket.CLOSING = 2;
+ WebSocket.CLOSED = 3;
- /**
- *
- * @param {string} eventTypeArg
- * @param {boolean} canBubbleArg
- * @param {boolean} cancelableArg
- * @return void
- */
- WebSocketEvent.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg) {
- this.type = eventTypeArg;
- this.cancelable = cancelableArg;
- this.timeStamp = new Date();
- };
+ WebSocket.__flash = null;
+ WebSocket.__instances = {};
+ WebSocket.__tasks = [];
+ WebSocket.__nextId = 0;
+
+ /**
+ * Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
+ */
+ WebSocket.__initialize = function() {
+ if (WebSocket.__flash) return;
+
+ if (WebSocket.__swfLocation) {
+ // For backword compatibility.
+ window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
+ }
+ if (!window.WEB_SOCKET_SWF_LOCATION) {
+ console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
+ return;
+ }
+ var container = document.createElement("div");
+ container.id = "webSocketContainer";
+ // Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
+ // Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
+ // But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
+ // Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
+ // the best we can do as far as we know now.
+ container.style.position = "absolute";
+ if (WebSocket.__isFlashLite()) {
+ container.style.left = "0px";
+ container.style.top = "0px";
+ } else {
+ container.style.left = "-100px";
+ container.style.top = "-100px";
+ }
+ var holder = document.createElement("div");
+ holder.id = "webSocketFlash";
+ container.appendChild(holder);
+ document.body.appendChild(container);
+ // See this article for hasPriority:
+ // http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
+ swfobject.embedSWF(
+ WEB_SOCKET_SWF_LOCATION,
+ "webSocketFlash",
+ "1" /* width */,
+ "1" /* height */,
+ "10.0.0" /* SWF version */,
+ null,
+ null,
+ {hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
+ null,
+ function(e) {
+ if (!e.success) {
+ console.error("[WebSocket] swfobject.embedSWF failed");
+ }
+ });
+ };
+
+ /**
+ * Load a new flash security policy file.
+ * @param {string} url
+ */
+ WebSocket.loadFlashPolicyFile = function(url){
+ WebSocket.__addTask(function() {
+ WebSocket.__flash.loadFlashPolicyFile(url);
+ });
+ };
+ /**
+ * Called by flash to notify js that it's fully loaded and ready
+ * for communication.
+ */
+ WebSocket.__onFlashInitialized = function() {
+ // We need to set a timeout here to avoid round-trip calls
+ // to flash during the initialization process.
+ setTimeout(function() {
+ WebSocket.__flash = document.getElementById("webSocketFlash");
+ WebSocket.__flash.setCallerUrl(location.href);
+ WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
+ for (var i = 0; i < WebSocket.__tasks.length; ++i) {
+ WebSocket.__tasks[i]();
+ }
+ WebSocket.__tasks = [];
+ }, 0);
+ };
+
+ /**
+ * Called by flash to dispatch an event to a web socket.
+ * @param {object} eventObj A web socket event dispatched from flash.
+ */
+ WebSocket.__onFlashEvent = function() {
+ setTimeout(function() {
+ // Gets events using receiveEvents() instead of getting it from event object
+ // of Flash event. This is to make sure to keep message order.
+ // It seems sometimes Flash events don't arrive in the same order as they are sent.
+ var events = WebSocket.__flash.receiveEvents();
+ for (var i = 0; i < events.length; ++i) {
+ WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
+ }
+ }, 0);
+ return true;
+ };
+
+ // called from Flash
+ WebSocket.__log = function(message) {
+ console.log(decodeURIComponent(message));
+ };
+
+ // called from Flash
+ WebSocket.__error = function(message) {
+ console.error(decodeURIComponent(message));
+ };
+
+ WebSocket.__addTask = function(task) {
+ if (WebSocket.__flash) {
+ task();
+ } else {
+ WebSocket.__tasks.push(task);
+ }
+ };
+
+ /**
+ * Test if the browser is running flash lite.
+ * @return {boolean} True if flash lite is running, false otherwise.
+ */
+ WebSocket.__isFlashLite = function() {
+ if (!window.navigator || !window.navigator.mimeTypes) {
+ return false;
+ }
+ var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
+ if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
+ return false;
+ }
+ return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
+ };
+
+ /**
+ * Basic implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface">DOM 2 EventInterface</a>}
+ *
+ * @class
+ * @constructor
+ */
+ function WebSocketEvent(){}
+
+ /**
+ *
+ * @type boolean
+ */
+ WebSocketEvent.prototype.cancelable = true;
+
+ /**
+ *
+ * @type boolean
+ */
+ WebSocketEvent.prototype.cancelBubble = false;
+
+ /**
+ *
+ * @return void
+ */
+ WebSocketEvent.prototype.preventDefault = function() {
+ if (this.cancelable) {
+ this.returnValue = false;
+ }
+ };
+
+ /**
+ *
+ * @return void
+ */
+ WebSocketEvent.prototype.stopPropagation = function() {
+ this.cancelBubble = true;
+ };
- window.wsController = new WebSocketController();
+ /**
+ *
+ * @param {string} eventTypeArg
+ * @param {boolean} canBubbleArg
+ * @param {boolean} cancelableArg
+ * @return void
+ */
+ WebSocketEvent.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg) {
+ this.type = eventTypeArg;
+ this.cancelable = cancelableArg;
+ this.timeStamp = new Date();
+ };
- // called from Flash
- window.webSocketLog = function(message) {
- console.log(decodeURIComponent(message));
- };
-
- // called from Flash
- window.webSocketError = function(message) {
- console.error(decodeURIComponent(message));
- };
-
- if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
- if (window.addEventListener) {
- window.addEventListener("load", function(){
- wsController.init();
- }, false);
- } else {
- window.attachEvent("onload", function(){
- wsController.init();
- });
- }
- }
+ if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
+ if (window.addEventListener) {
+ window.addEventListener("load", function(){
+ WebSocket.__initialize();
+ }, false);
+ } else {
+ window.attachEvent("onload", function(){
+ WebSocket.__initialize();
+ });
+ }
+ }
})();
Please sign in to comment.
Something went wrong with that request. Please try again.