Permalink
Browse files

easyWebSocket-node.js: removed a forEach for ie8 compatibility

  • Loading branch information...
1 parent 82a0723 commit 8e518b9ec956e54f21093a9ab762cef78d5c77a1 @jeromeetienne committed Feb 28, 2011
Showing with 7 additions and 8 deletions.
  1. +1 −1 easyWebSocket-node.min.js
  2. +1 −1 easyWebSocket.min.js
  3. +1 −1 example/devel-node.html
  4. +4 −5 node/easyWebSocket-node.js
View
2 easyWebSocket-node.min.js
@@ -101,7 +101,7 @@ function(b,e){return function(g){var l=new a;l.initEvent(e,true,true);l.target=l
2;WebSocket.CLOSED=3;WebSocket.__tasks=[];WebSocket.loadFlashPolicyFile=function(b){WebSocket.__addTask(function(){WebSocket.__flash.loadManualPolicyFile(b)})};WebSocket.__initialize=function(){if(WebSocket.__swfLocation)window.WEB_SOCKET_SWF_LOCATION=WebSocket.__swfLocation;if(window.WEB_SOCKET_SWF_LOCATION){var b=document.createElement("div");b.id="webSocketContainer";b.style.position="absolute";if(WebSocket.__isFlashLite()){b.style.left="0px";b.style.top="0px"}else{b.style.left="-100px";b.style.top=
"-100px"}var e=document.createElement("div");e.id="webSocketFlash";b.appendChild(e);document.body.appendChild(b);swfobject.embedSWF(WEB_SOCKET_SWF_LOCATION,"webSocketFlash","1","1","9.0.0",null,{bridgeName:"webSocket"},{hasPriority:true,allowScriptAccess:"always"},null,function(g){g.success||c.error("[WebSocket] swfobject.embedSWF failed")});FABridge.addInitializationCallback("webSocket",function(){try{WebSocket.__flash=FABridge.webSocket.root();WebSocket.__flash.setCallerUrl(location.href);WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
for(var g=0;g<WebSocket.__tasks.length;++g)WebSocket.__tasks[g]();WebSocket.__tasks=[]}catch(l){c.error("[WebSocket] "+l.toString())}})}else c.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf")};WebSocket.__addTask=function(b){WebSocket.__flash?b():WebSocket.__tasks.push(b)};WebSocket.__isFlashLite=function(){if(!window.navigator||!window.navigator.mimeTypes)return false;var b=window.navigator.mimeTypes["application/x-shockwave-flash"];if(!b||!b.enabledPlugin||!b.enabledPlugin.filename)return false;
-return b.enabledPlugin.filename.match(/flashlite/i)?true:false};window.webSocketLog=function(b){c.log(decodeURIComponent(b))};window.webSocketError=function(b){c.error(decodeURIComponent(b))};window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION||(window.addEventListener?window.addEventListener("load",WebSocket.__initialize,false):window.attachEvent("onload",WebSocket.__initialize))}else c.error("Flash Player is not installed.")}})();EasyWebSocket=function(a){var c=this;this.url=a;this.bufferedAmount=0;this.readyState=EasyWebSocket.CONNECTING;this._clientId="clientid-sio-"+this.url+"-"+Math.floor(Math.random()*999999).toString(36);this.log=EasyWebSocket.logFunction;["onopen","onmessage","onerror","onclode"].forEach(function(b){c[b]=function(){c.log("default "+b+" method")}});this._sioCtor()};
+return b.enabledPlugin.filename.match(/flashlite/i)?true:false};window.webSocketLog=function(b){c.log(decodeURIComponent(b))};window.webSocketError=function(b){c.error(decodeURIComponent(b))};window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION||(window.addEventListener?window.addEventListener("load",WebSocket.__initialize,false):window.attachEvent("onload",WebSocket.__initialize))}else c.error("Flash Player is not installed.")}})();EasyWebSocket=function(a){this.url=a;this.bufferedAmount=0;this.readyState=EasyWebSocket.CONNECTING;this._clientId="clientid-sio-"+this.url+"-"+Math.floor(Math.random()*999999).toString(36);this.log=EasyWebSocket.logFunction;a=["onopen","onmessage","onerror","onclode"];for(var c=0;c<a.length;c++){var b=a[c];this[b]=function(){this.log("default "+b+" method")}}this._sioCtor()};
EasyWebSocket.prototype._sioCtor=function(){var a=this.parseUri(EasyWebSocket.serverUrl),c=a.host;a=parseInt(a.port);this._sockio=new io.Socket(c,{port:a,rememberTransport:false});this._sockio.connect();this._sockio.on("connect",function(){console.log("socket connected",this._sockio,this._clientId);this._sockio.send({type:"connect",data:{wsUrl:this.url,clientId:this._clientId}});this.readyState=EasyWebSocket.CONNECTED;this.onopen()}.bind(this));this._sockio.on("connect_failed",function(){this.onerror()}.bind(this));
this._sockio.on("message",function(b){console.log("received message",b);this.onmessage({data:b})}.bind(this));this._sockio.on("disconnect",function(){console.log("socket disconnected");this.onclose()}.bind(this))};EasyWebSocket.prototype.send=function(a){this._sockio.send({type:"message",data:{clientId:this._clientId,message:a}})};EasyWebSocket.prototype.close=function(){this._sockio.disconnect()};EasyWebSocket.CONNECTING=0;EasyWebSocket.OPEN=1;EasyWebSocket.CLOSING=2;EasyWebSocket.CLOSED=3;
EasyWebSocket.serverUrl="http://88.191.76.230:8667";EasyWebSocket.logFunction=function(){};EasyWebSocket.prototype.parseUri=function a(c){var b=a.options;c=b.parser[b.strictMode?"strict":"loose"].exec(c);for(var e={},g=14;g--;)e[b.key[g]]=c[g]||"";e[b.q.name]={};e[b.key[12]].replace(b.q.parser,function(l,q,o){if(q)e[b.q.name][q]=o});return e};
View
2 easyWebSocket.min.js
@@ -101,7 +101,7 @@ function(b,e){return function(g){var l=new a;l.initEvent(e,true,true);l.target=l
2;WebSocket.CLOSED=3;WebSocket.__tasks=[];WebSocket.loadFlashPolicyFile=function(b){WebSocket.__addTask(function(){WebSocket.__flash.loadManualPolicyFile(b)})};WebSocket.__initialize=function(){if(WebSocket.__swfLocation)window.WEB_SOCKET_SWF_LOCATION=WebSocket.__swfLocation;if(window.WEB_SOCKET_SWF_LOCATION){var b=document.createElement("div");b.id="webSocketContainer";b.style.position="absolute";if(WebSocket.__isFlashLite()){b.style.left="0px";b.style.top="0px"}else{b.style.left="-100px";b.style.top=
"-100px"}var e=document.createElement("div");e.id="webSocketFlash";b.appendChild(e);document.body.appendChild(b);swfobject.embedSWF(WEB_SOCKET_SWF_LOCATION,"webSocketFlash","1","1","9.0.0",null,{bridgeName:"webSocket"},{hasPriority:true,allowScriptAccess:"always"},null,function(g){g.success||c.error("[WebSocket] swfobject.embedSWF failed")});FABridge.addInitializationCallback("webSocket",function(){try{WebSocket.__flash=FABridge.webSocket.root();WebSocket.__flash.setCallerUrl(location.href);WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
for(var g=0;g<WebSocket.__tasks.length;++g)WebSocket.__tasks[g]();WebSocket.__tasks=[]}catch(l){c.error("[WebSocket] "+l.toString())}})}else c.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf")};WebSocket.__addTask=function(b){WebSocket.__flash?b():WebSocket.__tasks.push(b)};WebSocket.__isFlashLite=function(){if(!window.navigator||!window.navigator.mimeTypes)return false;var b=window.navigator.mimeTypes["application/x-shockwave-flash"];if(!b||!b.enabledPlugin||!b.enabledPlugin.filename)return false;
-return b.enabledPlugin.filename.match(/flashlite/i)?true:false};window.webSocketLog=function(b){c.log(decodeURIComponent(b))};window.webSocketError=function(b){c.error(decodeURIComponent(b))};window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION||(window.addEventListener?window.addEventListener("load",WebSocket.__initialize,false):window.attachEvent("onload",WebSocket.__initialize))}else c.error("Flash Player is not installed.")}})();EasyWebSocket=function(a){var c=this;this.url=a;this.bufferedAmount=0;this.readyState=EasyWebSocket.CONNECTING;this._clientId="clientid-sio-"+this.url+"-"+Math.floor(Math.random()*999999).toString(36);this.log=EasyWebSocket.logFunction;["onopen","onmessage","onerror","onclode"].forEach(function(b){c[b]=function(){c.log("default "+b+" method")}});this._sioCtor()};
+return b.enabledPlugin.filename.match(/flashlite/i)?true:false};window.webSocketLog=function(b){c.log(decodeURIComponent(b))};window.webSocketError=function(b){c.error(decodeURIComponent(b))};window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION||(window.addEventListener?window.addEventListener("load",WebSocket.__initialize,false):window.attachEvent("onload",WebSocket.__initialize))}else c.error("Flash Player is not installed.")}})();EasyWebSocket=function(a){this.url=a;this.bufferedAmount=0;this.readyState=EasyWebSocket.CONNECTING;this._clientId="clientid-sio-"+this.url+"-"+Math.floor(Math.random()*999999).toString(36);this.log=EasyWebSocket.logFunction;a=["onopen","onmessage","onerror","onclode"];for(var c=0;c<a.length;c++){var b=a[c];this[b]=function(){this.log("default "+b+" method")}}this._sioCtor()};
EasyWebSocket.prototype._sioCtor=function(){var a=this.parseUri(EasyWebSocket.serverUrl),c=a.host;a=parseInt(a.port);this._sockio=new io.Socket(c,{port:a,rememberTransport:false});this._sockio.connect();this._sockio.on("connect",function(){console.log("socket connected",this._sockio,this._clientId);this._sockio.send({type:"connect",data:{wsUrl:this.url,clientId:this._clientId}});this.readyState=EasyWebSocket.CONNECTED;this.onopen()}.bind(this));this._sockio.on("connect_failed",function(){this.onerror()}.bind(this));
this._sockio.on("message",function(b){console.log("received message",b);this.onmessage({data:b})}.bind(this));this._sockio.on("disconnect",function(){console.log("socket disconnected");this.onclose()}.bind(this))};EasyWebSocket.prototype.send=function(a){this._sockio.send({type:"message",data:{clientId:this._clientId,message:a}})};EasyWebSocket.prototype.close=function(){this._sockio.disconnect()};EasyWebSocket.CONNECTING=0;EasyWebSocket.OPEN=1;EasyWebSocket.CLOSING=2;EasyWebSocket.CLOSED=3;
EasyWebSocket.serverUrl="http://88.191.76.230:8667";EasyWebSocket.logFunction=function(){};EasyWebSocket.prototype.parseUri=function a(c){var b=a.options;c=b.parser[b.strictMode?"strict":"loose"].exec(c);for(var e={},g=14;g--;)e[b.key[g]]=c[g]||"";e[b.q.name]={};e[b.key[12]].replace(b.q.parser,function(l,q,o){if(q)e[b.q.name][q]=o});return e};
View
2 example/devel-node.html
@@ -9,7 +9,7 @@
<script>
var basicTest = function(){
// setup EasyWebSocket for local server + loggin
- //EasyWebSocket.serverUrl = "http://127.0.0.1:8667";
+ EasyWebSocket.serverUrl = "http://127.0.0.1:8667";
EasyWebSocket.logFunction = function(){ console.log.apply(console, arguments) }
var url = "ws://example.com/superwa/wa"
View
9 node/easyWebSocket-node.js
@@ -28,11 +28,10 @@ EasyWebSocket = function(url, protocols)
this.log = EasyWebSocket.logFunction;
// init default binding
- ["onopen", "onmessage", "onerror", "onclode"].forEach(function(method){
- self[method] = function(){
- self.log("default "+method+" method")
- }
- })
+ this["onopen"] = function(){ self.log("default onopen method"); }
+ this["onmessage"] = function(){ self.log("default onmessage method"); }
+ this["onerror"] = function(){ self.log("default onerror method"); }
+ this["onclose"] = function(){ self.log("default onclose method"); }
// create socket.io client
this._sioCtor();
}

0 comments on commit 8e518b9

Please sign in to comment.