socky-client-rails 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -1
- data/README.md +1 -1
- data/VERSION +1 -1
- data/assets/socky.js +1000 -518
- metadata +4 -4
data/assets/socky.js
CHANGED
@@ -1,131 +1,613 @@
|
|
1
|
-
/**
|
2
|
-
* Socky push-server JavaScript client
|
3
|
-
*
|
4
|
-
* @version 0.4.
|
5
|
-
* @author Bernard Potocki <bernard.potocki@imanel.org>
|
6
|
-
* @license The MIT license.
|
7
|
-
* @source http://github.com/socky/socky-js
|
8
|
-
*
|
9
|
-
*/
|
10
|
-
|
11
|
-
// Set URL of your WebSocketMain.swf here:
|
12
|
-
WEB_SOCKET_SWF_LOCATION = "
|
13
|
-
// Set this to dump debug message from Flash to console.log:
|
14
|
-
WEB_SOCKET_DEBUG = false;
|
15
|
-
|
16
|
-
Socky = function(host, port, params) {
|
17
|
-
this.host = host;
|
18
|
-
this.port = port;
|
19
|
-
this.params = params;
|
20
|
-
this.connect();
|
21
|
-
};
|
22
|
-
|
23
|
-
// Socky states
|
24
|
-
Socky.CONNECTING = 0;
|
25
|
-
Socky.AUTHENTICATING = 1;
|
26
|
-
Socky.OPEN = 2;
|
27
|
-
Socky.CLOSED = 3;
|
28
|
-
Socky.UNAUTHENTICATED = 4;
|
29
|
-
|
30
|
-
Socky.prototype.connect = function() {
|
31
|
-
var instance = this;
|
32
|
-
instance.state = Socky.CONNECTING;
|
33
|
-
|
34
|
-
var ws = new WebSocket(this.host + ':' + this.port + '/?' + this.params);
|
35
|
-
ws.onopen = function() { instance.onopen(); };
|
36
|
-
ws.onmessage = function(evt) { instance.onmessage(evt); };
|
37
|
-
ws.onclose = function() { instance.onclose(); };
|
38
|
-
ws.onerror = function() { instance.onerror(); };
|
39
|
-
};
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
// ***** Private methods *****
|
44
|
-
// Try to avoid any modification of these methods
|
45
|
-
// Modification of these methods may cause script to work invalid
|
46
|
-
// Please see 'public methods' below
|
47
|
-
// ***************************
|
48
|
-
|
49
|
-
// Called when connection is opened
|
50
|
-
Socky.prototype.onopen = function() {
|
51
|
-
this.state = Socky.AUTHENTICATING;
|
52
|
-
this.respond_to_connect();
|
53
|
-
};
|
54
|
-
|
55
|
-
// Called when socket message is received
|
56
|
-
Socky.prototype.onmessage = function(evt) {
|
57
|
-
try {
|
58
|
-
var request = JSON.parse(evt.data);
|
59
|
-
switch (request.type) {
|
60
|
-
case "message":
|
61
|
-
this.respond_to_message(request.body);
|
62
|
-
break;
|
63
|
-
case "authentication":
|
64
|
-
if(request.body == "success") {
|
65
|
-
this.state = Socky.OPEN;
|
66
|
-
this.respond_to_authentication_success();
|
67
|
-
} else {
|
68
|
-
this.state = Socky.UNAUTHENTICATED;
|
69
|
-
this.respond_to_authentication_failure();
|
70
|
-
}
|
71
|
-
break;
|
72
|
-
}
|
73
|
-
} catch (e) {
|
74
|
-
console.error(e.toString());
|
75
|
-
}
|
76
|
-
};
|
77
|
-
|
78
|
-
// Called when socket connection is closed
|
79
|
-
Socky.prototype.onclose = function() {
|
80
|
-
if(this.state != Socky.CLOSED && this.state != Socky.UNAUTHENTICATED) {
|
81
|
-
this.respond_to_disconnect();
|
82
|
-
}
|
83
|
-
};
|
84
|
-
|
85
|
-
// Called when error occurs
|
86
|
-
// Currently unused
|
87
|
-
Socky.prototype.onerror = function() {};
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
// ***** Public methods *****
|
92
|
-
// These methods can be freely modified.
|
93
|
-
// The change should not affect the normal operation of the script.
|
94
|
-
// **************************
|
95
|
-
|
96
|
-
// Called after connection but before authentication confirmation is received
|
97
|
-
// At this point user is still not allowed to receive messages
|
98
|
-
Socky.prototype.respond_to_connect = function() {
|
99
|
-
};
|
100
|
-
|
101
|
-
// Called when authentication confirmation is received.
|
102
|
-
// At this point user will be able to receive messages
|
103
|
-
Socky.prototype.respond_to_authentication_success = function() {
|
104
|
-
};
|
105
|
-
|
106
|
-
// Called when authentication is rejected by server
|
107
|
-
// This usually means that secret is invalid or that authentication server is unavailable
|
108
|
-
// This method will NOT be called if connection with Socky server will be broken - see respond_to_disconnect
|
109
|
-
Socky.prototype.respond_to_authentication_failure = function() {
|
110
|
-
};
|
111
|
-
|
112
|
-
// Called when new message is received
|
113
|
-
// Note that msg is not sanitized - it can be any script received.
|
114
|
-
Socky.prototype.respond_to_message = function(msg) {
|
115
|
-
eval(msg);
|
116
|
-
};
|
117
|
-
|
118
|
-
// Called when connection is broken between client and server
|
119
|
-
// This usually happens when user lost his connection or when Socky server is down.
|
120
|
-
// At default it will try to reconnect after 1 second.
|
121
|
-
Socky.prototype.respond_to_disconnect = function() {
|
122
|
-
var instance = this;
|
123
|
-
setTimeout(function() { instance.connect(); }, 1000);
|
124
|
-
}
|
125
|
-
/*
|
126
|
-
|
127
|
-
|
128
|
-
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
|
1
|
+
/**
|
2
|
+
* Socky push-server JavaScript client
|
3
|
+
*
|
4
|
+
* @version 0.4.1
|
5
|
+
* @author Bernard Potocki <bernard.potocki@imanel.org>
|
6
|
+
* @license The MIT license.
|
7
|
+
* @source http://github.com/socky/socky-js
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
|
11
|
+
// Set URL of your WebSocketMain.swf here:
|
12
|
+
WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
|
13
|
+
// Set this to dump debug message from Flash to console.log:
|
14
|
+
WEB_SOCKET_DEBUG = false;
|
15
|
+
|
16
|
+
Socky = function(host, port, params) {
|
17
|
+
this.host = host;
|
18
|
+
this.port = port;
|
19
|
+
this.params = params;
|
20
|
+
this.connect();
|
21
|
+
};
|
22
|
+
|
23
|
+
// Socky states
|
24
|
+
Socky.CONNECTING = 0;
|
25
|
+
Socky.AUTHENTICATING = 1;
|
26
|
+
Socky.OPEN = 2;
|
27
|
+
Socky.CLOSED = 3;
|
28
|
+
Socky.UNAUTHENTICATED = 4;
|
29
|
+
|
30
|
+
Socky.prototype.connect = function() {
|
31
|
+
var instance = this;
|
32
|
+
instance.state = Socky.CONNECTING;
|
33
|
+
|
34
|
+
var ws = new WebSocket(this.host + ':' + this.port + '/?' + this.params);
|
35
|
+
ws.onopen = function() { instance.onopen(); };
|
36
|
+
ws.onmessage = function(evt) { instance.onmessage(evt); };
|
37
|
+
ws.onclose = function() { instance.onclose(); };
|
38
|
+
ws.onerror = function() { instance.onerror(); };
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// ***** Private methods *****
|
44
|
+
// Try to avoid any modification of these methods
|
45
|
+
// Modification of these methods may cause script to work invalid
|
46
|
+
// Please see 'public methods' below
|
47
|
+
// ***************************
|
48
|
+
|
49
|
+
// Called when connection is opened
|
50
|
+
Socky.prototype.onopen = function() {
|
51
|
+
this.state = Socky.AUTHENTICATING;
|
52
|
+
this.respond_to_connect();
|
53
|
+
};
|
54
|
+
|
55
|
+
// Called when socket message is received
|
56
|
+
Socky.prototype.onmessage = function(evt) {
|
57
|
+
try {
|
58
|
+
var request = JSON.parse(evt.data);
|
59
|
+
switch (request.type) {
|
60
|
+
case "message":
|
61
|
+
this.respond_to_message(request.body);
|
62
|
+
break;
|
63
|
+
case "authentication":
|
64
|
+
if(request.body == "success") {
|
65
|
+
this.state = Socky.OPEN;
|
66
|
+
this.respond_to_authentication_success();
|
67
|
+
} else {
|
68
|
+
this.state = Socky.UNAUTHENTICATED;
|
69
|
+
this.respond_to_authentication_failure();
|
70
|
+
}
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
} catch (e) {
|
74
|
+
console.error(e.toString());
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
// Called when socket connection is closed
|
79
|
+
Socky.prototype.onclose = function() {
|
80
|
+
if(this.state != Socky.CLOSED && this.state != Socky.UNAUTHENTICATED) {
|
81
|
+
this.respond_to_disconnect();
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
// Called when error occurs
|
86
|
+
// Currently unused
|
87
|
+
Socky.prototype.onerror = function() {};
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// ***** Public methods *****
|
92
|
+
// These methods can be freely modified.
|
93
|
+
// The change should not affect the normal operation of the script.
|
94
|
+
// **************************
|
95
|
+
|
96
|
+
// Called after connection but before authentication confirmation is received
|
97
|
+
// At this point user is still not allowed to receive messages
|
98
|
+
Socky.prototype.respond_to_connect = function() {
|
99
|
+
};
|
100
|
+
|
101
|
+
// Called when authentication confirmation is received.
|
102
|
+
// At this point user will be able to receive messages
|
103
|
+
Socky.prototype.respond_to_authentication_success = function() {
|
104
|
+
};
|
105
|
+
|
106
|
+
// Called when authentication is rejected by server
|
107
|
+
// This usually means that secret is invalid or that authentication server is unavailable
|
108
|
+
// This method will NOT be called if connection with Socky server will be broken - see respond_to_disconnect
|
109
|
+
Socky.prototype.respond_to_authentication_failure = function() {
|
110
|
+
};
|
111
|
+
|
112
|
+
// Called when new message is received
|
113
|
+
// Note that msg is not sanitized - it can be any script received.
|
114
|
+
Socky.prototype.respond_to_message = function(msg) {
|
115
|
+
eval(msg);
|
116
|
+
};
|
117
|
+
|
118
|
+
// Called when connection is broken between client and server
|
119
|
+
// This usually happens when user lost his connection or when Socky server is down.
|
120
|
+
// At default it will try to reconnect after 1 second.
|
121
|
+
Socky.prototype.respond_to_disconnect = function() {
|
122
|
+
var instance = this;
|
123
|
+
setTimeout(function() { instance.connect(); }, 1000);
|
124
|
+
}
|
125
|
+
/*
|
126
|
+
http://www.JSON.org/json2.js
|
127
|
+
2010-08-25
|
128
|
+
|
129
|
+
Public Domain.
|
130
|
+
|
131
|
+
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
132
|
+
|
133
|
+
See http://www.JSON.org/js.html
|
134
|
+
|
135
|
+
|
136
|
+
This code should be minified before deployment.
|
137
|
+
See http://javascript.crockford.com/jsmin.html
|
138
|
+
|
139
|
+
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
140
|
+
NOT CONTROL.
|
141
|
+
|
142
|
+
|
143
|
+
This file creates a global JSON object containing two methods: stringify
|
144
|
+
and parse.
|
145
|
+
|
146
|
+
JSON.stringify(value, replacer, space)
|
147
|
+
value any JavaScript value, usually an object or array.
|
148
|
+
|
149
|
+
replacer an optional parameter that determines how object
|
150
|
+
values are stringified for objects. It can be a
|
151
|
+
function or an array of strings.
|
152
|
+
|
153
|
+
space an optional parameter that specifies the indentation
|
154
|
+
of nested structures. If it is omitted, the text will
|
155
|
+
be packed without extra whitespace. If it is a number,
|
156
|
+
it will specify the number of spaces to indent at each
|
157
|
+
level. If it is a string (such as '\t' or ' '),
|
158
|
+
it contains the characters used to indent at each level.
|
159
|
+
|
160
|
+
This method produces a JSON text from a JavaScript value.
|
161
|
+
|
162
|
+
When an object value is found, if the object contains a toJSON
|
163
|
+
method, its toJSON method will be called and the result will be
|
164
|
+
stringified. A toJSON method does not serialize: it returns the
|
165
|
+
value represented by the name/value pair that should be serialized,
|
166
|
+
or undefined if nothing should be serialized. The toJSON method
|
167
|
+
will be passed the key associated with the value, and this will be
|
168
|
+
bound to the value
|
169
|
+
|
170
|
+
For example, this would serialize Dates as ISO strings.
|
171
|
+
|
172
|
+
Date.prototype.toJSON = function (key) {
|
173
|
+
function f(n) {
|
174
|
+
// Format integers to have at least two digits.
|
175
|
+
return n < 10 ? '0' + n : n;
|
176
|
+
}
|
177
|
+
|
178
|
+
return this.getUTCFullYear() + '-' +
|
179
|
+
f(this.getUTCMonth() + 1) + '-' +
|
180
|
+
f(this.getUTCDate()) + 'T' +
|
181
|
+
f(this.getUTCHours()) + ':' +
|
182
|
+
f(this.getUTCMinutes()) + ':' +
|
183
|
+
f(this.getUTCSeconds()) + 'Z';
|
184
|
+
};
|
185
|
+
|
186
|
+
You can provide an optional replacer method. It will be passed the
|
187
|
+
key and value of each member, with this bound to the containing
|
188
|
+
object. The value that is returned from your method will be
|
189
|
+
serialized. If your method returns undefined, then the member will
|
190
|
+
be excluded from the serialization.
|
191
|
+
|
192
|
+
If the replacer parameter is an array of strings, then it will be
|
193
|
+
used to select the members to be serialized. It filters the results
|
194
|
+
such that only members with keys listed in the replacer array are
|
195
|
+
stringified.
|
196
|
+
|
197
|
+
Values that do not have JSON representations, such as undefined or
|
198
|
+
functions, will not be serialized. Such values in objects will be
|
199
|
+
dropped; in arrays they will be replaced with null. You can use
|
200
|
+
a replacer function to replace those with JSON values.
|
201
|
+
JSON.stringify(undefined) returns undefined.
|
202
|
+
|
203
|
+
The optional space parameter produces a stringification of the
|
204
|
+
value that is filled with line breaks and indentation to make it
|
205
|
+
easier to read.
|
206
|
+
|
207
|
+
If the space parameter is a non-empty string, then that string will
|
208
|
+
be used for indentation. If the space parameter is a number, then
|
209
|
+
the indentation will be that many spaces.
|
210
|
+
|
211
|
+
Example:
|
212
|
+
|
213
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
214
|
+
// text is '["e",{"pluribus":"unum"}]'
|
215
|
+
|
216
|
+
|
217
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
218
|
+
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
219
|
+
|
220
|
+
text = JSON.stringify([new Date()], function (key, value) {
|
221
|
+
return this[key] instanceof Date ?
|
222
|
+
'Date(' + this[key] + ')' : value;
|
223
|
+
});
|
224
|
+
// text is '["Date(---current time---)"]'
|
225
|
+
|
226
|
+
|
227
|
+
JSON.parse(text, reviver)
|
228
|
+
This method parses a JSON text to produce an object or array.
|
229
|
+
It can throw a SyntaxError exception.
|
230
|
+
|
231
|
+
The optional reviver parameter is a function that can filter and
|
232
|
+
transform the results. It receives each of the keys and values,
|
233
|
+
and its return value is used instead of the original value.
|
234
|
+
If it returns what it received, then the structure is not modified.
|
235
|
+
If it returns undefined then the member is deleted.
|
236
|
+
|
237
|
+
Example:
|
238
|
+
|
239
|
+
// Parse the text. Values that look like ISO date strings will
|
240
|
+
// be converted to Date objects.
|
241
|
+
|
242
|
+
myData = JSON.parse(text, function (key, value) {
|
243
|
+
var a;
|
244
|
+
if (typeof value === 'string') {
|
245
|
+
a =
|
246
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
247
|
+
if (a) {
|
248
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
249
|
+
+a[5], +a[6]));
|
250
|
+
}
|
251
|
+
}
|
252
|
+
return value;
|
253
|
+
});
|
254
|
+
|
255
|
+
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
256
|
+
var d;
|
257
|
+
if (typeof value === 'string' &&
|
258
|
+
value.slice(0, 5) === 'Date(' &&
|
259
|
+
value.slice(-1) === ')') {
|
260
|
+
d = new Date(value.slice(5, -1));
|
261
|
+
if (d) {
|
262
|
+
return d;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
return value;
|
266
|
+
});
|
267
|
+
|
268
|
+
|
269
|
+
This is a reference implementation. You are free to copy, modify, or
|
270
|
+
redistribute.
|
271
|
+
*/
|
272
|
+
|
273
|
+
/*jslint evil: true, strict: false */
|
274
|
+
|
275
|
+
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
276
|
+
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
277
|
+
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
278
|
+
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
279
|
+
test, toJSON, toString, valueOf
|
280
|
+
*/
|
281
|
+
|
282
|
+
|
283
|
+
// Create a JSON object only if one does not already exist. We create the
|
284
|
+
// methods in a closure to avoid creating global variables.
|
285
|
+
|
286
|
+
if (!this.JSON) {
|
287
|
+
this.JSON = {};
|
288
|
+
}
|
289
|
+
|
290
|
+
(function () {
|
291
|
+
|
292
|
+
function f(n) {
|
293
|
+
// Format integers to have at least two digits.
|
294
|
+
return n < 10 ? '0' + n : n;
|
295
|
+
}
|
296
|
+
|
297
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
298
|
+
|
299
|
+
Date.prototype.toJSON = function (key) {
|
300
|
+
|
301
|
+
return isFinite(this.valueOf()) ?
|
302
|
+
this.getUTCFullYear() + '-' +
|
303
|
+
f(this.getUTCMonth() + 1) + '-' +
|
304
|
+
f(this.getUTCDate()) + 'T' +
|
305
|
+
f(this.getUTCHours()) + ':' +
|
306
|
+
f(this.getUTCMinutes()) + ':' +
|
307
|
+
f(this.getUTCSeconds()) + 'Z' : null;
|
308
|
+
};
|
309
|
+
|
310
|
+
String.prototype.toJSON =
|
311
|
+
Number.prototype.toJSON =
|
312
|
+
Boolean.prototype.toJSON = function (key) {
|
313
|
+
return this.valueOf();
|
314
|
+
};
|
315
|
+
}
|
316
|
+
|
317
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
318
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
319
|
+
gap,
|
320
|
+
indent,
|
321
|
+
meta = { // table of character substitutions
|
322
|
+
'\b': '\\b',
|
323
|
+
'\t': '\\t',
|
324
|
+
'\n': '\\n',
|
325
|
+
'\f': '\\f',
|
326
|
+
'\r': '\\r',
|
327
|
+
'"' : '\\"',
|
328
|
+
'\\': '\\\\'
|
329
|
+
},
|
330
|
+
rep;
|
331
|
+
|
332
|
+
|
333
|
+
function quote(string) {
|
334
|
+
|
335
|
+
// If the string contains no control characters, no quote characters, and no
|
336
|
+
// backslash characters, then we can safely slap some quotes around it.
|
337
|
+
// Otherwise we must also replace the offending characters with safe escape
|
338
|
+
// sequences.
|
339
|
+
|
340
|
+
escapable.lastIndex = 0;
|
341
|
+
return escapable.test(string) ?
|
342
|
+
'"' + string.replace(escapable, function (a) {
|
343
|
+
var c = meta[a];
|
344
|
+
return typeof c === 'string' ? c :
|
345
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
346
|
+
}) + '"' :
|
347
|
+
'"' + string + '"';
|
348
|
+
}
|
349
|
+
|
350
|
+
|
351
|
+
function str(key, holder) {
|
352
|
+
|
353
|
+
// Produce a string from holder[key].
|
354
|
+
|
355
|
+
var i, // The loop counter.
|
356
|
+
k, // The member key.
|
357
|
+
v, // The member value.
|
358
|
+
length,
|
359
|
+
mind = gap,
|
360
|
+
partial,
|
361
|
+
value = holder[key];
|
362
|
+
|
363
|
+
// If the value has a toJSON method, call it to obtain a replacement value.
|
364
|
+
|
365
|
+
if (value && typeof value === 'object' &&
|
366
|
+
typeof value.toJSON === 'function') {
|
367
|
+
value = value.toJSON(key);
|
368
|
+
}
|
369
|
+
|
370
|
+
// If we were called with a replacer function, then call the replacer to
|
371
|
+
// obtain a replacement value.
|
372
|
+
|
373
|
+
if (typeof rep === 'function') {
|
374
|
+
value = rep.call(holder, key, value);
|
375
|
+
}
|
376
|
+
|
377
|
+
// What happens next depends on the value's type.
|
378
|
+
|
379
|
+
switch (typeof value) {
|
380
|
+
case 'string':
|
381
|
+
return quote(value);
|
382
|
+
|
383
|
+
case 'number':
|
384
|
+
|
385
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
386
|
+
|
387
|
+
return isFinite(value) ? String(value) : 'null';
|
388
|
+
|
389
|
+
case 'boolean':
|
390
|
+
case 'null':
|
391
|
+
|
392
|
+
// If the value is a boolean or null, convert it to a string. Note:
|
393
|
+
// typeof null does not produce 'null'. The case is included here in
|
394
|
+
// the remote chance that this gets fixed someday.
|
395
|
+
|
396
|
+
return String(value);
|
397
|
+
|
398
|
+
// If the type is 'object', we might be dealing with an object or an array or
|
399
|
+
// null.
|
400
|
+
|
401
|
+
case 'object':
|
402
|
+
|
403
|
+
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
404
|
+
// so watch out for that case.
|
405
|
+
|
406
|
+
if (!value) {
|
407
|
+
return 'null';
|
408
|
+
}
|
409
|
+
|
410
|
+
// Make an array to hold the partial results of stringifying this object value.
|
411
|
+
|
412
|
+
gap += indent;
|
413
|
+
partial = [];
|
414
|
+
|
415
|
+
// Is the value an array?
|
416
|
+
|
417
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
418
|
+
|
419
|
+
// The value is an array. Stringify every element. Use null as a placeholder
|
420
|
+
// for non-JSON values.
|
421
|
+
|
422
|
+
length = value.length;
|
423
|
+
for (i = 0; i < length; i += 1) {
|
424
|
+
partial[i] = str(i, value) || 'null';
|
425
|
+
}
|
426
|
+
|
427
|
+
// Join all of the elements together, separated with commas, and wrap them in
|
428
|
+
// brackets.
|
429
|
+
|
430
|
+
v = partial.length === 0 ? '[]' :
|
431
|
+
gap ? '[\n' + gap +
|
432
|
+
partial.join(',\n' + gap) + '\n' +
|
433
|
+
mind + ']' :
|
434
|
+
'[' + partial.join(',') + ']';
|
435
|
+
gap = mind;
|
436
|
+
return v;
|
437
|
+
}
|
438
|
+
|
439
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
440
|
+
|
441
|
+
if (rep && typeof rep === 'object') {
|
442
|
+
length = rep.length;
|
443
|
+
for (i = 0; i < length; i += 1) {
|
444
|
+
k = rep[i];
|
445
|
+
if (typeof k === 'string') {
|
446
|
+
v = str(k, value);
|
447
|
+
if (v) {
|
448
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
449
|
+
}
|
450
|
+
}
|
451
|
+
}
|
452
|
+
} else {
|
453
|
+
|
454
|
+
// Otherwise, iterate through all of the keys in the object.
|
455
|
+
|
456
|
+
for (k in value) {
|
457
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
458
|
+
v = str(k, value);
|
459
|
+
if (v) {
|
460
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}
|
464
|
+
}
|
465
|
+
|
466
|
+
// Join all of the member texts together, separated with commas,
|
467
|
+
// and wrap them in braces.
|
468
|
+
|
469
|
+
v = partial.length === 0 ? '{}' :
|
470
|
+
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
471
|
+
mind + '}' : '{' + partial.join(',') + '}';
|
472
|
+
gap = mind;
|
473
|
+
return v;
|
474
|
+
}
|
475
|
+
}
|
476
|
+
|
477
|
+
// If the JSON object does not yet have a stringify method, give it one.
|
478
|
+
|
479
|
+
if (typeof JSON.stringify !== 'function') {
|
480
|
+
JSON.stringify = function (value, replacer, space) {
|
481
|
+
|
482
|
+
// The stringify method takes a value and an optional replacer, and an optional
|
483
|
+
// space parameter, and returns a JSON text. The replacer can be a function
|
484
|
+
// that can replace values, or an array of strings that will select the keys.
|
485
|
+
// A default replacer method can be provided. Use of the space parameter can
|
486
|
+
// produce text that is more easily readable.
|
487
|
+
|
488
|
+
var i;
|
489
|
+
gap = '';
|
490
|
+
indent = '';
|
491
|
+
|
492
|
+
// If the space parameter is a number, make an indent string containing that
|
493
|
+
// many spaces.
|
494
|
+
|
495
|
+
if (typeof space === 'number') {
|
496
|
+
for (i = 0; i < space; i += 1) {
|
497
|
+
indent += ' ';
|
498
|
+
}
|
499
|
+
|
500
|
+
// If the space parameter is a string, it will be used as the indent string.
|
501
|
+
|
502
|
+
} else if (typeof space === 'string') {
|
503
|
+
indent = space;
|
504
|
+
}
|
505
|
+
|
506
|
+
// If there is a replacer, it must be a function or an array.
|
507
|
+
// Otherwise, throw an error.
|
508
|
+
|
509
|
+
rep = replacer;
|
510
|
+
if (replacer && typeof replacer !== 'function' &&
|
511
|
+
(typeof replacer !== 'object' ||
|
512
|
+
typeof replacer.length !== 'number')) {
|
513
|
+
throw new Error('JSON.stringify');
|
514
|
+
}
|
515
|
+
|
516
|
+
// Make a fake root object containing our value under the key of ''.
|
517
|
+
// Return the result of stringifying the value.
|
518
|
+
|
519
|
+
return str('', {'': value});
|
520
|
+
};
|
521
|
+
}
|
522
|
+
|
523
|
+
|
524
|
+
// If the JSON object does not yet have a parse method, give it one.
|
525
|
+
|
526
|
+
if (typeof JSON.parse !== 'function') {
|
527
|
+
JSON.parse = function (text, reviver) {
|
528
|
+
|
529
|
+
// The parse method takes a text and an optional reviver function, and returns
|
530
|
+
// a JavaScript value if the text is a valid JSON text.
|
531
|
+
|
532
|
+
var j;
|
533
|
+
|
534
|
+
function walk(holder, key) {
|
535
|
+
|
536
|
+
// The walk method is used to recursively walk the resulting structure so
|
537
|
+
// that modifications can be made.
|
538
|
+
|
539
|
+
var k, v, value = holder[key];
|
540
|
+
if (value && typeof value === 'object') {
|
541
|
+
for (k in value) {
|
542
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
543
|
+
v = walk(value, k);
|
544
|
+
if (v !== undefined) {
|
545
|
+
value[k] = v;
|
546
|
+
} else {
|
547
|
+
delete value[k];
|
548
|
+
}
|
549
|
+
}
|
550
|
+
}
|
551
|
+
}
|
552
|
+
return reviver.call(holder, key, value);
|
553
|
+
}
|
554
|
+
|
555
|
+
|
556
|
+
// Parsing happens in four stages. In the first stage, we replace certain
|
557
|
+
// Unicode characters with escape sequences. JavaScript handles many characters
|
558
|
+
// incorrectly, either silently deleting them, or treating them as line endings.
|
559
|
+
|
560
|
+
text = String(text);
|
561
|
+
cx.lastIndex = 0;
|
562
|
+
if (cx.test(text)) {
|
563
|
+
text = text.replace(cx, function (a) {
|
564
|
+
return '\\u' +
|
565
|
+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
566
|
+
});
|
567
|
+
}
|
568
|
+
|
569
|
+
// In the second stage, we run the text against regular expressions that look
|
570
|
+
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
571
|
+
// because they can cause invocation, and '=' because it can cause mutation.
|
572
|
+
// But just to be safe, we want to reject all unexpected forms.
|
573
|
+
|
574
|
+
// We split the second stage into 4 regexp operations in order to work around
|
575
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
576
|
+
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
577
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
578
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
579
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
580
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
581
|
+
|
582
|
+
if (/^[\],:{}\s]*$/
|
583
|
+
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
584
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
585
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
586
|
+
|
587
|
+
// In the third stage we use the eval function to compile the text into a
|
588
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
589
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
590
|
+
// in parens to eliminate the ambiguity.
|
591
|
+
|
592
|
+
j = eval('(' + text + ')');
|
593
|
+
|
594
|
+
// In the optional fourth stage, we recursively walk the new structure, passing
|
595
|
+
// each name/value pair to a reviver function for possible transformation.
|
596
|
+
|
597
|
+
return typeof reviver === 'function' ?
|
598
|
+
walk({'': j}, '') : j;
|
599
|
+
}
|
600
|
+
|
601
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
602
|
+
|
603
|
+
throw new SyntaxError('JSON.parse');
|
604
|
+
};
|
605
|
+
}
|
606
|
+
}());
|
607
|
+
/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
608
|
+
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
609
|
+
*/
|
610
|
+
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
|
129
611
|
/*
|
130
612
|
/*
|
131
613
|
Copyright 2006 Adobe Systems Incorporated
|
@@ -730,393 +1212,393 @@ ASProxy.prototype =
|
|
730
1212
|
this.bridge.release(this);
|
731
1213
|
}
|
732
1214
|
};
|
733
|
-
|
734
|
-
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
735
|
-
// License: New BSD License
|
736
|
-
// Reference: http://dev.w3.org/html5/websockets/
|
737
|
-
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
|
738
|
-
|
739
|
-
(function() {
|
740
|
-
|
741
|
-
if (window.WebSocket) return;
|
742
|
-
|
743
|
-
var console = window.console;
|
744
|
-
if (!console) console = {log: function(){ }, error: function(){ }};
|
745
|
-
|
746
|
-
if (!swfobject.hasFlashPlayerVersion("9.0.0")) {
|
747
|
-
console.error("Flash Player is not installed.");
|
748
|
-
return;
|
749
|
-
}
|
750
|
-
if (location.protocol == "file:") {
|
751
|
-
console.error(
|
752
|
-
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
753
|
-
"unless you set Flash Security Settings properly. " +
|
754
|
-
"Open the page via Web server i.e. http://...");
|
755
|
-
}
|
756
|
-
|
757
|
-
WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
|
758
|
-
var self = this;
|
759
|
-
self.readyState = WebSocket.CONNECTING;
|
760
|
-
self.bufferedAmount = 0;
|
761
|
-
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
762
|
-
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
763
|
-
setTimeout(function() {
|
764
|
-
WebSocket.__addTask(function() {
|
765
|
-
self.__createFlash(url, protocol, proxyHost, proxyPort, headers);
|
766
|
-
});
|
767
|
-
}, 1);
|
768
|
-
}
|
769
|
-
|
770
|
-
WebSocket.prototype.__createFlash = function(url, protocol, proxyHost, proxyPort, headers) {
|
771
|
-
var self = this;
|
772
|
-
self.__flash =
|
773
|
-
WebSocket.__flash.create(url, protocol, proxyHost || null, proxyPort || 0, headers || null);
|
774
|
-
|
775
|
-
self.__flash.addEventListener("open", function(fe) {
|
776
|
-
try {
|
777
|
-
self.readyState = self.__flash.getReadyState();
|
778
|
-
if (self.__timer) clearInterval(self.__timer);
|
779
|
-
if (window.opera) {
|
780
|
-
// Workaround for weird behavior of Opera which sometimes drops events.
|
781
|
-
self.__timer = setInterval(function () {
|
782
|
-
self.__handleMessages();
|
783
|
-
}, 500);
|
784
|
-
}
|
785
|
-
if (self.onopen) self.onopen();
|
786
|
-
} catch (e) {
|
787
|
-
console.error(e.toString());
|
788
|
-
}
|
789
|
-
});
|
790
|
-
|
791
|
-
self.__flash.addEventListener("close", function(fe) {
|
792
|
-
try {
|
793
|
-
self.readyState = self.__flash.getReadyState();
|
794
|
-
if (self.__timer) clearInterval(self.__timer);
|
795
|
-
if (self.onclose) self.onclose();
|
796
|
-
} catch (e) {
|
797
|
-
console.error(e.toString());
|
798
|
-
}
|
799
|
-
});
|
800
|
-
|
801
|
-
self.__flash.addEventListener("message", function() {
|
802
|
-
try {
|
803
|
-
self.__handleMessages();
|
804
|
-
} catch (e) {
|
805
|
-
console.error(e.toString());
|
806
|
-
}
|
807
|
-
});
|
808
|
-
|
809
|
-
self.__flash.addEventListener("error", function(fe) {
|
810
|
-
try {
|
811
|
-
if (self.__timer) clearInterval(self.__timer);
|
812
|
-
if (self.onerror) self.onerror();
|
813
|
-
} catch (e) {
|
814
|
-
console.error(e.toString());
|
815
|
-
}
|
816
|
-
});
|
817
|
-
|
818
|
-
self.__flash.addEventListener("stateChange", function(fe) {
|
819
|
-
try {
|
820
|
-
self.readyState = self.__flash.getReadyState();
|
821
|
-
self.bufferedAmount = fe.getBufferedAmount();
|
822
|
-
} catch (e) {
|
823
|
-
console.error(e.toString());
|
824
|
-
}
|
825
|
-
});
|
826
|
-
|
827
|
-
//console.log("[WebSocket] Flash object is ready");
|
828
|
-
};
|
829
|
-
|
830
|
-
WebSocket.prototype.send = function(data) {
|
831
|
-
if (this.__flash) {
|
832
|
-
this.readyState = this.__flash.getReadyState();
|
833
|
-
}
|
834
|
-
if (!this.__flash || this.readyState == WebSocket.CONNECTING) {
|
835
|
-
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
836
|
-
}
|
837
|
-
// We use encodeURIComponent() here, because FABridge doesn't work if
|
838
|
-
// the argument includes some characters. We don't use escape() here
|
839
|
-
// because of this:
|
840
|
-
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
841
|
-
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
842
|
-
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
843
|
-
var result = this.__flash.send(encodeURIComponent(data));
|
844
|
-
if (result < 0) { // success
|
845
|
-
return true;
|
846
|
-
} else {
|
847
|
-
this.bufferedAmount = result;
|
848
|
-
return false;
|
849
|
-
}
|
850
|
-
};
|
851
|
-
|
852
|
-
WebSocket.prototype.close = function() {
|
853
|
-
var self = this;
|
854
|
-
if (!self.__flash) return;
|
855
|
-
self.readyState = self.__flash.getReadyState();
|
856
|
-
if (self.readyState == WebSocket.CLOSED || self.readyState == WebSocket.CLOSING) return;
|
857
|
-
self.__flash.close();
|
858
|
-
// Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events
|
859
|
-
// which causes weird error:
|
860
|
-
// > You are trying to call recursively into the Flash Player which is not allowed.
|
861
|
-
self.readyState = WebSocket.CLOSED;
|
862
|
-
if (self.__timer) clearInterval(self.__timer);
|
863
|
-
if (self.onclose) {
|
864
|
-
// Make it asynchronous so that it looks more like an actual
|
865
|
-
// close event
|
866
|
-
setTimeout(self.onclose, 1);
|
867
|
-
}
|
868
|
-
};
|
869
|
-
|
870
|
-
/**
|
871
|
-
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
872
|
-
*
|
873
|
-
* @param {string} type
|
874
|
-
* @param {function} listener
|
875
|
-
* @param {boolean} useCapture !NB Not implemented yet
|
876
|
-
* @return void
|
877
|
-
*/
|
878
|
-
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
879
|
-
if (!('__events' in this)) {
|
880
|
-
this.__events = {};
|
881
|
-
}
|
882
|
-
if (!(type in this.__events)) {
|
883
|
-
this.__events[type] = [];
|
884
|
-
if ('function' == typeof this['on' + type]) {
|
885
|
-
this.__events[type].defaultHandler = this['on' + type];
|
886
|
-
this['on' + type] = this.__createEventHandler(this, type);
|
887
|
-
}
|
888
|
-
}
|
889
|
-
this.__events[type].push(listener);
|
890
|
-
};
|
891
|
-
|
892
|
-
/**
|
893
|
-
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
894
|
-
*
|
895
|
-
* @param {string} type
|
896
|
-
* @param {function} listener
|
897
|
-
* @param {boolean} useCapture NB! Not implemented yet
|
898
|
-
* @return void
|
899
|
-
*/
|
900
|
-
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
901
|
-
if (!('__events' in this)) {
|
902
|
-
this.__events = {};
|
903
|
-
}
|
904
|
-
if (!(type in this.__events)) return;
|
905
|
-
for (var i = this.__events.length; i > -1; --i) {
|
906
|
-
if (listener === this.__events[type][i]) {
|
907
|
-
this.__events[type].splice(i, 1);
|
908
|
-
break;
|
909
|
-
}
|
910
|
-
}
|
911
|
-
};
|
912
|
-
|
913
|
-
/**
|
914
|
-
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
915
|
-
*
|
916
|
-
* @param {WebSocketEvent} event
|
917
|
-
* @return void
|
918
|
-
*/
|
919
|
-
WebSocket.prototype.dispatchEvent = function(event) {
|
920
|
-
if (!('__events' in this)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
|
921
|
-
if (!(event.type in this.__events)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
|
922
|
-
|
923
|
-
for (var i = 0, l = this.__events[event.type].length; i < l; ++ i) {
|
924
|
-
this.__events[event.type][i](event);
|
925
|
-
if (event.cancelBubble) break;
|
926
|
-
}
|
927
|
-
|
928
|
-
if (false !== event.returnValue &&
|
929
|
-
'function' == typeof this.__events[event.type].defaultHandler)
|
930
|
-
{
|
931
|
-
this.__events[event.type].defaultHandler(event);
|
932
|
-
}
|
933
|
-
};
|
934
|
-
|
935
|
-
WebSocket.prototype.__handleMessages = function() {
|
936
|
-
// Gets data using readSocketData() instead of getting it from event object
|
937
|
-
// of Flash event. This is to make sure to keep message order.
|
938
|
-
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
939
|
-
var arr = this.__flash.readSocketData();
|
940
|
-
for (var i = 0; i < arr.length; i++) {
|
941
|
-
var data = decodeURIComponent(arr[i]);
|
942
|
-
try {
|
943
|
-
if (this.onmessage) {
|
944
|
-
var e;
|
945
|
-
if (window.MessageEvent && !window.opera) {
|
946
|
-
e = document.createEvent("MessageEvent");
|
947
|
-
e.initMessageEvent("message", false, false, data, null, null, window, null);
|
948
|
-
} else { // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes
|
949
|
-
e = {data: data};
|
950
|
-
}
|
951
|
-
this.onmessage(e);
|
952
|
-
}
|
953
|
-
} catch (e) {
|
954
|
-
console.error(e.toString());
|
955
|
-
}
|
956
|
-
}
|
957
|
-
};
|
958
|
-
|
959
|
-
/**
|
960
|
-
* @param {object} object
|
961
|
-
* @param {string} type
|
962
|
-
*/
|
963
|
-
WebSocket.prototype.__createEventHandler = function(object, type) {
|
964
|
-
return function(data) {
|
965
|
-
var event = new WebSocketEvent();
|
966
|
-
event.initEvent(type, true, true);
|
967
|
-
event.target = event.currentTarget = object;
|
968
|
-
for (var key in data) {
|
969
|
-
event[key] = data[key];
|
970
|
-
}
|
971
|
-
object.dispatchEvent(event, arguments);
|
972
|
-
};
|
973
|
-
}
|
974
|
-
|
975
|
-
/**
|
976
|
-
* Basic implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface">DOM 2 EventInterface</a>}
|
977
|
-
*
|
978
|
-
* @class
|
979
|
-
* @constructor
|
980
|
-
*/
|
981
|
-
function WebSocketEvent(){}
|
982
|
-
|
983
|
-
/**
|
984
|
-
*
|
985
|
-
* @type boolean
|
986
|
-
*/
|
987
|
-
WebSocketEvent.prototype.cancelable = true;
|
988
|
-
|
989
|
-
/**
|
990
|
-
*
|
991
|
-
* @type boolean
|
992
|
-
*/
|
993
|
-
WebSocketEvent.prototype.cancelBubble = false;
|
994
|
-
|
995
|
-
/**
|
996
|
-
*
|
997
|
-
* @return void
|
998
|
-
*/
|
999
|
-
WebSocketEvent.prototype.preventDefault = function() {
|
1000
|
-
if (this.cancelable) {
|
1001
|
-
this.returnValue = false;
|
1002
|
-
}
|
1003
|
-
};
|
1004
|
-
|
1005
|
-
/**
|
1006
|
-
*
|
1007
|
-
* @return void
|
1008
|
-
*/
|
1009
|
-
WebSocketEvent.prototype.stopPropagation = function() {
|
1010
|
-
this.cancelBubble = true;
|
1011
|
-
};
|
1012
|
-
|
1013
|
-
/**
|
1014
|
-
*
|
1015
|
-
* @param {string} eventTypeArg
|
1016
|
-
* @param {boolean} canBubbleArg
|
1017
|
-
* @param {boolean} cancelableArg
|
1018
|
-
* @return void
|
1019
|
-
*/
|
1020
|
-
WebSocketEvent.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg) {
|
1021
|
-
this.type = eventTypeArg;
|
1022
|
-
this.cancelable = cancelableArg;
|
1023
|
-
this.timeStamp = new Date();
|
1024
|
-
};
|
1025
|
-
|
1026
|
-
|
1027
|
-
WebSocket.CONNECTING = 0;
|
1028
|
-
WebSocket.OPEN = 1;
|
1029
|
-
WebSocket.CLOSING = 2;
|
1030
|
-
WebSocket.CLOSED = 3;
|
1031
|
-
|
1032
|
-
WebSocket.__tasks = [];
|
1033
|
-
|
1034
|
-
WebSocket.__initialize = function() {
|
1035
|
-
if (WebSocket.__swfLocation) {
|
1036
|
-
// For backword compatibility.
|
1037
|
-
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
1038
|
-
}
|
1039
|
-
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
1040
|
-
console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
1041
|
-
return;
|
1042
|
-
}
|
1043
|
-
var container = document.createElement("div");
|
1044
|
-
container.id = "webSocketContainer";
|
1045
|
-
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
1046
|
-
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
1047
|
-
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
1048
|
-
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
1049
|
-
// the best we can do as far as we know now.
|
1050
|
-
container.style.position = "absolute";
|
1051
|
-
if (WebSocket.__isFlashLite()) {
|
1052
|
-
container.style.left = "0px";
|
1053
|
-
container.style.top = "0px";
|
1054
|
-
} else {
|
1055
|
-
container.style.left = "-100px";
|
1056
|
-
container.style.top = "-100px";
|
1057
|
-
}
|
1058
|
-
var holder = document.createElement("div");
|
1059
|
-
holder.id = "webSocketFlash";
|
1060
|
-
container.appendChild(holder);
|
1061
|
-
document.body.appendChild(container);
|
1062
|
-
// See this article for hasPriority:
|
1063
|
-
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
1064
|
-
swfobject.embedSWF(
|
1065
|
-
WEB_SOCKET_SWF_LOCATION, "webSocketFlash",
|
1066
|
-
"1" /* width */, "1" /* height */, "9.0.0" /* SWF version */,
|
1067
|
-
null, {bridgeName: "webSocket"}, {hasPriority: true, allowScriptAccess: "always"}, null,
|
1068
|
-
function(e) {
|
1069
|
-
if (!e.success) console.error("[WebSocket] swfobject.embedSWF failed");
|
1070
|
-
}
|
1071
|
-
);
|
1072
|
-
FABridge.addInitializationCallback("webSocket", function() {
|
1073
|
-
try {
|
1074
|
-
//console.log("[WebSocket] FABridge initializad");
|
1075
|
-
WebSocket.__flash = FABridge.webSocket.root();
|
1076
|
-
WebSocket.__flash.setCallerUrl(location.href);
|
1077
|
-
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
1078
|
-
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
1079
|
-
WebSocket.__tasks[i]();
|
1080
|
-
}
|
1081
|
-
WebSocket.__tasks = [];
|
1082
|
-
} catch (e) {
|
1083
|
-
console.error("[WebSocket] " + e.toString());
|
1084
|
-
}
|
1085
|
-
});
|
1086
|
-
};
|
1087
|
-
|
1088
|
-
WebSocket.__addTask = function(task) {
|
1089
|
-
if (WebSocket.__flash) {
|
1090
|
-
task();
|
1091
|
-
} else {
|
1092
|
-
WebSocket.__tasks.push(task);
|
1093
|
-
}
|
1094
|
-
};
|
1095
|
-
|
1096
|
-
WebSocket.__isFlashLite = function() {
|
1097
|
-
if (!window.navigator || !window.navigator.mimeTypes) return false;
|
1098
|
-
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
1099
|
-
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) return false;
|
1100
|
-
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
1101
|
-
};
|
1102
|
-
|
1103
|
-
// called from Flash
|
1104
|
-
window.webSocketLog = function(message) {
|
1105
|
-
console.log(decodeURIComponent(message));
|
1106
|
-
};
|
1107
|
-
|
1108
|
-
// called from Flash
|
1109
|
-
window.webSocketError = function(message) {
|
1110
|
-
console.error(decodeURIComponent(message));
|
1111
|
-
};
|
1112
|
-
|
1113
|
-
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
1114
|
-
if (window.addEventListener) {
|
1115
|
-
window.addEventListener("load", WebSocket.__initialize, false);
|
1116
|
-
} else {
|
1117
|
-
window.attachEvent("onload", WebSocket.__initialize);
|
1118
|
-
}
|
1119
|
-
}
|
1120
|
-
|
1121
|
-
})();
|
1122
|
-
|
1215
|
+
|
1216
|
+
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
1217
|
+
// License: New BSD License
|
1218
|
+
// Reference: http://dev.w3.org/html5/websockets/
|
1219
|
+
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
|
1220
|
+
|
1221
|
+
(function() {
|
1222
|
+
|
1223
|
+
if (window.WebSocket) return;
|
1224
|
+
|
1225
|
+
var console = window.console;
|
1226
|
+
if (!console) console = {log: function(){ }, error: function(){ }};
|
1227
|
+
|
1228
|
+
if (!swfobject.hasFlashPlayerVersion("9.0.0")) {
|
1229
|
+
console.error("Flash Player is not installed.");
|
1230
|
+
return;
|
1231
|
+
}
|
1232
|
+
if (location.protocol == "file:") {
|
1233
|
+
console.error(
|
1234
|
+
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
1235
|
+
"unless you set Flash Security Settings properly. " +
|
1236
|
+
"Open the page via Web server i.e. http://...");
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
|
1240
|
+
var self = this;
|
1241
|
+
self.readyState = WebSocket.CONNECTING;
|
1242
|
+
self.bufferedAmount = 0;
|
1243
|
+
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
1244
|
+
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
1245
|
+
setTimeout(function() {
|
1246
|
+
WebSocket.__addTask(function() {
|
1247
|
+
self.__createFlash(url, protocol, proxyHost, proxyPort, headers);
|
1248
|
+
});
|
1249
|
+
}, 1);
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
WebSocket.prototype.__createFlash = function(url, protocol, proxyHost, proxyPort, headers) {
|
1253
|
+
var self = this;
|
1254
|
+
self.__flash =
|
1255
|
+
WebSocket.__flash.create(url, protocol, proxyHost || null, proxyPort || 0, headers || null);
|
1256
|
+
|
1257
|
+
self.__flash.addEventListener("open", function(fe) {
|
1258
|
+
try {
|
1259
|
+
self.readyState = self.__flash.getReadyState();
|
1260
|
+
if (self.__timer) clearInterval(self.__timer);
|
1261
|
+
if (window.opera) {
|
1262
|
+
// Workaround for weird behavior of Opera which sometimes drops events.
|
1263
|
+
self.__timer = setInterval(function () {
|
1264
|
+
self.__handleMessages();
|
1265
|
+
}, 500);
|
1266
|
+
}
|
1267
|
+
if (self.onopen) self.onopen();
|
1268
|
+
} catch (e) {
|
1269
|
+
console.error(e.toString());
|
1270
|
+
}
|
1271
|
+
});
|
1272
|
+
|
1273
|
+
self.__flash.addEventListener("close", function(fe) {
|
1274
|
+
try {
|
1275
|
+
self.readyState = self.__flash.getReadyState();
|
1276
|
+
if (self.__timer) clearInterval(self.__timer);
|
1277
|
+
if (self.onclose) self.onclose();
|
1278
|
+
} catch (e) {
|
1279
|
+
console.error(e.toString());
|
1280
|
+
}
|
1281
|
+
});
|
1282
|
+
|
1283
|
+
self.__flash.addEventListener("message", function() {
|
1284
|
+
try {
|
1285
|
+
self.__handleMessages();
|
1286
|
+
} catch (e) {
|
1287
|
+
console.error(e.toString());
|
1288
|
+
}
|
1289
|
+
});
|
1290
|
+
|
1291
|
+
self.__flash.addEventListener("error", function(fe) {
|
1292
|
+
try {
|
1293
|
+
if (self.__timer) clearInterval(self.__timer);
|
1294
|
+
if (self.onerror) self.onerror();
|
1295
|
+
} catch (e) {
|
1296
|
+
console.error(e.toString());
|
1297
|
+
}
|
1298
|
+
});
|
1299
|
+
|
1300
|
+
self.__flash.addEventListener("stateChange", function(fe) {
|
1301
|
+
try {
|
1302
|
+
self.readyState = self.__flash.getReadyState();
|
1303
|
+
self.bufferedAmount = fe.getBufferedAmount();
|
1304
|
+
} catch (e) {
|
1305
|
+
console.error(e.toString());
|
1306
|
+
}
|
1307
|
+
});
|
1308
|
+
|
1309
|
+
//console.log("[WebSocket] Flash object is ready");
|
1310
|
+
};
|
1311
|
+
|
1312
|
+
WebSocket.prototype.send = function(data) {
|
1313
|
+
if (this.__flash) {
|
1314
|
+
this.readyState = this.__flash.getReadyState();
|
1315
|
+
}
|
1316
|
+
if (!this.__flash || this.readyState == WebSocket.CONNECTING) {
|
1317
|
+
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
1318
|
+
}
|
1319
|
+
// We use encodeURIComponent() here, because FABridge doesn't work if
|
1320
|
+
// the argument includes some characters. We don't use escape() here
|
1321
|
+
// because of this:
|
1322
|
+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
1323
|
+
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
1324
|
+
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
1325
|
+
var result = this.__flash.send(encodeURIComponent(data));
|
1326
|
+
if (result < 0) { // success
|
1327
|
+
return true;
|
1328
|
+
} else {
|
1329
|
+
this.bufferedAmount = result;
|
1330
|
+
return false;
|
1331
|
+
}
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
WebSocket.prototype.close = function() {
|
1335
|
+
var self = this;
|
1336
|
+
if (!self.__flash) return;
|
1337
|
+
self.readyState = self.__flash.getReadyState();
|
1338
|
+
if (self.readyState == WebSocket.CLOSED || self.readyState == WebSocket.CLOSING) return;
|
1339
|
+
self.__flash.close();
|
1340
|
+
// Sets/calls them manually here because Flash WebSocketConnection.close cannot fire events
|
1341
|
+
// which causes weird error:
|
1342
|
+
// > You are trying to call recursively into the Flash Player which is not allowed.
|
1343
|
+
self.readyState = WebSocket.CLOSED;
|
1344
|
+
if (self.__timer) clearInterval(self.__timer);
|
1345
|
+
if (self.onclose) {
|
1346
|
+
// Make it asynchronous so that it looks more like an actual
|
1347
|
+
// close event
|
1348
|
+
setTimeout(self.onclose, 1);
|
1349
|
+
}
|
1350
|
+
};
|
1351
|
+
|
1352
|
+
/**
|
1353
|
+
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
1354
|
+
*
|
1355
|
+
* @param {string} type
|
1356
|
+
* @param {function} listener
|
1357
|
+
* @param {boolean} useCapture !NB Not implemented yet
|
1358
|
+
* @return void
|
1359
|
+
*/
|
1360
|
+
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
1361
|
+
if (!('__events' in this)) {
|
1362
|
+
this.__events = {};
|
1363
|
+
}
|
1364
|
+
if (!(type in this.__events)) {
|
1365
|
+
this.__events[type] = [];
|
1366
|
+
if ('function' == typeof this['on' + type]) {
|
1367
|
+
this.__events[type].defaultHandler = this['on' + type];
|
1368
|
+
this['on' + type] = this.__createEventHandler(this, type);
|
1369
|
+
}
|
1370
|
+
}
|
1371
|
+
this.__events[type].push(listener);
|
1372
|
+
};
|
1373
|
+
|
1374
|
+
/**
|
1375
|
+
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
1376
|
+
*
|
1377
|
+
* @param {string} type
|
1378
|
+
* @param {function} listener
|
1379
|
+
* @param {boolean} useCapture NB! Not implemented yet
|
1380
|
+
* @return void
|
1381
|
+
*/
|
1382
|
+
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
1383
|
+
if (!('__events' in this)) {
|
1384
|
+
this.__events = {};
|
1385
|
+
}
|
1386
|
+
if (!(type in this.__events)) return;
|
1387
|
+
for (var i = this.__events.length; i > -1; --i) {
|
1388
|
+
if (listener === this.__events[type][i]) {
|
1389
|
+
this.__events[type].splice(i, 1);
|
1390
|
+
break;
|
1391
|
+
}
|
1392
|
+
}
|
1393
|
+
};
|
1394
|
+
|
1395
|
+
/**
|
1396
|
+
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
1397
|
+
*
|
1398
|
+
* @param {WebSocketEvent} event
|
1399
|
+
* @return void
|
1400
|
+
*/
|
1401
|
+
WebSocket.prototype.dispatchEvent = function(event) {
|
1402
|
+
if (!('__events' in this)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
|
1403
|
+
if (!(event.type in this.__events)) throw 'UNSPECIFIED_EVENT_TYPE_ERR';
|
1404
|
+
|
1405
|
+
for (var i = 0, l = this.__events[event.type].length; i < l; ++ i) {
|
1406
|
+
this.__events[event.type][i](event);
|
1407
|
+
if (event.cancelBubble) break;
|
1408
|
+
}
|
1409
|
+
|
1410
|
+
if (false !== event.returnValue &&
|
1411
|
+
'function' == typeof this.__events[event.type].defaultHandler)
|
1412
|
+
{
|
1413
|
+
this.__events[event.type].defaultHandler(event);
|
1414
|
+
}
|
1415
|
+
};
|
1416
|
+
|
1417
|
+
WebSocket.prototype.__handleMessages = function() {
|
1418
|
+
// Gets data using readSocketData() instead of getting it from event object
|
1419
|
+
// of Flash event. This is to make sure to keep message order.
|
1420
|
+
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
1421
|
+
var arr = this.__flash.readSocketData();
|
1422
|
+
for (var i = 0; i < arr.length; i++) {
|
1423
|
+
var data = decodeURIComponent(arr[i]);
|
1424
|
+
try {
|
1425
|
+
if (this.onmessage) {
|
1426
|
+
var e;
|
1427
|
+
if (window.MessageEvent && !window.opera) {
|
1428
|
+
e = document.createEvent("MessageEvent");
|
1429
|
+
e.initMessageEvent("message", false, false, data, null, null, window, null);
|
1430
|
+
} else { // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes
|
1431
|
+
e = {data: data};
|
1432
|
+
}
|
1433
|
+
this.onmessage(e);
|
1434
|
+
}
|
1435
|
+
} catch (e) {
|
1436
|
+
console.error(e.toString());
|
1437
|
+
}
|
1438
|
+
}
|
1439
|
+
};
|
1440
|
+
|
1441
|
+
/**
|
1442
|
+
* @param {object} object
|
1443
|
+
* @param {string} type
|
1444
|
+
*/
|
1445
|
+
WebSocket.prototype.__createEventHandler = function(object, type) {
|
1446
|
+
return function(data) {
|
1447
|
+
var event = new WebSocketEvent();
|
1448
|
+
event.initEvent(type, true, true);
|
1449
|
+
event.target = event.currentTarget = object;
|
1450
|
+
for (var key in data) {
|
1451
|
+
event[key] = data[key];
|
1452
|
+
}
|
1453
|
+
object.dispatchEvent(event, arguments);
|
1454
|
+
};
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
/**
|
1458
|
+
* Basic implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface">DOM 2 EventInterface</a>}
|
1459
|
+
*
|
1460
|
+
* @class
|
1461
|
+
* @constructor
|
1462
|
+
*/
|
1463
|
+
function WebSocketEvent(){}
|
1464
|
+
|
1465
|
+
/**
|
1466
|
+
*
|
1467
|
+
* @type boolean
|
1468
|
+
*/
|
1469
|
+
WebSocketEvent.prototype.cancelable = true;
|
1470
|
+
|
1471
|
+
/**
|
1472
|
+
*
|
1473
|
+
* @type boolean
|
1474
|
+
*/
|
1475
|
+
WebSocketEvent.prototype.cancelBubble = false;
|
1476
|
+
|
1477
|
+
/**
|
1478
|
+
*
|
1479
|
+
* @return void
|
1480
|
+
*/
|
1481
|
+
WebSocketEvent.prototype.preventDefault = function() {
|
1482
|
+
if (this.cancelable) {
|
1483
|
+
this.returnValue = false;
|
1484
|
+
}
|
1485
|
+
};
|
1486
|
+
|
1487
|
+
/**
|
1488
|
+
*
|
1489
|
+
* @return void
|
1490
|
+
*/
|
1491
|
+
WebSocketEvent.prototype.stopPropagation = function() {
|
1492
|
+
this.cancelBubble = true;
|
1493
|
+
};
|
1494
|
+
|
1495
|
+
/**
|
1496
|
+
*
|
1497
|
+
* @param {string} eventTypeArg
|
1498
|
+
* @param {boolean} canBubbleArg
|
1499
|
+
* @param {boolean} cancelableArg
|
1500
|
+
* @return void
|
1501
|
+
*/
|
1502
|
+
WebSocketEvent.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg) {
|
1503
|
+
this.type = eventTypeArg;
|
1504
|
+
this.cancelable = cancelableArg;
|
1505
|
+
this.timeStamp = new Date();
|
1506
|
+
};
|
1507
|
+
|
1508
|
+
|
1509
|
+
WebSocket.CONNECTING = 0;
|
1510
|
+
WebSocket.OPEN = 1;
|
1511
|
+
WebSocket.CLOSING = 2;
|
1512
|
+
WebSocket.CLOSED = 3;
|
1513
|
+
|
1514
|
+
WebSocket.__tasks = [];
|
1515
|
+
|
1516
|
+
WebSocket.__initialize = function() {
|
1517
|
+
if (WebSocket.__swfLocation) {
|
1518
|
+
// For backword compatibility.
|
1519
|
+
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
1520
|
+
}
|
1521
|
+
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
1522
|
+
console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
1523
|
+
return;
|
1524
|
+
}
|
1525
|
+
var container = document.createElement("div");
|
1526
|
+
container.id = "webSocketContainer";
|
1527
|
+
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
1528
|
+
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
1529
|
+
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
1530
|
+
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
1531
|
+
// the best we can do as far as we know now.
|
1532
|
+
container.style.position = "absolute";
|
1533
|
+
if (WebSocket.__isFlashLite()) {
|
1534
|
+
container.style.left = "0px";
|
1535
|
+
container.style.top = "0px";
|
1536
|
+
} else {
|
1537
|
+
container.style.left = "-100px";
|
1538
|
+
container.style.top = "-100px";
|
1539
|
+
}
|
1540
|
+
var holder = document.createElement("div");
|
1541
|
+
holder.id = "webSocketFlash";
|
1542
|
+
container.appendChild(holder);
|
1543
|
+
document.body.appendChild(container);
|
1544
|
+
// See this article for hasPriority:
|
1545
|
+
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
1546
|
+
swfobject.embedSWF(
|
1547
|
+
WEB_SOCKET_SWF_LOCATION, "webSocketFlash",
|
1548
|
+
"1" /* width */, "1" /* height */, "9.0.0" /* SWF version */,
|
1549
|
+
null, {bridgeName: "webSocket"}, {hasPriority: true, allowScriptAccess: "always"}, null,
|
1550
|
+
function(e) {
|
1551
|
+
if (!e.success) console.error("[WebSocket] swfobject.embedSWF failed");
|
1552
|
+
}
|
1553
|
+
);
|
1554
|
+
FABridge.addInitializationCallback("webSocket", function() {
|
1555
|
+
try {
|
1556
|
+
//console.log("[WebSocket] FABridge initializad");
|
1557
|
+
WebSocket.__flash = FABridge.webSocket.root();
|
1558
|
+
WebSocket.__flash.setCallerUrl(location.href);
|
1559
|
+
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
1560
|
+
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
1561
|
+
WebSocket.__tasks[i]();
|
1562
|
+
}
|
1563
|
+
WebSocket.__tasks = [];
|
1564
|
+
} catch (e) {
|
1565
|
+
console.error("[WebSocket] " + e.toString());
|
1566
|
+
}
|
1567
|
+
});
|
1568
|
+
};
|
1569
|
+
|
1570
|
+
WebSocket.__addTask = function(task) {
|
1571
|
+
if (WebSocket.__flash) {
|
1572
|
+
task();
|
1573
|
+
} else {
|
1574
|
+
WebSocket.__tasks.push(task);
|
1575
|
+
}
|
1576
|
+
};
|
1577
|
+
|
1578
|
+
WebSocket.__isFlashLite = function() {
|
1579
|
+
if (!window.navigator || !window.navigator.mimeTypes) return false;
|
1580
|
+
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
1581
|
+
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) return false;
|
1582
|
+
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
1583
|
+
};
|
1584
|
+
|
1585
|
+
// called from Flash
|
1586
|
+
window.webSocketLog = function(message) {
|
1587
|
+
console.log(decodeURIComponent(message));
|
1588
|
+
};
|
1589
|
+
|
1590
|
+
// called from Flash
|
1591
|
+
window.webSocketError = function(message) {
|
1592
|
+
console.error(decodeURIComponent(message));
|
1593
|
+
};
|
1594
|
+
|
1595
|
+
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
1596
|
+
if (window.addEventListener) {
|
1597
|
+
window.addEventListener("load", WebSocket.__initialize, false);
|
1598
|
+
} else {
|
1599
|
+
window.attachEvent("onload", WebSocket.__initialize);
|
1600
|
+
}
|
1601
|
+
}
|
1602
|
+
|
1603
|
+
})();
|
1604
|
+
|