/
pubnub-3.4.min.js
22 lines (22 loc) · 9.84 KB
/
pubnub-3.4.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function n(){return function(){}}
window.JSON&&window.JSON.stringify||function(){function a(a){b.lastIndex=0;return b.test(a)?'"'+a.replace(b,function(a){var b=j[a];return"string"===typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function c(b,j){var i,l,h,g,m=e,k,d=j[b];d&&("object"===typeof d&&"function"===typeof d.toJSON)&&(d=d.toJSON(b));"function"===typeof q&&(d=q.call(j,b,d));switch(typeof d){case "string":return a(d);case "number":return isFinite(d)?String(d):"null";case "boolean":case "null":return String(d);
case "object":if(!d)return"null";e+=f;k=[];if("[object Array]"===Object.prototype.toString.apply(d)){g=d.length;for(i=0;i<g;i+=1)k[i]=c(i,d)||"null";h=0===k.length?"[]":e?"[\n"+e+k.join(",\n"+e)+"\n"+m+"]":"["+k.join(",")+"]";e=m;return h}if(q&&"object"===typeof q){g=q.length;for(i=0;i<g;i+=1)l=q[i],"string"===typeof l&&(h=c(l,d))&&k.push(a(l)+(e?": ":":")+h)}else for(l in d)Object.hasOwnProperty.call(d,l)&&(h=c(l,d))&&k.push(a(l)+(e?": ":":")+h);h=0===k.length?"{}":e?"{\n"+e+k.join(",\n"+e)+"\n"+
m+"}":"{"+k.join(",")+"}";e=m;return h}}window.JSON||(window.JSON={});"function"!==typeof String.prototype.toJSON&&(String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var b=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,e,f,j={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},q;"function"!==typeof JSON.stringify&&(JSON.stringify=function(a,
b,i){var j;f=e="";if("number"===typeof i)for(j=0;j<i;j+=1)f+=" ";else"string"===typeof i&&(f=i);if((q=b)&&"function"!==typeof b&&("object"!==typeof b||"number"!==typeof b.length))throw Error("JSON.stringify");return c("",{"":a})});"function"!==typeof JSON.parse&&(JSON.parse=function(a){return eval("("+a+")")})}();
if(!window.PUBNUB){var p=function(){return"x"+ ++aa+""+ +new Date},r=function(){return+new Date},ba=function(a,c){function b(){f+c>r()?(clearTimeout(e),e=setTimeout(b,c)):(f=r(),a())}var e,f=0;return b},s=function(a){return document.getElementById(a)},t=function(a){console.error(a)},w=function(a,c){var b=[];v(a.split(/\s+/),function(a){v((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b},v=function(a,c){if(a&&c)if("undefined"!=typeof a[0])for(var b=0,e=a.length;b<e;)c.call(a[b],
a[b],b++);else for(b in a)a.hasOwnProperty&&a.hasOwnProperty(b)&&c.call(a[b],b,a[b])},y=function(a,c){var b=[];v(a||[],function(a,f){b.push(c(a,f))});return b},da=function(a,c){var b=[];v(a||[],function(a){c(a)&&b.push(a)});return b},fa=function(a,c){return a.replace(ea,function(a,e){return c[e]||a})},z=function(a,c,b){v(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=!1,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}
c.addEventListener?c.addEventListener(a,f,!1):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})},A=function(){return w("head")[0]},C=function(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)},D=function(a,c){for(var b in c)if(c.hasOwnProperty(b))try{a.style[b]=c[b]+(0<"|width|height|top|left|".indexOf(b)&&"number"==typeof c[b]?"px":"")}catch(e){}},E=function(a){return document.createElement(a)},H=function(){return F||G()?0:p()},I=function(a){return y(encodeURIComponent(a).split(""),
function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")},N=function(a){function c(a,b){V||(V=1,a||la(b),d.onerror=null,clearTimeout(ma),setTimeout(function(){a&&na();var b=s(u),c=b&&b.parentNode;c&&c.removeChild(b)},J))}if(F||G()){a:{var b,e,f=function(){if(!q){q=1;clearTimeout(B);try{e=JSON.parse(b.responseText)}catch(a){return h(1)}l(e)}},j=0,q=0,x=a.timeout||K,B=setTimeout(function(){h(1)},x),i=a.b||n(),l=a.c||n(),h=function(a){j||(j=1,clearTimeout(B),
b&&(b.onerror=b.onload=null,b.abort&&b.abort(),b=null),a&&i())};try{b=G()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest;b.onerror=b.onabort=function(){h(1)};b.onload=b.onloadend=f;b.timeout=x;var g=a.url.join(L);if(a.data){var f=[],m,g=g+"?";for(m in a.data)f.push(m+"="+a.data[m]);g+=f.join(M)}b.open("GET",g,typeof("undefined"===a.g));b.send()}catch(k){h(0);F=0;a=N(a);break a}a=h}return a}var d=E("script"),g=a.a,u=p(),V=0,ma=setTimeout(function(){c(1)},a.timeout||K),na=a.b||n(),la=
a.c||n();window[g]=function(a){c(0,a)};a.g||(d[O]=O);d.onerror=function(){c(1)};d.src=a.url.join(L);if(a.data){g=[];d.src+="?";for(key in a.data)g.push(key+"="+a.data[key]);d.src+=g.join(M)}C(d,"id",u);A().appendChild(d);return c},P=function(a){var c=[];v(a,function(a,e){e.f&&c.push(a)});return c.sort()},S=function(){PUBNUB.time(r);PUBNUB.time(function(){setTimeout(function(){R||(R=1,v(ga,function(a){a()}))},J)})},G=function(){if(!ha.get)return 0;var a={id:G.id++,send:n(),abort:function(){a.id={}},
open:function(c,b){G[a.id]=a;ha.get(a.id,b)}};return a},aa=1,ea=/{([\w\-]+)}/g,O="async",L="/",M="&",ia=31E4,K=1E4,J=1E3,T="-pnpres",F=-1==navigator.userAgent.indexOf("MSIE 6");window.console||(window.console=window.console||{});console.error||(console.error=(window.opera||{}).postError||n());var U,W=window.localStorage;U={get:function(a){try{return W?W.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(W)return W.setItem(a,
c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};var X,Y=Math.floor(20*Math.random());X=function(a){return 0<a.indexOf("pubsub")&&a.replace("pubsub","ps"+(20>++Y?Y:Y=1))||a};var Z={list:{},unbind:function(a){Z.list[a]=[]},bind:function(a,c){(Z.list[a]=Z.list[a]||[]).push(c)},fire:function(a,c){v(Z.list[a]||[],function(a){a(c)})}},$=s("pubnub")||{},R=0,ga=[],qa=function(a){function c(){}function b(){}function e(a){v(P(f),function(b){a(f[b]||{})})}var f={},
j=0,q=0,x=0,B=0,i=0,l=0,h=a.publish_key||"",g=a.subscribe_key||"",m=a.ssl?"s":"",k=a.uuid||U.get(g+"uuid")||"",d="http"+m+"://"+(a.origin||"pubsub.pubnub.com"),u={history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,e=a.reverse||"false",f=a.error||n(),i=a.channel,k=a.start,h=a.end,j={},l=H();if(!i)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");j.count=c;j.reverse=e;k&&(j.start=k);h&&(j.end=h);N({a:l,data:j,c:function(a){b(a)},b:f,
url:[d,"v2","history","sub-key",g,"channel",I(i)]})},time:function(a){var b=H(),c=X(d);N({a:b,url:[c,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},uuid:function(a){var b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0;return("x"==a?b:b&3|8).toString(16)});a&&a(b);return b},publish:function(a,b){var b=b||a.callback||n(),c=a.message,e=a.channel,f=H();if(!c)return t("Missing Message");if(!e)return t("Missing Channel");if(!h)return t("Missing Publish Key");
if(!g)return t("Missing Subscribe Key");c=JSON.stringify(c);c=[d,"publish",h,g,0,I(e),f,I(c)];N({a:f,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:c,data:{uuid:k}})},unsubscribe:function(a){a=a.channel;a=y((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+T}).join(",");v(a.split(","),function(a){R&&b(a,0);f[a]={}});R&&c()},subscribe:function(a,b){function h(){var a=H(),b=P(f).join(",");b&&(x=N({timeout:ia,a:a,data:{uuid:k},url:[ca,"subscribe",g,I(b),a,l],b:function(){e(function(a){a.d||
(a.d=1,a.j(a.name))});ca=X(d);setTimeout(h,J);u.time(function(a){e(function(b){a&&b.d?(b.d=0,b.k(b.name)):b.error()})})},c:function(a){if(!a)return setTimeout(h,10);e(function(a){a.e||(a.e=1,a.i(a.name))});l=!l&&B?U.get(g)||a[1]:a[1];U.set(g,a[1]);var b,c=(2<a.length?a[2]:"").split(",");b=function(){var a=c.shift()||"";return[(f[a]||{}).a||j,(a||q).split(T)[0]]};v(a[0],function(c){var d=b();if(f[d[1]].f)d[0](c,a,d[1])});setTimeout(h,10)}}))}var m=a.channel,b=(b=b||a.callback)||a.message,ja=a.error||
n(),ka=a.connect||n(),oa=a.reconnect||n(),pa=a.disconnect||n(),Q=a.presence||0,ra=a.restore,ca=X(d);ra&&(B=1);if(!m)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");v((m.join?m.join(","):""+m).split(","),function(a){var c=f[a]||{};f[q=a]={name:a,e:c.e,d:c.d,f:1,a:j=b,i:ka,error:ja,j:pa,k:oa};Q&&(u.m({h:a+T,a:Q}),c.f||u.here_now({h:a,a:function(b){v("uuids"in b?b.uuids:[],function(c){Q({action:"join",uuid:c,timestamp:r(),occupancy:b.occupancy||
1},b,a)})}}))});c=function(){x&&x();clearTimeout(i);i=setTimeout(h,100)};if(!R)return ga.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||n(),e=a.channel,f=H(),h={};if(!e)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");"0"!=f&&(h.callback=f);N({a:f,data:h,c:function(a){b(a)},b:c,url:[d,"v2","presence","sub_key",g,"channel",I(e)]})},xdr:N,ready:S,db:U,each:v,map:y,grep:da,css:D,$:s,create:E,bind:z,supplant:fa,head:A,search:w,
attr:C,now:r,unique:p,events:Z,updater:ba,init:qa};k||(k=u.uuid());U.set(g+"uuid",k);b=function(a,b){var c={uuid:k},e=X(d),f=H();0<a.indexOf(T)||("0"!=f&&(c.callback=f),N({g:b||m,timeout:2E3,a:f,data:c,url:[e,"v2","presence","sub_key",g,"channel",I(a),"leave"]}))};z("beforeunload",window,function(){e(function(a){b(a.name,1)});return!0});return u};PUBNUB=qa({publish_key:C($,"pub-key"),subscribe_key:C($,"sub-key"),ssl:!document.location.href.indexOf("https")||"on"==C($,"ssl"),origin:C($,"origin"),uuid:C($,
"uuid")});D($,{position:"absolute",top:-J});if("opera"in window||C($,"flash"))$.innerHTML="<object id=pubnubs data=https://dh15atwfs066y.cloudfront.net/pubnub.swf><param name=movie value=https://dh15atwfs066y.cloudfront.net/pubnub.swf><param name=allowscriptaccess value=always></object>";var ha=s("pubnubs")||{};z("load",window,function(){setTimeout(S,0)});PUBNUB.rdx=function(a,c){if(!c)return G[a].onerror();G[a].responseText=unescape(c);G[a].onload()};G.id=J;window.jQuery&&(window.jQuery.PUBNUB=PUBNUB);
"undefined"!==typeof module&&(module.l=PUBNUB)&&S()};