Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated 3.4 with new REPLAY function.

  • Loading branch information...
commit f713d108b732fbdf220ceecb4893a3bbdc8c3356 1 parent 5c41c06
Stephen L. Blum stephenlb authored
40 app-showcase/ascii-player/ascii-player.html
View
@@ -37,42 +37,36 @@
</div>
<!-- PUBNUB SOURCE -->
-<script src=https://pubnub.s3.amazonaws.com/pubnub-3.4.min.js></script>
+<script src=../../javascript/pubnub-3.4.js></script>
<script>(function(){
/* GENERATE CHANNEL */
var channel = PUBNUB.uuid()
-, pub_key = 'pub-7d598eb7-1523-4c72-9786-d8650a856bf5'
-, sub_key = 'sub-041c0011-6d41-11e1-8b07-35f1f17243aa'
+, pub_key = 'demo'
+, sub_key = 'demo'
, out = PUBNUB.$('pubnub-terminal-out')
-, p = PUBNUB.init({ subscribe_key : sub_key });
+, p = PUBNUB.init({ subscribe_key : sub_key, publish_key : pub_key });
/* OPEN RECEIVE SOCKET */
p.subscribe({
channel : channel,
- message : function(data) { out.innerHTML = parse(data)||'' }
+ message : function(data) { out.innerHTML = parse(data)||'' },
+ connect : start_replay
});
-function parse(data) { try{return JSON.parse(data)} catch(e){} }
-
/* START THE MOVIE STREAM */
-(function(){
- var img = p.create('img');
- img.src = p.supplant([
- 'http:','','23.23.187.160:9050',
- 'v1','replay','{pub_key}',
- '{sub_key}','{src_channel}',
- '{des_channel}'
- ].join('/'), {
- pub_key : pub_key,
- sub_key : sub_key,
- des_channel : channel,
- src_channel : '0cefce37-606c-4eae-a9e9-aff35186b854'
- } );
- p.css( img, { display : 'none' } );
- p.search('body')[0].appendChild(img);
-})();
+function start_replay() {
+ p.replay({
+ //source : '0cefce37-606c-4eae-a9e9-aff35186b854',
+ source : 'my_channel',
+ destination : channel,
+ reverse : true
+ });
+}
+
+function parse(data) { return data }
+
})();</script>
</body>
</html>
50 javascript/3.4/pubnub-3.4.js
View
@@ -562,6 +562,56 @@ var PDIV = $('pubnub') || {}
},
/*
+ PUBNUB.replay({
+ source : 'my_channel',
+ destination : 'new_channel'
+ });
+ */
+ 'replay' : function(args) {
+ var callback = callback || args['callback'] || function(){}
+ , source = args['source']
+ , destination = args['destination']
+ , stop = args['stop']
+ , start = args['start']
+ , end = args['end']
+ , reverse = args['reverse']
+ , limit = args['limit']
+ , jsonp = jsonp_cb()
+ , data = {}
+ , url;
+
+ // Check User Input
+ if (!source) return error('Missing Source Channel');
+ if (!destination) return error('Missing Destination Channel');
+ if (!PUBLISH_KEY) return error('Missing Publish Key');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ // Setup URL Params
+ if (jsonp != '0') data['callback'] = jsonp;
+ if (stop) data['stop'] = 'all';
+ if (reverse) data['reverse'] = 'true';
+ if (start) data['start'] = start;
+ if (end) data['end'] = end;
+ if (limit) data['count'] = limit;
+
+ // Compose URL Parts
+ url = [
+ ORIGIN, 'v1', 'replay',
+ PUBLISH_KEY, SUBSCRIBE_KEY,
+ source, destination
+ ];
+
+ // Start (or Stop) Replay!
+ xdr({
+ callback : jsonp,
+ success : function(response) { callback(response) },
+ fail : function() { callback([ 0, 'Disconnected' ]) },
+ url : url,
+ data : data
+ });
+ },
+
+ /*
PUBNUB.time(function(time){ });
*/
'time' : function(callback) {
43 javascript/3.4/pubnub-3.4.min.js
View
@@ -1,24 +1,25 @@
(function(){
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.log||(console.log=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){(b=
-f[b])&&a(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]=0});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.i(a.name))});ca=X(d);setTimeout(h,J);u.time(function(a){e(function(b){a&&b.d?(b.d=0,b.j(b.name)):b.error()})})},c:function(a){if(!a)return setTimeout(h,10);e(function(a){a.e||(a.e=1,a.h(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,h:ka,error:ja,i:pa,j:oa};Q&&(u.subscribe({channel:a+T,callback:Q}),c.f||u.here_now({channel:a,callback: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.exports=PUBNUB)&&S()};
+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 h,m,i,g,p=d,k,f=j[b];f&&("object"===typeof f&&"function"===typeof f.toJSON)&&(f=f.toJSON(b));"function"===typeof l&&(f=l.call(j,b,f));switch(typeof f){case "string":return a(f);case "number":return isFinite(f)?String(f):"null";case "boolean":case "null":return String(f);
+case "object":if(!f)return"null";d+=e;k=[];if("[object Array]"===Object.prototype.toString.apply(f)){g=f.length;for(h=0;h<g;h+=1)k[h]=c(h,f)||"null";i=0===k.length?"[]":d?"[\n"+d+k.join(",\n"+d)+"\n"+p+"]":"["+k.join(",")+"]";d=p;return i}if(l&&"object"===typeof l){g=l.length;for(h=0;h<g;h+=1)m=l[h],"string"===typeof m&&(i=c(m,f))&&k.push(a(m)+(d?": ":":")+i)}else for(m in f)Object.hasOwnProperty.call(f,m)&&(i=c(m,f))&&k.push(a(m)+(d?": ":":")+i);i=0===k.length?"{}":d?"{\n"+d+k.join(",\n"+d)+"\n"+
+p+"}":"{"+k.join(",")+"}";d=p;return i}}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,d,e,j={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},l;"function"!==typeof JSON.stringify&&(JSON.stringify=function(a,
+b,h){var j;e=d="";if("number"===typeof h)for(j=0;j<h;j+=1)e+=" ";else"string"===typeof h&&(e=h);if((l=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 q=function(){return"x"+ ++aa+""+ +new Date},r=function(){return+new Date},ba=function(a,c){function b(){e+c>r()?(clearTimeout(d),d=setTimeout(b,c)):(e=r(),a())}var d,e=0;return b},s=function(a){return document.getElementById(a)},t=function(a){console.error(a)},w=function(a,c){var b=[];u(a.split(/\s+/),function(a){u((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b},u=function(a,c){if(a&&c)if("undefined"!=typeof a[0])for(var b=0,d=a.length;b<d;)c.call(a[b],
+a[b],b++);else for(b in a)a.hasOwnProperty&&a.hasOwnProperty(b)&&c.call(a[b],b,a[b])},x=function(a,c){var b=[];u(a||[],function(a,e){b.push(c(a,e))});return b},da=function(a,c){var b=[];u(a||[],function(a){c(a)&&b.push(a)});return b},fa=function(a,c){return a.replace(ea,function(a,d){return c[d]||a})},z=function(a,c,b){u(a.split(","),function(a){function e(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,e,!1):c.attachEvent?c.attachEvent("on"+a,e):c["on"+a]=e})},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)},E=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(d){}},F=function(a){return document.createElement(a)},I=function(){return G||H()?0:q()},J=function(a){return x(encodeURIComponent(a).split(""),
+function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")},O=function(a){function c(a,b){D||(D=1,a||la(b),f.onerror=null,clearTimeout(ma),setTimeout(function(){a&&na();var b=s(v),D=b&&b.parentNode;D&&D.removeChild(b)},K))}if(G||H()){a:{var b,d,e=function(){if(!l){l=1;clearTimeout(B);try{d=JSON.parse(b.responseText)}catch(a){return i(1)}m(d)}},j=0,l=0,y=a.timeout||L,B=setTimeout(function(){i(1)},y),h=a.b||n(),m=a.c||n(),i=function(a){j||(j=1,clearTimeout(B),
+b&&(b.onerror=b.onload=null,b.abort&&b.abort(),b=null),a&&h())};try{b=H()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest;b.onerror=b.onabort=function(){i(1)};b.onload=b.onloadend=e;b.timeout=y;var g=a.url.join(M);if(a.data){var e=[],p,g=g+"?";for(p in a.data)e.push(p+"="+a.data[p]);g+=e.join(N)}b.open("GET",g,typeof("undefined"===a.g));b.send()}catch(k){i(0);G=0;a=O(a);break a}a=i}return a}var f=F("script"),g=a.a,v=q(),D=0,ma=setTimeout(function(){c(1)},a.timeout||L),na=a.b||n(),la=
+a.c||n();window[g]=function(a){c(0,a)};a.g||(f[P]=P);f.onerror=function(){c(1)};f.src=a.url.join(M);if(a.data){g=[];f.src+="?";for(key in a.data)g.push(key+"="+a.data[key]);f.src+=g.join(N)}C(f,"id",v);A().appendChild(f);return c},Q=function(a){var c=[];u(a,function(a,d){d.f&&c.push(a)});return c.sort()},T=function(){PUBNUB.time(r);PUBNUB.time(function(){setTimeout(function(){S||(S=1,u(ga,function(a){a()}))},K)})},H=function(){if(!ha.get)return 0;var a={id:H.id++,send:n(),abort:function(){a.id={}},
+open:function(c,b){H[a.id]=a;ha.get(a.id,b)}};return a},aa=1,ea=/{([\w\-]+)}/g,P="async",M="/",N="&",ia=31E4,L=1E4,K=1E3,U="-pnpres",G=-1==navigator.userAgent.indexOf("MSIE 6");window.console||(window.console=window.console||{});console.log||(console.log=console.error=(window.opera||{}).postError||n());var V,W=window.localStorage;V={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){u(Z.list[a]||[],function(a){a(c)})}},$=s("pubnub")||{},S=0,ga=[],qa=function(a){function c(){}function b(){}function d(a){u(Q(e),function(b){(b=
+e[b])&&a(b)})}var e={},j=0,l=0,y=0,B=0,h=0,m=0,i=a.publish_key||"",g=a.subscribe_key||"",p=a.ssl?"s":"",k=a.uuid||V.get(g+"uuid")||"",f="http"+p+"://"+(a.origin||"pubsub.pubnub.com"),v={history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||n(),h=a.channel,i=a.start,k=a.end,j={},m=I();if(!h)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");j.count=c;j.reverse=d;i&&(j.start=i);k&&(j.end=k);O({a:m,data:j,
+c:function(a){b(a)},b:e,url:[f,"v2","history","sub-key",g,"channel",J(h)]})},replay:function(a){var b=b||a.callback||n(),c=a.source,d=a.destination,e=a.stop,h=a.start,j=a.end,k=a.reverse,a=a.limit,m=I(),l={};if(!c)return t("Missing Source Channel");if(!d)return t("Missing Destination Channel");if(!i)return t("Missing Publish Key");if(!g)return t("Missing Subscribe Key");"0"!=m&&(l.callback=m);e&&(l.stop="all");k&&(l.reverse="true");h&&(l.start=h);j&&(l.end=j);a&&(l.count=a);O({a:m,c:function(a){b(a)},
+b:function(){b([0,"Disconnected"])},url:[f,"v1","replay",i,g,c,d],data:l})},time:function(a){var b=I(),c=X(f);O({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,d=a.channel,e=I();if(!c)return t("Missing Message");if(!d)return t("Missing Channel");if(!i)return t("Missing Publish Key");
+if(!g)return t("Missing Subscribe Key");c=JSON.stringify(c);c=[f,"publish",i,g,0,J(d),e,J(c)];O({a:e,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:c,data:{uuid:k}})},unsubscribe:function(a){a=a.channel;a=x((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+U}).join(",");u(a.split(","),function(a){S&&b(a,0);e[a]=0});S&&c()},subscribe:function(a,b){function i(){var a=I(),b=Q(e).join(",");b&&(y=O({timeout:ia,a:a,data:{uuid:k},url:[ca,"subscribe",g,J(b),a,m],b:function(){d(function(a){a.d||
+(a.d=1,a.i(a.name))});ca=X(f);setTimeout(i,K);v.time(function(a){d(function(b){a&&b.d?(b.d=0,b.j(b.name)):b.error()})})},c:function(a){if(!a)return setTimeout(i,10);d(function(a){a.e||(a.e=1,a.h(a.name))});m=!m&&B?V.get(g)||a[1]:a[1];V.set(g,a[1]);var b,c=(2<a.length?a[2]:"").split(",");b=function(){var a=c.shift()||"";return[(e[a]||{}).a||j,(a||l).split(U)[0]]};u(a[0],function(c){var d=b();if(e[d[1]].f)d[0](c,a,d[1])});setTimeout(i,10)}}))}var p=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(),R=a.presence||0,ra=a.restore,ca=X(f);ra&&(B=1);if(!p)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");u((p.join?p.join(","):""+p).split(","),function(a){var c=e[a]||{};e[l=a]={name:a,e:c.e,d:c.d,f:1,a:j=b,h:ka,error:ja,i:pa,j:oa};R&&(v.subscribe({channel:a+U,callback:R}),c.f||v.here_now({channel:a,callback:function(b){u("uuids"in b?b.uuids:[],function(c){R({action:"join",uuid:c,timestamp:r(),
+occupancy:b.occupancy||1},b,a)})}}))});c=function(){y&&y();clearTimeout(h);h=setTimeout(i,100)};if(!S)return ga.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||n(),d=a.channel,e=I(),h={};if(!d)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");"0"!=e&&(h.callback=e);O({a:e,data:h,c:function(a){b(a)},b:c,url:[f,"v2","presence","sub_key",g,"channel",J(d)]})},xdr:O,ready:T,db:V,each:u,map:x,grep:da,css:E,$:s,create:F,bind:z,supplant:fa,
+head:A,search:w,attr:C,now:r,unique:q,events:Z,updater:ba,init:qa};k||(k=v.uuid());V.set(g+"uuid",k);b=function(a,b){var c={uuid:k},d=X(f),e=I();0<a.indexOf(U)||("0"!=e&&(c.callback=e),O({g:b||p,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",J(a),"leave"]}))};z("beforeunload",window,function(){d(function(a){b(a.name,1)});return!0});return v};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")});E($,{position:"absolute",top:-K});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(T,0)});PUBNUB.rdx=function(a,c){if(!c)return H[a].onerror();H[a].responseText=unescape(c);H[a].onload()};H.id=K;window.jQuery&&(window.jQuery.PUBNUB=
+PUBNUB);"undefined"!==typeof module&&(module.exports=PUBNUB)&&T()};
})();
BIN  javascript/3.4/pubnub-3.4.min.js.gz
View
Binary file not shown
50 javascript/pubnub-3.4.js
View
@@ -562,6 +562,56 @@ var PDIV = $('pubnub') || {}
},
/*
+ PUBNUB.replay({
+ source : 'my_channel',
+ destination : 'new_channel'
+ });
+ */
+ 'replay' : function(args) {
+ var callback = callback || args['callback'] || function(){}
+ , source = args['source']
+ , destination = args['destination']
+ , stop = args['stop']
+ , start = args['start']
+ , end = args['end']
+ , reverse = args['reverse']
+ , limit = args['limit']
+ , jsonp = jsonp_cb()
+ , data = {}
+ , url;
+
+ // Check User Input
+ if (!source) return error('Missing Source Channel');
+ if (!destination) return error('Missing Destination Channel');
+ if (!PUBLISH_KEY) return error('Missing Publish Key');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ // Setup URL Params
+ if (jsonp != '0') data['callback'] = jsonp;
+ if (stop) data['stop'] = 'all';
+ if (reverse) data['reverse'] = 'true';
+ if (start) data['start'] = start;
+ if (end) data['end'] = end;
+ if (limit) data['count'] = limit;
+
+ // Compose URL Parts
+ url = [
+ ORIGIN, 'v1', 'replay',
+ PUBLISH_KEY, SUBSCRIBE_KEY,
+ source, destination
+ ];
+
+ // Start (or Stop) Replay!
+ xdr({
+ callback : jsonp,
+ success : function(response) { callback(response) },
+ fail : function() { callback([ 0, 'Disconnected' ]) },
+ url : url,
+ data : data
+ });
+ },
+
+ /*
PUBNUB.time(function(time){ });
*/
'time' : function(callback) {
43 javascript/pubnub-3.4.min.js
View
@@ -1,24 +1,25 @@
(function(){
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.log||(console.log=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){(b=
-f[b])&&a(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]=0});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.i(a.name))});ca=X(d);setTimeout(h,J);u.time(function(a){e(function(b){a&&b.d?(b.d=0,b.j(b.name)):b.error()})})},c:function(a){if(!a)return setTimeout(h,10);e(function(a){a.e||(a.e=1,a.h(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,h:ka,error:ja,i:pa,j:oa};Q&&(u.subscribe({channel:a+T,callback:Q}),c.f||u.here_now({channel:a,callback: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.exports=PUBNUB)&&S()};
+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 h,m,i,g,p=d,k,f=j[b];f&&("object"===typeof f&&"function"===typeof f.toJSON)&&(f=f.toJSON(b));"function"===typeof l&&(f=l.call(j,b,f));switch(typeof f){case "string":return a(f);case "number":return isFinite(f)?String(f):"null";case "boolean":case "null":return String(f);
+case "object":if(!f)return"null";d+=e;k=[];if("[object Array]"===Object.prototype.toString.apply(f)){g=f.length;for(h=0;h<g;h+=1)k[h]=c(h,f)||"null";i=0===k.length?"[]":d?"[\n"+d+k.join(",\n"+d)+"\n"+p+"]":"["+k.join(",")+"]";d=p;return i}if(l&&"object"===typeof l){g=l.length;for(h=0;h<g;h+=1)m=l[h],"string"===typeof m&&(i=c(m,f))&&k.push(a(m)+(d?": ":":")+i)}else for(m in f)Object.hasOwnProperty.call(f,m)&&(i=c(m,f))&&k.push(a(m)+(d?": ":":")+i);i=0===k.length?"{}":d?"{\n"+d+k.join(",\n"+d)+"\n"+
+p+"}":"{"+k.join(",")+"}";d=p;return i}}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,d,e,j={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},l;"function"!==typeof JSON.stringify&&(JSON.stringify=function(a,
+b,h){var j;e=d="";if("number"===typeof h)for(j=0;j<h;j+=1)e+=" ";else"string"===typeof h&&(e=h);if((l=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 q=function(){return"x"+ ++aa+""+ +new Date},r=function(){return+new Date},ba=function(a,c){function b(){e+c>r()?(clearTimeout(d),d=setTimeout(b,c)):(e=r(),a())}var d,e=0;return b},s=function(a){return document.getElementById(a)},t=function(a){console.error(a)},w=function(a,c){var b=[];u(a.split(/\s+/),function(a){u((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b},u=function(a,c){if(a&&c)if("undefined"!=typeof a[0])for(var b=0,d=a.length;b<d;)c.call(a[b],
+a[b],b++);else for(b in a)a.hasOwnProperty&&a.hasOwnProperty(b)&&c.call(a[b],b,a[b])},x=function(a,c){var b=[];u(a||[],function(a,e){b.push(c(a,e))});return b},da=function(a,c){var b=[];u(a||[],function(a){c(a)&&b.push(a)});return b},fa=function(a,c){return a.replace(ea,function(a,d){return c[d]||a})},z=function(a,c,b){u(a.split(","),function(a){function e(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,e,!1):c.attachEvent?c.attachEvent("on"+a,e):c["on"+a]=e})},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)},E=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(d){}},F=function(a){return document.createElement(a)},I=function(){return G||H()?0:q()},J=function(a){return x(encodeURIComponent(a).split(""),
+function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")},O=function(a){function c(a,b){D||(D=1,a||la(b),f.onerror=null,clearTimeout(ma),setTimeout(function(){a&&na();var b=s(v),D=b&&b.parentNode;D&&D.removeChild(b)},K))}if(G||H()){a:{var b,d,e=function(){if(!l){l=1;clearTimeout(B);try{d=JSON.parse(b.responseText)}catch(a){return i(1)}m(d)}},j=0,l=0,y=a.timeout||L,B=setTimeout(function(){i(1)},y),h=a.b||n(),m=a.c||n(),i=function(a){j||(j=1,clearTimeout(B),
+b&&(b.onerror=b.onload=null,b.abort&&b.abort(),b=null),a&&h())};try{b=H()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest;b.onerror=b.onabort=function(){i(1)};b.onload=b.onloadend=e;b.timeout=y;var g=a.url.join(M);if(a.data){var e=[],p,g=g+"?";for(p in a.data)e.push(p+"="+a.data[p]);g+=e.join(N)}b.open("GET",g,typeof("undefined"===a.g));b.send()}catch(k){i(0);G=0;a=O(a);break a}a=i}return a}var f=F("script"),g=a.a,v=q(),D=0,ma=setTimeout(function(){c(1)},a.timeout||L),na=a.b||n(),la=
+a.c||n();window[g]=function(a){c(0,a)};a.g||(f[P]=P);f.onerror=function(){c(1)};f.src=a.url.join(M);if(a.data){g=[];f.src+="?";for(key in a.data)g.push(key+"="+a.data[key]);f.src+=g.join(N)}C(f,"id",v);A().appendChild(f);return c},Q=function(a){var c=[];u(a,function(a,d){d.f&&c.push(a)});return c.sort()},T=function(){PUBNUB.time(r);PUBNUB.time(function(){setTimeout(function(){S||(S=1,u(ga,function(a){a()}))},K)})},H=function(){if(!ha.get)return 0;var a={id:H.id++,send:n(),abort:function(){a.id={}},
+open:function(c,b){H[a.id]=a;ha.get(a.id,b)}};return a},aa=1,ea=/{([\w\-]+)}/g,P="async",M="/",N="&",ia=31E4,L=1E4,K=1E3,U="-pnpres",G=-1==navigator.userAgent.indexOf("MSIE 6");window.console||(window.console=window.console||{});console.log||(console.log=console.error=(window.opera||{}).postError||n());var V,W=window.localStorage;V={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){u(Z.list[a]||[],function(a){a(c)})}},$=s("pubnub")||{},S=0,ga=[],qa=function(a){function c(){}function b(){}function d(a){u(Q(e),function(b){(b=
+e[b])&&a(b)})}var e={},j=0,l=0,y=0,B=0,h=0,m=0,i=a.publish_key||"",g=a.subscribe_key||"",p=a.ssl?"s":"",k=a.uuid||V.get(g+"uuid")||"",f="http"+p+"://"+(a.origin||"pubsub.pubnub.com"),v={history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||n(),h=a.channel,i=a.start,k=a.end,j={},m=I();if(!h)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");j.count=c;j.reverse=d;i&&(j.start=i);k&&(j.end=k);O({a:m,data:j,
+c:function(a){b(a)},b:e,url:[f,"v2","history","sub-key",g,"channel",J(h)]})},replay:function(a){var b=b||a.callback||n(),c=a.source,d=a.destination,e=a.stop,h=a.start,j=a.end,k=a.reverse,a=a.limit,m=I(),l={};if(!c)return t("Missing Source Channel");if(!d)return t("Missing Destination Channel");if(!i)return t("Missing Publish Key");if(!g)return t("Missing Subscribe Key");"0"!=m&&(l.callback=m);e&&(l.stop="all");k&&(l.reverse="true");h&&(l.start=h);j&&(l.end=j);a&&(l.count=a);O({a:m,c:function(a){b(a)},
+b:function(){b([0,"Disconnected"])},url:[f,"v1","replay",i,g,c,d],data:l})},time:function(a){var b=I(),c=X(f);O({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,d=a.channel,e=I();if(!c)return t("Missing Message");if(!d)return t("Missing Channel");if(!i)return t("Missing Publish Key");
+if(!g)return t("Missing Subscribe Key");c=JSON.stringify(c);c=[f,"publish",i,g,0,J(d),e,J(c)];O({a:e,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:c,data:{uuid:k}})},unsubscribe:function(a){a=a.channel;a=x((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+U}).join(",");u(a.split(","),function(a){S&&b(a,0);e[a]=0});S&&c()},subscribe:function(a,b){function i(){var a=I(),b=Q(e).join(",");b&&(y=O({timeout:ia,a:a,data:{uuid:k},url:[ca,"subscribe",g,J(b),a,m],b:function(){d(function(a){a.d||
+(a.d=1,a.i(a.name))});ca=X(f);setTimeout(i,K);v.time(function(a){d(function(b){a&&b.d?(b.d=0,b.j(b.name)):b.error()})})},c:function(a){if(!a)return setTimeout(i,10);d(function(a){a.e||(a.e=1,a.h(a.name))});m=!m&&B?V.get(g)||a[1]:a[1];V.set(g,a[1]);var b,c=(2<a.length?a[2]:"").split(",");b=function(){var a=c.shift()||"";return[(e[a]||{}).a||j,(a||l).split(U)[0]]};u(a[0],function(c){var d=b();if(e[d[1]].f)d[0](c,a,d[1])});setTimeout(i,10)}}))}var p=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(),R=a.presence||0,ra=a.restore,ca=X(f);ra&&(B=1);if(!p)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");u((p.join?p.join(","):""+p).split(","),function(a){var c=e[a]||{};e[l=a]={name:a,e:c.e,d:c.d,f:1,a:j=b,h:ka,error:ja,i:pa,j:oa};R&&(v.subscribe({channel:a+U,callback:R}),c.f||v.here_now({channel:a,callback:function(b){u("uuids"in b?b.uuids:[],function(c){R({action:"join",uuid:c,timestamp:r(),
+occupancy:b.occupancy||1},b,a)})}}))});c=function(){y&&y();clearTimeout(h);h=setTimeout(i,100)};if(!S)return ga.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||n(),d=a.channel,e=I(),h={};if(!d)return t("Missing Channel");if(!b)return t("Missing Callback");if(!g)return t("Missing Subscribe Key");"0"!=e&&(h.callback=e);O({a:e,data:h,c:function(a){b(a)},b:c,url:[f,"v2","presence","sub_key",g,"channel",J(d)]})},xdr:O,ready:T,db:V,each:u,map:x,grep:da,css:E,$:s,create:F,bind:z,supplant:fa,
+head:A,search:w,attr:C,now:r,unique:q,events:Z,updater:ba,init:qa};k||(k=v.uuid());V.set(g+"uuid",k);b=function(a,b){var c={uuid:k},d=X(f),e=I();0<a.indexOf(U)||("0"!=e&&(c.callback=e),O({g:b||p,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",J(a),"leave"]}))};z("beforeunload",window,function(){d(function(a){b(a.name,1)});return!0});return v};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")});E($,{position:"absolute",top:-K});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(T,0)});PUBNUB.rdx=function(a,c){if(!c)return H[a].onerror();H[a].responseText=unescape(c);H[a].onload()};H.id=K;window.jQuery&&(window.jQuery.PUBNUB=
+PUBNUB);"undefined"!==typeof module&&(module.exports=PUBNUB)&&T()};
})();
BIN  javascript/pubnub-3.4.min.js.gz
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.