Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

solved a race condition in unsubscribe within subscribes after receiv…

…ing a message and unsubscribing inside message received callback.
  • Loading branch information...
commit eb8eb88e906f1c6088a4ede86d9b77e13d808537 1 parent d0e5eb9
@stephenlb stephenlb authored
View
50 core/pubnub-common.js
@@ -199,7 +199,7 @@ function PN_API(setup) {
, PUB_QUEUE = []
, SUB_CALLBACK = 0
, SUB_CHANNEL = 0
- , SUB_RECEIVER = []
+ , SUB_RECEIVER = 0
, SUB_RESTORE = 0
, SUB_BUFF_WAIT = 0
, TIMETOKEN = 0
@@ -219,11 +219,18 @@ function PN_API(setup) {
}
function each_channel(callback) {
+ var count = 0;
+
each( generate_channel_list(CHANNELS), function(channel) {
var chan = CHANNELS[channel];
+
if (!chan) return;
- callback(chan);
+
+ count++;
+ (callback||function(){})(chan);
} );
+
+ return count;
}
// Announce Leave Event
@@ -421,9 +428,6 @@ function PN_API(setup) {
if (READY) SELF['LEAVE']( channel, 0 );
CHANNELS[channel] = 0;
} );
-
- // ReOpen Connection if Any Channels Left
- if (READY) CONNECT();
},
/*
@@ -434,16 +438,16 @@ function PN_API(setup) {
*/
'subscribe' : function( args, callback ) {
var channel = args['channel']
- , callback = callback || args['callback']
- , callback = callback || args['message']
- , connect = args['connect'] || function(){}
- , reconnect = args['reconnect'] || function(){}
- , disconnect = args['disconnect'] || function(){}
- , presence = args['presence'] || 0
- , noheresync = args['noheresync'] || 0
- , backfill = args['backfill'] || 0
- , sub_timeout = args['timeout'] || SUB_TIMEOUT
- , windowing = args['windowing'] || SUB_WINDOWING
+ , callback = callback || args['callback']
+ , callback = callback || args['message']
+ , connect = args['connect'] || function(){}
+ , reconnect = args['reconnect'] || function(){}
+ , disconnect = args['disconnect'] || function(){}
+ , presence = args['presence'] || 0
+ , noheresync = args['noheresync'] || 0
+ , backfill = args['backfill'] || 0
+ , sub_timeout = args['timeout'] || SUB_TIMEOUT
+ , windowing = args['windowing'] || SUB_WINDOWING
, restore = args['restore'];
// Restore Enabled?
@@ -544,7 +548,8 @@ function PN_API(setup) {
if (!channels) return;
// Connect to PubNub Subscribe Servers
- SUB_RECEIVER.push( xdr({
+ _reset_offline();
+ SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() { SELF['time'](_test_connection) },
@@ -605,20 +610,13 @@ function PN_API(setup) {
timeout( CONNECT, windowing );
}
- }));
- }
- function CLOSE_PREVIOUS_SUB() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ });
}
CONNECT = function() {
- CLOSE_PREVIOUS_SUB();
_connect();
};
-
// Reduce Status Flicker
if (!READY) return READY_BUFFER.push(CONNECT);
@@ -684,9 +682,7 @@ function PN_API(setup) {
}
function _reset_offline() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ SUB_RECEIVER && SUB_RECEIVER();
}
if (!UUID) UUID = SELF['uuid']();
View
50 modern/pubnub.js
@@ -200,7 +200,7 @@ function PN_API(setup) {
, PUB_QUEUE = []
, SUB_CALLBACK = 0
, SUB_CHANNEL = 0
- , SUB_RECEIVER = []
+ , SUB_RECEIVER = 0
, SUB_RESTORE = 0
, SUB_BUFF_WAIT = 0
, TIMETOKEN = 0
@@ -220,11 +220,18 @@ function PN_API(setup) {
}
function each_channel(callback) {
+ var count = 0;
+
each( generate_channel_list(CHANNELS), function(channel) {
var chan = CHANNELS[channel];
+
if (!chan) return;
- callback(chan);
+
+ count++;
+ (callback||function(){})(chan);
} );
+
+ return count;
}
// Announce Leave Event
@@ -422,9 +429,6 @@ function PN_API(setup) {
if (READY) SELF['LEAVE']( channel, 0 );
CHANNELS[channel] = 0;
} );
-
- // ReOpen Connection if Any Channels Left
- if (READY) CONNECT();
},
/*
@@ -435,16 +439,16 @@ function PN_API(setup) {
*/
'subscribe' : function( args, callback ) {
var channel = args['channel']
- , callback = callback || args['callback']
- , callback = callback || args['message']
- , connect = args['connect'] || function(){}
- , reconnect = args['reconnect'] || function(){}
- , disconnect = args['disconnect'] || function(){}
- , presence = args['presence'] || 0
- , noheresync = args['noheresync'] || 0
- , backfill = args['backfill'] || 0
- , sub_timeout = args['timeout'] || SUB_TIMEOUT
- , windowing = args['windowing'] || SUB_WINDOWING
+ , callback = callback || args['callback']
+ , callback = callback || args['message']
+ , connect = args['connect'] || function(){}
+ , reconnect = args['reconnect'] || function(){}
+ , disconnect = args['disconnect'] || function(){}
+ , presence = args['presence'] || 0
+ , noheresync = args['noheresync'] || 0
+ , backfill = args['backfill'] || 0
+ , sub_timeout = args['timeout'] || SUB_TIMEOUT
+ , windowing = args['windowing'] || SUB_WINDOWING
, restore = args['restore'];
// Restore Enabled?
@@ -545,7 +549,8 @@ function PN_API(setup) {
if (!channels) return;
// Connect to PubNub Subscribe Servers
- SUB_RECEIVER.push( xdr({
+ _reset_offline();
+ SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() { SELF['time'](_test_connection) },
@@ -606,20 +611,13 @@ function PN_API(setup) {
timeout( CONNECT, windowing );
}
- }));
- }
- function CLOSE_PREVIOUS_SUB() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ });
}
CONNECT = function() {
- CLOSE_PREVIOUS_SUB();
_connect();
};
-
// Reduce Status Flicker
if (!READY) return READY_BUFFER.push(CONNECT);
@@ -685,9 +683,7 @@ function PN_API(setup) {
}
function _reset_offline() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ SUB_RECEIVER && SUB_RECEIVER();
}
if (!UUID) UUID = SELF['uuid']();
View
28 modern/pubnub.min.js
@@ -1,23 +1,23 @@
// Version: 3.4.7
(function(){
-var j=!1;function k(){return function(){}}var aa=1,p=j,v=[],y=1E3,ba=/{([\w\-]+)}/g;function ca(){return"x"+ ++aa+""+ +new Date}function z(){return+new Date}var G,H=Math.floor(20*Math.random());G=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++H?H:H=1))||a};function da(a,c){function b(){f+c>z()?(clearTimeout(d),d=setTimeout(b,c)):(f=z(),a())}var d,f=0;return b}function ea(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
+var i=!1;function k(){return function(){}}var aa=1,p=i,v=[],y=1E3,ba=/{([\w\-]+)}/g;function ca(){return"x"+ ++aa+""+ +new Date}function z(){return+new Date}var G,I=Math.floor(20*Math.random());G=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++I?I:I=1))||a};function da(a,c){function b(){f+c>z()?(clearTimeout(d),d=setTimeout(b,c)):(f=z(),a())}var d,f=0;return b}function ea(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
function fa(a,c){return a.replace(ba,function(a,d){return c[d]||a})}function J(a){var c="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c=16*Math.random()|0;return("x"==a?c:c&3|8).toString(16)});a&&a(c);return c}function K(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])}function L(a,c){var b=[];K(a||[],function(a,f){b.push(c(a,f))});return b}
function M(a){return L(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function N(a){var c=[];K(a,function(a,d){d.i&&c.push(a)});return c.sort()}function ga(){setTimeout(function(){p||(p=1,K(v,function(a){a()}))},y)}
-function Q(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&O())}function b(){if(!s){s=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}B(response)}}var d,f=0,s=0,e;e=setTimeout(function(){c(1)},R);var I=a.data||{},O=a.b||k(),B=a.c||k(),q="undefined"===typeof a.j;try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;q&&(d.timeout=R);
-I.pnsdk=ha;var g=a.url.join("/"),r=[];I&&(K(I,function(a,b){r.push(a+"="+M(b))}),g+="?"+r.join("&"));url=g;d.open("GET",url,q);d.send()}catch(C){return c(0),Q(a)}return c}function S(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=j,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,j):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ia(a){console.error(a)}
+function Q(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&O())}function b(){if(!s){s=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}B(response)}}var d,f=0,s=0,e;e=setTimeout(function(){c(1)},R);var H=a.data||{},O=a.b||k(),B=a.c||k(),q="undefined"===typeof a.j;try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;q&&(d.timeout=R);
+H.pnsdk=ha;var g=a.url.join("/"),r=[];H&&(K(H,function(a,b){r.push(a+"="+M(b))}),g+="?"+r.join("&"));url=g;d.open("GET",url,q);d.send()}catch(C){return c(0),Q(a)}return c}function S(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=i,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,i):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ia(a){console.error(a)}
function ja(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)}function ka(a){return document.getElementById(a)}function la(a,c){var b=[];K(a.split(/\s+/),function(a){K((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b}function ma(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){}}function na(a){return document.createElement(a)}
-function T(a){function c(){}function b(){i.time(function(a){if(!a)for(;w.length;)w.shift()();setTimeout(b,B)})}function d(){if(!oa())for(;w.length;)w.shift()();setTimeout(d,y)}function f(a){K(N(m),function(b){(b=m[b])&&a(b)})}function s(a){a&&(t.g=0);!t.g&&t.length&&(t.g=1,u(t.shift()))}a.db=U;a.xdr=Q;a.error=ia;var e,I=+a.windowing||10,O=(+a.timeout||310)*y,B=(+a.keepalive||3600)*y,q=a.publish_key||"",g=a.subscribe_key||"",r=a.ssl?"s":"",C="http"+r+"://"+(a.origin||"pubsub.pubnub.com"),A=G(C),W=
-G(C),t=[],Y=0,Z=0,w=[],P=0,D=0,m={},u=a.xdr,h=a.error||k(),oa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},E=a.db||{get:k(),set:k()},F=a.uuid||E&&E.get(g+"uuid")||"",i={LEAVE:function(a,b){var c={uuid:F},d=G(C),e=x();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),u({j:b||r,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",M(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||k(),f=a.channel,i=
-a.start,m=a.end,n={},l=x();if(!f)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");n.stringtoken="true";n.count=c;n.reverse=d;l&&(n.callback=l);i&&(n.start=i);m&&(n.end=m);u({a:l,data:n,c:function(a){b(a)},b:e,url:[A,"v2","history","sub-key",g,"channel",M(f)]})},replay:function(a){var b=b||a.callback||k(),c=a.source,d=a.destination,e=a.stop,f=a.start,i=a.end,m=a.reverse,a=a.limit,n=x(),l={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");
-if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");"0"!=n&&(l.callback=n);e&&(l.stop="all");m&&(l.reverse="true");f&&(l.start=f);i&&(l.end=i);a&&(l.count=a);u({a:n,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[A,"v1","replay",q,g,c,d],data:l})},time:function(a){var b=x();u({a:b,timeout:5*y,url:[A,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||k(),c=a.message,d=a.channel,e=x();if(!c)return h("Missing Message");
-if(!d)return h("Missing Channel");if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[A,"publish",q,g,0,M(d),e,M(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:F},c:function(a){b(a);s(1)},b:function(){b([0,"Failed",c]);s(1)}});s()},unsubscribe:function(a){a=a.channel;D=0;P=1;a=L((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){p&&i.LEAVE(a,0);m[a]=0});p&&c()},subscribe:function(a,b){function d(a){a?
-setTimeout(c,y):(A=G(C,1),W=G(C,1),setTimeout(function(){i.time(d)},y));f(function(b){if(a&&b.d)return b.d=0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var e=a.channel,b=(b=b||a.callback)||a.message,q=a.connect||k(),s=a.reconnect||k(),t=a.disconnect||k(),r=a.presence||0,n=a.noheresync||0,l=a.backfill||0,B=a.timeout||O,$=a.windowing||I;P=a.restore;D=0;if(!e)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");K((e.join?e.join(","):""+e).split(","),
-function(a){var c=m[a]||{};m[Z=a]={name:a,f:c.f,d:c.d,i:1,a:Y=b,k:q,l:t,m:s};r&&(i.subscribe({channel:a+"-pnpres",callback:r}),!c.i&&!n&&i.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){r({action:"join",uuid:c,timestamp:z(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){for(;w.length;)w.shift()();var a=x(),b=N(m).join(",");b&&w.push(u({timeout:B,a:a,b:function(){i.time(d)},data:{uuid:F},url:[W,"subscribe",g,M(b),a,D],c:function(a){if(!a)return setTimeout(c,$);D=
-!D&&P&&E.get(g)||a[1];f(function(a){a.f||(a.f=1,a.k(a.name))});l&&(D=1E4,l=0);E.set(g,a[1]);var b,d=(2<a.length?a[2]:L(m,function(b){return L(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||Z;return[(m[a]||{}).a||Y,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,$)}}))};if(!p)return v.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||k(),d=a.channel,e=x(),f=null;if(!d)return h("Missing Channel");
-if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[A,"v2","presence","sub_key",g,"channel",M(d)]})},xdr:u,ready:ga,db:E,uuid:J,map:L,each:K,"each-channel":f,grep:ea,supplant:fa,now:z,unique:ca,updater:da};F||(F=i.uuid());E.set(g+"uuid",F);setTimeout(d,y);setTimeout(b,B);i.time(k());e=i;e.init=T;e.$=ka;e.attr=ja;e.search=la;e.bind=S;e.css=ma;e.create=na;S("beforeunload",window,function(){e["each-channel"](function(a){e.LEAVE(a.name,
-1)});return!0});if(a.notest)return e;S("offline",window,e._reset_offline);S("offline",document,e._reset_offline);e.ready();return e}var ha="PubNub-JS-Modern/3.4.7",R=31E4,U,V="undefined"!=typeof localStorage&&localStorage;U={get:function(a){try{return V?V.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(V)return V.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};
+function T(a){function c(){}function b(){j.time(function(a){a||w&&w();setTimeout(b,B)})}function d(){oa()||w&&w();setTimeout(d,y)}function f(a){var b=0;K(N(m),function(c){if(c=m[c])b++,(a||k())(c)});return b}function s(a){a&&(t.g=0);!t.g&&t.length&&(t.g=1,u(t.shift()))}a.db=U;a.xdr=Q;a.error=ia;var e,H=+a.windowing||10,O=(+a.timeout||310)*y,B=(+a.keepalive||3600)*y,q=a.publish_key||"",g=a.subscribe_key||"",r=a.ssl?"s":"",C="http"+r+"://"+(a.origin||"pubsub.pubnub.com"),A=G(C),W=G(C),t=[],Y=0,Z=0,
+w=0,P=0,D=0,m={},u=a.xdr,h=a.error||k(),oa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},E=a.db||{get:k(),set:k()},F=a.uuid||E&&E.get(g+"uuid")||"",j={LEAVE:function(a,b){var c={uuid:F},d=G(C),e=x();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),u({j:b||r,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",M(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||k(),f=a.channel,j=a.start,m=a.end,n=
+{},l=x();if(!f)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");n.stringtoken="true";n.count=c;n.reverse=d;l&&(n.callback=l);j&&(n.start=j);m&&(n.end=m);u({a:l,data:n,c:function(a){b(a)},b:e,url:[A,"v2","history","sub-key",g,"channel",M(f)]})},replay:function(a){var b=b||a.callback||k(),c=a.source,d=a.destination,e=a.stop,f=a.start,j=a.end,m=a.reverse,a=a.limit,n=x(),l={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");
+if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");"0"!=n&&(l.callback=n);e&&(l.stop="all");m&&(l.reverse="true");f&&(l.start=f);j&&(l.end=j);a&&(l.count=a);u({a:n,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[A,"v1","replay",q,g,c,d],data:l})},time:function(a){var b=x();u({a:b,timeout:5*y,url:[A,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||k(),c=a.message,d=a.channel,e=x();if(!c)return h("Missing Message");
+if(!d)return h("Missing Channel");if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[A,"publish",q,g,0,M(d),e,M(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:F},c:function(a){b(a);s(1)},b:function(){b([0,"Failed",c]);s(1)}});s()},unsubscribe:function(a){a=a.channel;D=0;P=1;a=L((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){p&&j.LEAVE(a,0);m[a]=0})},subscribe:function(a,b){function d(a){a?
+setTimeout(c,y):(A=G(C,1),W=G(C,1),setTimeout(function(){j.time(d)},y));f(function(b){if(a&&b.d)return b.d=0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var e=a.channel,b=(b=b||a.callback)||a.message,q=a.connect||k(),s=a.reconnect||k(),t=a.disconnect||k(),r=a.presence||0,n=a.noheresync||0,l=a.backfill||0,B=a.timeout||O,$=a.windowing||H;P=a.restore;D=0;if(!e)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");K((e.join?e.join(","):""+e).split(","),
+function(a){var c=m[a]||{};m[Z=a]={name:a,f:c.f,d:c.d,i:1,a:Y=b,k:q,l:t,m:s};r&&(j.subscribe({channel:a+"-pnpres",callback:r}),!c.i&&!n&&j.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){r({action:"join",uuid:c,timestamp:z(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){var a=x(),b=N(m).join(",");b&&(w&&w(),w=u({timeout:B,a:a,b:function(){j.time(d)},data:{uuid:F},url:[W,"subscribe",g,M(b),a,D],c:function(a){if(!a)return setTimeout(c,$);D=!D&&P&&E.get(g)||a[1];f(function(a){a.f||
+(a.f=1,a.k(a.name))});l&&(D=1E4,l=0);E.set(g,a[1]);var b,d=(2<a.length?a[2]:L(m,function(b){return L(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||Z;return[(m[a]||{}).a||Y,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,$)}}))};if(!p)return v.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||k(),d=a.channel,e=x(),f=null;if(!d)return h("Missing Channel");if(!b)return h("Missing Callback");
+if(!g)return h("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[A,"v2","presence","sub_key",g,"channel",M(d)]})},xdr:u,ready:ga,db:E,uuid:J,map:L,each:K,"each-channel":f,grep:ea,supplant:fa,now:z,unique:ca,updater:da};F||(F=j.uuid());E.set(g+"uuid",F);setTimeout(d,y);setTimeout(b,B);j.time(k());e=j;e.init=T;e.$=ka;e.attr=ja;e.search=la;e.bind=S;e.css=ma;e.create=na;S("beforeunload",window,function(){e["each-channel"](function(a){e.LEAVE(a.name,1)});return!0});
+if(a.notest)return e;S("offline",window,e._reset_offline);S("offline",document,e._reset_offline);e.ready();return e}var ha="PubNub-JS-Modern/3.4.7",R=31E4,U,V="undefined"!=typeof localStorage&&localStorage;U={get:function(a){try{return V?V.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(V)return V.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};
"undefined"!==typeof module&&(module.o=T)||"undefined"!==typeof exports&&(exports.n=T)||(PUBNUB=T);
var X=PUBNUB.ws=function(a,c){if(!(this instanceof X))return new X(a,c);var b=this,a=b.url=a||"";b.protocol=c||"Sec-WebSocket-Protocol";var d=a.split("/"),d={ssl:"wss:"===d[0],origin:d[2],publish_key:d[3],subscribe_key:d[4],channel:d[5]};b.CONNECTING=0;b.OPEN=1;b.CLOSING=2;b.CLOSED=3;b.CLOSE_NORMAL=1E3;b.CLOSE_GOING_AWAY=1001;b.CLOSE_PROTOCOL_ERROR=1002;b.CLOSE_UNSUPPORTED=1003;b.CLOSE_TOO_LARGE=1004;b.CLOSE_NO_STATUS=1005;b.CLOSE_ABNORMAL=1006;b.onclose=b.onerror=b.onmessage=b.onopen=b.onsend=k();
-b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=j;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.h=d;b.h=d;b.e.subscribe({restore:j,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:j})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
+b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=i;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.h=d;b.h=d;b.e.subscribe({restore:i,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:i})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
X.prototype.send=function(a){var c=this;c.e.publish({channel:c.e.h.channel,message:a,callback:function(a){c.onsend({data:a})}})};
})();
View
50 node.js/pubnub.js
@@ -200,7 +200,7 @@ function PN_API(setup) {
, PUB_QUEUE = []
, SUB_CALLBACK = 0
, SUB_CHANNEL = 0
- , SUB_RECEIVER = []
+ , SUB_RECEIVER = 0
, SUB_RESTORE = 0
, SUB_BUFF_WAIT = 0
, TIMETOKEN = 0
@@ -220,11 +220,18 @@ function PN_API(setup) {
}
function each_channel(callback) {
+ var count = 0;
+
each( generate_channel_list(CHANNELS), function(channel) {
var chan = CHANNELS[channel];
+
if (!chan) return;
- callback(chan);
+
+ count++;
+ (callback||function(){})(chan);
} );
+
+ return count;
}
// Announce Leave Event
@@ -422,9 +429,6 @@ function PN_API(setup) {
if (READY) SELF['LEAVE']( channel, 0 );
CHANNELS[channel] = 0;
} );
-
- // ReOpen Connection if Any Channels Left
- if (READY) CONNECT();
},
/*
@@ -435,16 +439,16 @@ function PN_API(setup) {
*/
'subscribe' : function( args, callback ) {
var channel = args['channel']
- , callback = callback || args['callback']
- , callback = callback || args['message']
- , connect = args['connect'] || function(){}
- , reconnect = args['reconnect'] || function(){}
- , disconnect = args['disconnect'] || function(){}
- , presence = args['presence'] || 0
- , noheresync = args['noheresync'] || 0
- , backfill = args['backfill'] || 0
- , sub_timeout = args['timeout'] || SUB_TIMEOUT
- , windowing = args['windowing'] || SUB_WINDOWING
+ , callback = callback || args['callback']
+ , callback = callback || args['message']
+ , connect = args['connect'] || function(){}
+ , reconnect = args['reconnect'] || function(){}
+ , disconnect = args['disconnect'] || function(){}
+ , presence = args['presence'] || 0
+ , noheresync = args['noheresync'] || 0
+ , backfill = args['backfill'] || 0
+ , sub_timeout = args['timeout'] || SUB_TIMEOUT
+ , windowing = args['windowing'] || SUB_WINDOWING
, restore = args['restore'];
// Restore Enabled?
@@ -545,7 +549,8 @@ function PN_API(setup) {
if (!channels) return;
// Connect to PubNub Subscribe Servers
- SUB_RECEIVER.push( xdr({
+ _reset_offline();
+ SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() { SELF['time'](_test_connection) },
@@ -606,20 +611,13 @@ function PN_API(setup) {
timeout( CONNECT, windowing );
}
- }));
- }
- function CLOSE_PREVIOUS_SUB() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ });
}
CONNECT = function() {
- CLOSE_PREVIOUS_SUB();
_connect();
};
-
// Reduce Status Flicker
if (!READY) return READY_BUFFER.push(CONNECT);
@@ -685,9 +683,7 @@ function PN_API(setup) {
}
function _reset_offline() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ SUB_RECEIVER && SUB_RECEIVER();
}
if (!UUID) UUID = SELF['uuid']();
View
50 phonegap/pubnub.js
@@ -200,7 +200,7 @@ function PN_API(setup) {
, PUB_QUEUE = []
, SUB_CALLBACK = 0
, SUB_CHANNEL = 0
- , SUB_RECEIVER = []
+ , SUB_RECEIVER = 0
, SUB_RESTORE = 0
, SUB_BUFF_WAIT = 0
, TIMETOKEN = 0
@@ -220,11 +220,18 @@ function PN_API(setup) {
}
function each_channel(callback) {
+ var count = 0;
+
each( generate_channel_list(CHANNELS), function(channel) {
var chan = CHANNELS[channel];
+
if (!chan) return;
- callback(chan);
+
+ count++;
+ (callback||function(){})(chan);
} );
+
+ return count;
}
// Announce Leave Event
@@ -422,9 +429,6 @@ function PN_API(setup) {
if (READY) SELF['LEAVE']( channel, 0 );
CHANNELS[channel] = 0;
} );
-
- // ReOpen Connection if Any Channels Left
- if (READY) CONNECT();
},
/*
@@ -435,16 +439,16 @@ function PN_API(setup) {
*/
'subscribe' : function( args, callback ) {
var channel = args['channel']
- , callback = callback || args['callback']
- , callback = callback || args['message']
- , connect = args['connect'] || function(){}
- , reconnect = args['reconnect'] || function(){}
- , disconnect = args['disconnect'] || function(){}
- , presence = args['presence'] || 0
- , noheresync = args['noheresync'] || 0
- , backfill = args['backfill'] || 0
- , sub_timeout = args['timeout'] || SUB_TIMEOUT
- , windowing = args['windowing'] || SUB_WINDOWING
+ , callback = callback || args['callback']
+ , callback = callback || args['message']
+ , connect = args['connect'] || function(){}
+ , reconnect = args['reconnect'] || function(){}
+ , disconnect = args['disconnect'] || function(){}
+ , presence = args['presence'] || 0
+ , noheresync = args['noheresync'] || 0
+ , backfill = args['backfill'] || 0
+ , sub_timeout = args['timeout'] || SUB_TIMEOUT
+ , windowing = args['windowing'] || SUB_WINDOWING
, restore = args['restore'];
// Restore Enabled?
@@ -545,7 +549,8 @@ function PN_API(setup) {
if (!channels) return;
// Connect to PubNub Subscribe Servers
- SUB_RECEIVER.push( xdr({
+ _reset_offline();
+ SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() { SELF['time'](_test_connection) },
@@ -606,20 +611,13 @@ function PN_API(setup) {
timeout( CONNECT, windowing );
}
- }));
- }
- function CLOSE_PREVIOUS_SUB() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ });
}
CONNECT = function() {
- CLOSE_PREVIOUS_SUB();
_connect();
};
-
// Reduce Status Flicker
if (!READY) return READY_BUFFER.push(CONNECT);
@@ -685,9 +683,7 @@ function PN_API(setup) {
}
function _reset_offline() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ SUB_RECEIVER && SUB_RECEIVER();
}
if (!UUID) UUID = SELF['uuid']();
View
28 phonegap/pubnub.min.js
@@ -1,23 +1,23 @@
// Version: 3.4.7
(function(){
-var j=!1;function k(){return function(){}}var aa=1,p=j,v=[],y=1E3,ba=/{([\w\-]+)}/g;function ca(){return"x"+ ++aa+""+ +new Date}function z(){return+new Date}var G,H=Math.floor(20*Math.random());G=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++H?H:H=1))||a};function da(a,c){function b(){f+c>z()?(clearTimeout(d),d=setTimeout(b,c)):(f=z(),a())}var d,f=0;return b}function ea(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
+var i=!1;function k(){return function(){}}var aa=1,p=i,v=[],y=1E3,ba=/{([\w\-]+)}/g;function ca(){return"x"+ ++aa+""+ +new Date}function z(){return+new Date}var G,I=Math.floor(20*Math.random());G=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++I?I:I=1))||a};function da(a,c){function b(){f+c>z()?(clearTimeout(d),d=setTimeout(b,c)):(f=z(),a())}var d,f=0;return b}function ea(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
function fa(a,c){return a.replace(ba,function(a,d){return c[d]||a})}function J(a){var c="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c=16*Math.random()|0;return("x"==a?c:c&3|8).toString(16)});a&&a(c);return c}function K(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])}function L(a,c){var b=[];K(a||[],function(a,f){b.push(c(a,f))});return b}
function M(a){return L(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function N(a){var c=[];K(a,function(a,d){d.i&&c.push(a)});return c.sort()}function ga(){setTimeout(function(){p||(p=1,K(v,function(a){a()}))},y)}
-function Q(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&O())}function b(){if(!s){s=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}B(response)}}var d,f=0,s=0,e;e=setTimeout(function(){c(1)},R);var I=a.data||{},O=a.b||k(),B=a.c||k(),q="undefined"===typeof a.j;try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;q&&(d.timeout=R);
-I.pnsdk=ha;var g=a.url.join("/"),r=[];I&&(K(I,function(a,b){r.push(a+"="+M(b))}),g+="?"+r.join("&"));url=g;d.open("GET",url,q);d.send()}catch(C){return c(0),Q(a)}return c}function S(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=j,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,j):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ia(a){console.error(a)}
+function Q(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&O())}function b(){if(!s){s=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}B(response)}}var d,f=0,s=0,e;e=setTimeout(function(){c(1)},R);var H=a.data||{},O=a.b||k(),B=a.c||k(),q="undefined"===typeof a.j;try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;q&&(d.timeout=R);
+H.pnsdk=ha;var g=a.url.join("/"),r=[];H&&(K(H,function(a,b){r.push(a+"="+M(b))}),g+="?"+r.join("&"));url=g;d.open("GET",url,q);d.send()}catch(C){return c(0),Q(a)}return c}function S(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=i,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,i):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ia(a){console.error(a)}
function ja(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)}function ka(a){return document.getElementById(a)}function la(a,c){var b=[];K(a.split(/\s+/),function(a){K((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b}function ma(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){}}function na(a){return document.createElement(a)}
-function T(a){function c(){}function b(){i.time(function(a){if(!a)for(;w.length;)w.shift()();setTimeout(b,B)})}function d(){if(!oa())for(;w.length;)w.shift()();setTimeout(d,y)}function f(a){K(N(m),function(b){(b=m[b])&&a(b)})}function s(a){a&&(t.g=0);!t.g&&t.length&&(t.g=1,u(t.shift()))}a.db=U;a.xdr=Q;a.error=ia;var e,I=+a.windowing||10,O=(+a.timeout||310)*y,B=(+a.keepalive||3600)*y,q=a.publish_key||"",g=a.subscribe_key||"",r=a.ssl?"s":"",C="http"+r+"://"+(a.origin||"pubsub.pubnub.com"),A=G(C),W=
-G(C),t=[],Y=0,Z=0,w=[],P=0,D=0,m={},u=a.xdr,h=a.error||k(),oa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},E=a.db||{get:k(),set:k()},F=a.uuid||E&&E.get(g+"uuid")||"",i={LEAVE:function(a,b){var c={uuid:F},d=G(C),e=x();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),u({j:b||r,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",M(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||k(),f=a.channel,i=
-a.start,m=a.end,n={},l=x();if(!f)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");n.stringtoken="true";n.count=c;n.reverse=d;l&&(n.callback=l);i&&(n.start=i);m&&(n.end=m);u({a:l,data:n,c:function(a){b(a)},b:e,url:[A,"v2","history","sub-key",g,"channel",M(f)]})},replay:function(a){var b=b||a.callback||k(),c=a.source,d=a.destination,e=a.stop,f=a.start,i=a.end,m=a.reverse,a=a.limit,n=x(),l={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");
-if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");"0"!=n&&(l.callback=n);e&&(l.stop="all");m&&(l.reverse="true");f&&(l.start=f);i&&(l.end=i);a&&(l.count=a);u({a:n,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[A,"v1","replay",q,g,c,d],data:l})},time:function(a){var b=x();u({a:b,timeout:5*y,url:[A,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||k(),c=a.message,d=a.channel,e=x();if(!c)return h("Missing Message");
-if(!d)return h("Missing Channel");if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[A,"publish",q,g,0,M(d),e,M(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:F},c:function(a){b(a);s(1)},b:function(){b([0,"Failed",c]);s(1)}});s()},unsubscribe:function(a){a=a.channel;D=0;P=1;a=L((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){p&&i.LEAVE(a,0);m[a]=0});p&&c()},subscribe:function(a,b){function d(a){a?
-setTimeout(c,y):(A=G(C,1),W=G(C,1),setTimeout(function(){i.time(d)},y));f(function(b){if(a&&b.d)return b.d=0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var e=a.channel,b=(b=b||a.callback)||a.message,q=a.connect||k(),s=a.reconnect||k(),t=a.disconnect||k(),r=a.presence||0,n=a.noheresync||0,l=a.backfill||0,B=a.timeout||O,$=a.windowing||I;P=a.restore;D=0;if(!e)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");K((e.join?e.join(","):""+e).split(","),
-function(a){var c=m[a]||{};m[Z=a]={name:a,f:c.f,d:c.d,i:1,a:Y=b,k:q,l:t,m:s};r&&(i.subscribe({channel:a+"-pnpres",callback:r}),!c.i&&!n&&i.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){r({action:"join",uuid:c,timestamp:z(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){for(;w.length;)w.shift()();var a=x(),b=N(m).join(",");b&&w.push(u({timeout:B,a:a,b:function(){i.time(d)},data:{uuid:F},url:[W,"subscribe",g,M(b),a,D],c:function(a){if(!a)return setTimeout(c,$);D=
-!D&&P&&E.get(g)||a[1];f(function(a){a.f||(a.f=1,a.k(a.name))});l&&(D=1E4,l=0);E.set(g,a[1]);var b,d=(2<a.length?a[2]:L(m,function(b){return L(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||Z;return[(m[a]||{}).a||Y,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,$)}}))};if(!p)return v.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||k(),d=a.channel,e=x(),f=null;if(!d)return h("Missing Channel");
-if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[A,"v2","presence","sub_key",g,"channel",M(d)]})},xdr:u,ready:ga,db:E,uuid:J,map:L,each:K,"each-channel":f,grep:ea,supplant:fa,now:z,unique:ca,updater:da};F||(F=i.uuid());E.set(g+"uuid",F);setTimeout(d,y);setTimeout(b,B);i.time(k());e=i;e.init=T;e.$=ka;e.attr=ja;e.search=la;e.bind=S;e.css=ma;e.create=na;S("beforeunload",window,function(){e["each-channel"](function(a){e.LEAVE(a.name,
-1)});return!0});if(a.notest)return e;S("offline",window,e._reset_offline);S("offline",document,e._reset_offline);e.ready();return e}var ha="PubNub-JS-Phonegap/3.4.7",R=31E4,U,V="undefined"!=typeof localStorage&&localStorage;U={get:function(a){try{return V?V.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(V)return V.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};
+function T(a){function c(){}function b(){j.time(function(a){a||w&&w();setTimeout(b,B)})}function d(){oa()||w&&w();setTimeout(d,y)}function f(a){var b=0;K(N(m),function(c){if(c=m[c])b++,(a||k())(c)});return b}function s(a){a&&(t.g=0);!t.g&&t.length&&(t.g=1,u(t.shift()))}a.db=U;a.xdr=Q;a.error=ia;var e,H=+a.windowing||10,O=(+a.timeout||310)*y,B=(+a.keepalive||3600)*y,q=a.publish_key||"",g=a.subscribe_key||"",r=a.ssl?"s":"",C="http"+r+"://"+(a.origin||"pubsub.pubnub.com"),A=G(C),W=G(C),t=[],Y=0,Z=0,
+w=0,P=0,D=0,m={},u=a.xdr,h=a.error||k(),oa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},E=a.db||{get:k(),set:k()},F=a.uuid||E&&E.get(g+"uuid")||"",j={LEAVE:function(a,b){var c={uuid:F},d=G(C),e=x();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),u({j:b||r,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",M(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||k(),f=a.channel,j=a.start,m=a.end,n=
+{},l=x();if(!f)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");n.stringtoken="true";n.count=c;n.reverse=d;l&&(n.callback=l);j&&(n.start=j);m&&(n.end=m);u({a:l,data:n,c:function(a){b(a)},b:e,url:[A,"v2","history","sub-key",g,"channel",M(f)]})},replay:function(a){var b=b||a.callback||k(),c=a.source,d=a.destination,e=a.stop,f=a.start,j=a.end,m=a.reverse,a=a.limit,n=x(),l={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");
+if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");"0"!=n&&(l.callback=n);e&&(l.stop="all");m&&(l.reverse="true");f&&(l.start=f);j&&(l.end=j);a&&(l.count=a);u({a:n,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[A,"v1","replay",q,g,c,d],data:l})},time:function(a){var b=x();u({a:b,timeout:5*y,url:[A,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||k(),c=a.message,d=a.channel,e=x();if(!c)return h("Missing Message");
+if(!d)return h("Missing Channel");if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[A,"publish",q,g,0,M(d),e,M(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:F},c:function(a){b(a);s(1)},b:function(){b([0,"Failed",c]);s(1)}});s()},unsubscribe:function(a){a=a.channel;D=0;P=1;a=L((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){p&&j.LEAVE(a,0);m[a]=0})},subscribe:function(a,b){function d(a){a?
+setTimeout(c,y):(A=G(C,1),W=G(C,1),setTimeout(function(){j.time(d)},y));f(function(b){if(a&&b.d)return b.d=0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var e=a.channel,b=(b=b||a.callback)||a.message,q=a.connect||k(),s=a.reconnect||k(),t=a.disconnect||k(),r=a.presence||0,n=a.noheresync||0,l=a.backfill||0,B=a.timeout||O,$=a.windowing||H;P=a.restore;D=0;if(!e)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");K((e.join?e.join(","):""+e).split(","),
+function(a){var c=m[a]||{};m[Z=a]={name:a,f:c.f,d:c.d,i:1,a:Y=b,k:q,l:t,m:s};r&&(j.subscribe({channel:a+"-pnpres",callback:r}),!c.i&&!n&&j.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){r({action:"join",uuid:c,timestamp:z(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){var a=x(),b=N(m).join(",");b&&(w&&w(),w=u({timeout:B,a:a,b:function(){j.time(d)},data:{uuid:F},url:[W,"subscribe",g,M(b),a,D],c:function(a){if(!a)return setTimeout(c,$);D=!D&&P&&E.get(g)||a[1];f(function(a){a.f||
+(a.f=1,a.k(a.name))});l&&(D=1E4,l=0);E.set(g,a[1]);var b,d=(2<a.length?a[2]:L(m,function(b){return L(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||Z;return[(m[a]||{}).a||Y,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,$)}}))};if(!p)return v.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||k(),d=a.channel,e=x(),f=null;if(!d)return h("Missing Channel");if(!b)return h("Missing Callback");
+if(!g)return h("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[A,"v2","presence","sub_key",g,"channel",M(d)]})},xdr:u,ready:ga,db:E,uuid:J,map:L,each:K,"each-channel":f,grep:ea,supplant:fa,now:z,unique:ca,updater:da};F||(F=j.uuid());E.set(g+"uuid",F);setTimeout(d,y);setTimeout(b,B);j.time(k());e=j;e.init=T;e.$=ka;e.attr=ja;e.search=la;e.bind=S;e.css=ma;e.create=na;S("beforeunload",window,function(){e["each-channel"](function(a){e.LEAVE(a.name,1)});return!0});
+if(a.notest)return e;S("offline",window,e._reset_offline);S("offline",document,e._reset_offline);e.ready();return e}var ha="PubNub-JS-Phonegap/3.4.7",R=31E4,U,V="undefined"!=typeof localStorage&&localStorage;U={get:function(a){try{return V?V.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(V)return V.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};
"undefined"!==typeof module&&(module.o=T)||"undefined"!==typeof exports&&(exports.n=T)||(PUBNUB=T);
var X=PUBNUB.ws=function(a,c){if(!(this instanceof X))return new X(a,c);var b=this,a=b.url=a||"";b.protocol=c||"Sec-WebSocket-Protocol";var d=a.split("/"),d={ssl:"wss:"===d[0],origin:d[2],publish_key:d[3],subscribe_key:d[4],channel:d[5]};b.CONNECTING=0;b.OPEN=1;b.CLOSING=2;b.CLOSED=3;b.CLOSE_NORMAL=1E3;b.CLOSE_GOING_AWAY=1001;b.CLOSE_PROTOCOL_ERROR=1002;b.CLOSE_UNSUPPORTED=1003;b.CLOSE_TOO_LARGE=1004;b.CLOSE_NO_STATUS=1005;b.CLOSE_ABNORMAL=1006;b.onclose=b.onerror=b.onmessage=b.onopen=b.onsend=k();
-b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=j;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.h=d;b.h=d;b.e.subscribe({restore:j,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:j})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
+b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=i;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.h=d;b.h=d;b.e.subscribe({restore:i,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:i})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
X.prototype.send=function(a){var c=this;c.e.publish({channel:c.e.h.channel,message:a,callback:function(a){c.onsend({data:a})}})};
})();
View
50 sencha/pubnub.js
@@ -200,7 +200,7 @@ function PN_API(setup) {
, PUB_QUEUE = []
, SUB_CALLBACK = 0
, SUB_CHANNEL = 0
- , SUB_RECEIVER = []
+ , SUB_RECEIVER = 0
, SUB_RESTORE = 0
, SUB_BUFF_WAIT = 0
, TIMETOKEN = 0
@@ -220,11 +220,18 @@ function PN_API(setup) {
}
function each_channel(callback) {
+ var count = 0;
+
each( generate_channel_list(CHANNELS), function(channel) {
var chan = CHANNELS[channel];
+
if (!chan) return;
- callback(chan);
+
+ count++;
+ (callback||function(){})(chan);
} );
+
+ return count;
}
// Announce Leave Event
@@ -422,9 +429,6 @@ function PN_API(setup) {
if (READY) SELF['LEAVE']( channel, 0 );
CHANNELS[channel] = 0;
} );
-
- // ReOpen Connection if Any Channels Left
- if (READY) CONNECT();
},
/*
@@ -435,16 +439,16 @@ function PN_API(setup) {
*/
'subscribe' : function( args, callback ) {
var channel = args['channel']
- , callback = callback || args['callback']
- , callback = callback || args['message']
- , connect = args['connect'] || function(){}
- , reconnect = args['reconnect'] || function(){}
- , disconnect = args['disconnect'] || function(){}
- , presence = args['presence'] || 0
- , noheresync = args['noheresync'] || 0
- , backfill = args['backfill'] || 0
- , sub_timeout = args['timeout'] || SUB_TIMEOUT
- , windowing = args['windowing'] || SUB_WINDOWING
+ , callback = callback || args['callback']
+ , callback = callback || args['message']
+ , connect = args['connect'] || function(){}
+ , reconnect = args['reconnect'] || function(){}
+ , disconnect = args['disconnect'] || function(){}
+ , presence = args['presence'] || 0
+ , noheresync = args['noheresync'] || 0
+ , backfill = args['backfill'] || 0
+ , sub_timeout = args['timeout'] || SUB_TIMEOUT
+ , windowing = args['windowing'] || SUB_WINDOWING
, restore = args['restore'];
// Restore Enabled?
@@ -545,7 +549,8 @@ function PN_API(setup) {
if (!channels) return;
// Connect to PubNub Subscribe Servers
- SUB_RECEIVER.push( xdr({
+ _reset_offline();
+ SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() { SELF['time'](_test_connection) },
@@ -606,20 +611,13 @@ function PN_API(setup) {
timeout( CONNECT, windowing );
}
- }));
- }
- function CLOSE_PREVIOUS_SUB() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ });
}
CONNECT = function() {
- CLOSE_PREVIOUS_SUB();
_connect();
};
-
// Reduce Status Flicker
if (!READY) return READY_BUFFER.push(CONNECT);
@@ -685,9 +683,7 @@ function PN_API(setup) {
}
function _reset_offline() {
- while (SUB_RECEIVER.length) {
- (SUB_RECEIVER.shift())();
- }
+ SUB_RECEIVER && SUB_RECEIVER();
}
if (!UUID) UUID = SELF['uuid']();
View
28 sencha/pubnub.min.js
@@ -1,23 +1,23 @@
// Version: 3.4.7
(function(){
-var j=!1;function k(){return function(){}}var aa=1,p=j,v=[],y=1E3,ba=/{([\w\-]+)}/g;function ca(){return"x"+ ++aa+""+ +new Date}function z(){return+new Date}var G,H=Math.floor(20*Math.random());G=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++H?H:H=1))||a};function da(a,c){function b(){f+c>z()?(clearTimeout(d),d=setTimeout(b,c)):(f=z(),a())}var d,f=0;return b}function ea(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
+var i=!1;function k(){return function(){}}var aa=1,p=i,v=[],y=1E3,ba=/{([\w\-]+)}/g;function ca(){return"x"+ ++aa+""+ +new Date}function z(){return+new Date}var G,I=Math.floor(20*Math.random());G=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++I?I:I=1))||a};function da(a,c){function b(){f+c>z()?(clearTimeout(d),d=setTimeout(b,c)):(f=z(),a())}var d,f=0;return b}function ea(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
function fa(a,c){return a.replace(ba,function(a,d){return c[d]||a})}function J(a){var c="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c=16*Math.random()|0;return("x"==a?c:c&3|8).toString(16)});a&&a(c);return c}function K(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])}function L(a,c){var b=[];K(a||[],function(a,f){b.push(c(a,f))});return b}
function M(a){return L(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function N(a){var c=[];K(a,function(a,d){d.i&&c.push(a)});return c.sort()}function ga(){setTimeout(function(){p||(p=1,K(v,function(a){a()}))},y)}
-function Q(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&O())}function b(){if(!s){s=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}B(response)}}var d,f=0,s=0,e;e=setTimeout(function(){c(1)},R);var I=a.data||{},O=a.b||k(),B=a.c||k(),q="undefined"===typeof a.j;try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;q&&(d.timeout=R);
-I.pnsdk=ha;var g=a.url.join("/"),r=[];I&&(K(I,function(a,b){r.push(a+"="+M(b))}),g+="?"+r.join("&"));url=g;d.open("GET",url,q);d.send()}catch(C){return c(0),Q(a)}return c}function S(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=j,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,j):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ia(a){console.error(a)}
+function Q(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&O())}function b(){if(!s){s=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}B(response)}}var d,f=0,s=0,e;e=setTimeout(function(){c(1)},R);var H=a.data||{},O=a.b||k(),B=a.c||k(),q="undefined"===typeof a.j;try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;q&&(d.timeout=R);
+H.pnsdk=ha;var g=a.url.join("/"),r=[];H&&(K(H,function(a,b){r.push(a+"="+M(b))}),g+="?"+r.join("&"));url=g;d.open("GET",url,q);d.send()}catch(C){return c(0),Q(a)}return c}function S(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=i,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,i):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ia(a){console.error(a)}
function ja(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)}function ka(a){return document.getElementById(a)}function la(a,c){var b=[];K(a.split(/\s+/),function(a){K((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b}function ma(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){}}function na(a){return document.createElement(a)}
-function T(a){function c(){}function b(){i.time(function(a){if(!a)for(;w.length;)w.shift()();setTimeout(b,B)})}function d(){if(!oa())for(;w.length;)w.shift()();setTimeout(d,y)}function f(a){K(N(m),function(b){(b=m[b])&&a(b)})}function s(a){a&&(t.g=0);!t.g&&t.length&&(t.g=1,u(t.shift()))}a.db=U;a.xdr=Q;a.error=ia;var e,I=+a.windowing||10,O=(+a.timeout||310)*y,B=(+a.keepalive||3600)*y,q=a.publish_key||"",g=a.subscribe_key||"",r=a.ssl?"s":"",C="http"+r+"://"+(a.origin||"pubsub.pubnub.com"),A=G(C),W=
-G(C),t=[],Y=0,Z=0,w=[],P=0,D=0,m={},u=a.xdr,h=a.error||k(),oa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},E=a.db||{get:k(),set:k()},F=a.uuid||E&&E.get(g+"uuid")||"",i={LEAVE:function(a,b){var c={uuid:F},d=G(C),e=x();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),u({j:b||r,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",M(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||k(),f=a.channel,i=
-a.start,m=a.end,n={},l=x();if(!f)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");n.stringtoken="true";n.count=c;n.reverse=d;l&&(n.callback=l);i&&(n.start=i);m&&(n.end=m);u({a:l,data:n,c:function(a){b(a)},b:e,url:[A,"v2","history","sub-key",g,"channel",M(f)]})},replay:function(a){var b=b||a.callback||k(),c=a.source,d=a.destination,e=a.stop,f=a.start,i=a.end,m=a.reverse,a=a.limit,n=x(),l={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");
-if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");"0"!=n&&(l.callback=n);e&&(l.stop="all");m&&(l.reverse="true");f&&(l.start=f);i&&(l.end=i);a&&(l.count=a);u({a:n,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[A,"v1","replay",q,g,c,d],data:l})},time:function(a){var b=x();u({a:b,timeout:5*y,url:[A,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||k(),c=a.message,d=a.channel,e=x();if(!c)return h("Missing Message");
-if(!d)return h("Missing Channel");if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[A,"publish",q,g,0,M(d),e,M(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:F},c:function(a){b(a);s(1)},b:function(){b([0,"Failed",c]);s(1)}});s()},unsubscribe:function(a){a=a.channel;D=0;P=1;a=L((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){p&&i.LEAVE(a,0);m[a]=0});p&&c()},subscribe:function(a,b){function d(a){a?
-setTimeout(c,y):(A=G(C,1),W=G(C,1),setTimeout(function(){i.time(d)},y));f(function(b){if(a&&b.d)return b.d=0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var e=a.channel,b=(b=b||a.callback)||a.message,q=a.connect||k(),s=a.reconnect||k(),t=a.disconnect||k(),r=a.presence||0,n=a.noheresync||0,l=a.backfill||0,B=a.timeout||O,$=a.windowing||I;P=a.restore;D=0;if(!e)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");K((e.join?e.join(","):""+e).split(","),
-function(a){var c=m[a]||{};m[Z=a]={name:a,f:c.f,d:c.d,i:1,a:Y=b,k:q,l:t,m:s};r&&(i.subscribe({channel:a+"-pnpres",callback:r}),!c.i&&!n&&i.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){r({action:"join",uuid:c,timestamp:z(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){for(;w.length;)w.shift()();var a=x(),b=N(m).join(",");b&&w.push(u({timeout:B,a:a,b:function(){i.time(d)},data:{uuid:F},url:[W,"subscribe",g,M(b),a,D],c:function(a){if(!a)return setTimeout(c,$);D=
-!D&&P&&E.get(g)||a[1];f(function(a){a.f||(a.f=1,a.k(a.name))});l&&(D=1E4,l=0);E.set(g,a[1]);var b,d=(2<a.length?a[2]:L(m,function(b){return L(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||Z;return[(m[a]||{}).a||Y,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,$)}}))};if(!p)return v.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||k(),d=a.channel,e=x(),f=null;if(!d)return h("Missing Channel");
-if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[A,"v2","presence","sub_key",g,"channel",M(d)]})},xdr:u,ready:ga,db:E,uuid:J,map:L,each:K,"each-channel":f,grep:ea,supplant:fa,now:z,unique:ca,updater:da};F||(F=i.uuid());E.set(g+"uuid",F);setTimeout(d,y);setTimeout(b,B);i.time(k());e=i;e.init=T;e.$=ka;e.attr=ja;e.search=la;e.bind=S;e.css=ma;e.create=na;S("beforeunload",window,function(){e["each-channel"](function(a){e.LEAVE(a.name,
-1)});return!0});if(a.notest)return e;S("offline",window,e._reset_offline);S("offline",document,e._reset_offline);e.ready();return e}var ha="PubNub-JS-Sencha/3.4.7",R=31E4,U,V="undefined"!=typeof localStorage&&localStorage;U={get:function(a){try{return V?V.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(V)return V.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};
+function T(a){function c(){}function b(){j.time(function(a){a||w&&w();setTimeout(b,B)})}function d(){oa()||w&&w();setTimeout(d,y)}function f(a){var b=0;K(N(m),function(c){if(c=m[c])b++,(a||k())(c)});return b}function s(a){a&&(t.g=0);!t.g&&t.length&&(t.g=1,u(t.shift()))}a.db=U;a.xdr=Q;a.error=ia;var e,H=+a.windowing||10,O=(+a.timeout||310)*y,B=(+a.keepalive||3600)*y,q=a.publish_key||"",g=a.subscribe_key||"",r=a.ssl?"s":"",C="http"+r+"://"+(a.origin||"pubsub.pubnub.com"),A=G(C),W=G(C),t=[],Y=0,Z=0,
+w=0,P=0,D=0,m={},u=a.xdr,h=a.error||k(),oa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},E=a.db||{get:k(),set:k()},F=a.uuid||E&&E.get(g+"uuid")||"",j={LEAVE:function(a,b){var c={uuid:F},d=G(C),e=x();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),u({j:b||r,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",g,"channel",M(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||k(),f=a.channel,j=a.start,m=a.end,n=
+{},l=x();if(!f)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");n.stringtoken="true";n.count=c;n.reverse=d;l&&(n.callback=l);j&&(n.start=j);m&&(n.end=m);u({a:l,data:n,c:function(a){b(a)},b:e,url:[A,"v2","history","sub-key",g,"channel",M(f)]})},replay:function(a){var b=b||a.callback||k(),c=a.source,d=a.destination,e=a.stop,f=a.start,j=a.end,m=a.reverse,a=a.limit,n=x(),l={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");
+if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");"0"!=n&&(l.callback=n);e&&(l.stop="all");m&&(l.reverse="true");f&&(l.start=f);j&&(l.end=j);a&&(l.count=a);u({a:n,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[A,"v1","replay",q,g,c,d],data:l})},time:function(a){var b=x();u({a:b,timeout:5*y,url:[A,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||k(),c=a.message,d=a.channel,e=x();if(!c)return h("Missing Message");
+if(!d)return h("Missing Channel");if(!q)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[A,"publish",q,g,0,M(d),e,M(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:F},c:function(a){b(a);s(1)},b:function(){b([0,"Failed",c]);s(1)}});s()},unsubscribe:function(a){a=a.channel;D=0;P=1;a=L((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){p&&j.LEAVE(a,0);m[a]=0})},subscribe:function(a,b){function d(a){a?
+setTimeout(c,y):(A=G(C,1),W=G(C,1),setTimeout(function(){j.time(d)},y));f(function(b){if(a&&b.d)return b.d=0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var e=a.channel,b=(b=b||a.callback)||a.message,q=a.connect||k(),s=a.reconnect||k(),t=a.disconnect||k(),r=a.presence||0,n=a.noheresync||0,l=a.backfill||0,B=a.timeout||O,$=a.windowing||H;P=a.restore;D=0;if(!e)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");K((e.join?e.join(","):""+e).split(","),
+function(a){var c=m[a]||{};m[Z=a]={name:a,f:c.f,d:c.d,i:1,a:Y=b,k:q,l:t,m:s};r&&(j.subscribe({channel:a+"-pnpres",callback:r}),!c.i&&!n&&j.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){r({action:"join",uuid:c,timestamp:z(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){var a=x(),b=N(m).join(",");b&&(w&&w(),w=u({timeout:B,a:a,b:function(){j.time(d)},data:{uuid:F},url:[W,"subscribe",g,M(b),a,D],c:function(a){if(!a)return setTimeout(c,$);D=!D&&P&&E.get(g)||a[1];f(function(a){a.f||
+(a.f=1,a.k(a.name))});l&&(D=1E4,l=0);E.set(g,a[1]);var b,d=(2<a.length?a[2]:L(m,function(b){return L(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||Z;return[(m[a]||{}).a||Y,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,$)}}))};if(!p)return v.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||k(),d=a.channel,e=x(),f=null;if(!d)return h("Missing Channel");if(!b)return h("Missing Callback");
+if(!g)return h("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[A,"v2","presence","sub_key",g,"channel",M(d)]})},xdr:u,ready:ga,db:E,uuid:J,map:L,each:K,"each-channel":f,grep:ea,supplant:fa,now:z,unique:ca,updater:da};F||(F=j.uuid());E.set(g+"uuid",F);setTimeout(d,y);setTimeout(b,B);j.time(k());e=j;e.init=T;e.$=ka;e.attr=ja;e.search=la;e.bind=S;e.css=ma;e.create=na;S("beforeunload",window,function(){e["each-channel"](function(a){e.LEAVE(a.name,1)});return!0});
+if(a.notest)return e;S("offline",window,e._reset_offline);S("offline",document,e._reset_offline);e.ready();return e}var ha="PubNub-JS-Sencha/3.4.7",R=31E4,U,V="undefined"!=typeof localStorage&&localStorage;U={get:function(a){try{return V?V.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(c){}},set:function(a,c){try{if(V)return V.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};
"undefined"!==typeof module&&(module.o=T)||"undefined"!==typeof exports&&(exports.n=T)||(PUBNUB=T);
var X=PUBNUB.ws=function(a,c){if(!(this instanceof X))return new X(a,c);var b=this,a=b.url=a||"";b.protocol=c||"Sec-WebSocket-Protocol";var d=a.split("/"),d={ssl:"wss:"===d[0],origin:d[2],publish_key:d[3],subscribe_key:d[4],channel:d[5]};b.CONNECTING=0;b.OPEN=1;b.CLOSING=2;b.CLOSED=3;b.CLOSE_NORMAL=1E3;b.CLOSE_GOING_AWAY=1001;b.CLOSE_PROTOCOL_ERROR=1002;b.CLOSE_UNSUPPORTED=1003;b.CLOSE_TOO_LARGE=1004;b.CLOSE_NO_STATUS=1005;b.CLOSE_ABNORMAL=1006;b.onclose=b.onerror=b.onmessage=b.onopen=b.onsend=k();
-b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=j;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.h=d;b.h=d;b.e.subscribe({restore:j,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:j})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
+b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=i;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.h=d;b.h=d;b.e.subscribe({restore:i,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:i})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
X.prototype.send=function(a){var c=this;c.e.publish({channel:c.e.h.channel,message:a,callback:function(a){c.onsend({data:a})}})};
})();
View
7 socket.io/Makefile
@@ -8,8 +8,7 @@ SOCKET_IO_MIN_JS=socket.io.min.js
OUTPUT_FILES=$(SOCKET_IO_MIN_JS)
SOCKET_IO_TMP=socket.io.tmp
-GIBBERISH_AES_JS=$(CRYPTO_DIR)/gibberish-aes.js
-ENCRYPT_PUBNUB_JS=$(CRYPTO_DIR)/encrypt-pubnub.js
+GIBBERISH_AES_JS=$(WEB_DIR)/pubnub-crypto.min.js
.PHONY : all
all: build
@@ -17,11 +16,9 @@ all: build
.PHONY : build
build: $(SOCKET_IO_MIN_JS)
-
-
$(SOCKET_IO_MIN_JS): $(SOCKET_IO_BASE_JS) $(PUBNUB_MIN_JS)
cat $(SOCKET_IO_BASE_JS) | java -jar $(GOOGLE_MINIFY) > $(SOCKET_IO_TMP)
- cat $(PUBNUB_MIN_JS) $(GIBBERISH_AES_JS) $(ENCRYPT_PUBNUB_JS) $(SOCKET_IO_TMP) > $(SOCKET_IO_MIN_JS)
+ cat $(PUBNUB_MIN_JS) $(GIBBERISH_AES_JS) $(SOCKET_IO_TMP) > $(SOCKET_IO_MIN_JS)
rm $(SOCKET_IO_TMP)
.PHONY : clean
View
1,248 socket.io/socket.io.min.js
@@ -6,1224 +6,54 @@ case "object":if(!g)return"null";e+=p;h=[];if("[object Array]"===Object.prototyp
r+"}":"{"+h.join(",")+"}";e=r;return j}}window.JSON||(window.JSON={});var d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,e,p,u={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},f;"function"!==typeof JSON.stringify&&(JSON.stringify=function(a,c,d){var k;p=e="";if("number"===typeof d)for(k=0;k<d;k+=1)p+=" ";else"string"===typeof d&&(p=d);if((f=c)&&"function"!==typeof c&&("object"!==typeof c||"number"!==
typeof c.length))throw Error("JSON.stringify");return b("",{"":a})});"function"!==typeof JSON.parse&&(JSON.parse=function(a){return eval("("+a+")")})}();var aa=1,v=q,ba=[],y=1E3,da="/",ea="&",fa=/{([\w\-]+)}/g;function B(){return"x"+ ++aa+""+ +new Date}function C(){return+new Date}var E,G=Math.floor(20*Math.random());E=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?ga().split("-")[0]:20>++G?G:G=1))||a};
function ha(a,c){var b=a.join(da),d=[];if(!c)return b;K(c,function(a,b){d.push(a+"="+L(b))});return b+="?"+d.join(ea)}function ia(a,c){function b(){e+c>C()?(clearTimeout(d),d=setTimeout(b,c)):(e=C(),a())}var d,e=0;return b}function ja(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}function ka(a,c){return a.replace(fa,function(a,d){return c[d]||a})}
-function ga(a){var c="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c=16*Math.random()|0;return("x"==a?c:c&3|8).toString(16)});a&&a(c);return c}function K(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])}function M(a,c){var b=[];K(a||[],function(a,e){b.push(c(a,e))});return b}
-function L(a){return M(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function la(a){var c=[];K(a,function(a,d){d.j&&c.push(a)});return c.sort()}function P(){setTimeout(function(){v||(v=1,K(ba,function(a){a()}))},y)}
-if(!window.PUBNUB){var Q=function(a){return document.getElementById(a)},ma=function(a){console.error(a)},na=function(a,c){var b=[];K(a.split(/\s+/),function(a){K((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b},R=function(a,c,b){K(a.split(","),function(a){function e(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=q,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,e,q):c.attachEvent?c.attachEvent("on"+
-a,e):c["on"+a]=e})},oa=function(){return na("head")[0]},T=function(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)},qa=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){}},ra=function(a){return document.createElement(a)},sa=function(){return U||V()?0:B()},ua=function(a){function c(a,b){N||(N=1,a||O(b),g.onerror=m,clearTimeout(W),setTimeout(function(){a&&w();var b=
-Q(t),c=b&&b.parentNode;c&&c.removeChild(b)},y))}if(U||V()){a:{var b,d,e=function(){if(!u){u=1;clearTimeout(S);try{d=JSON.parse(b.responseText)}catch(a){return l(1)}k(d)}},p=0,u=0,f=a.timeout||1E4,S=setTimeout(function(){l(1)},f),F=a.b||s(),i=a.data||{},k=a.c||s(),j="undefined"===typeof a.g,l=function(a){p||(p=1,clearTimeout(S),b&&(b.onerror=b.onload=m,b.abort&&b.abort(),b=m),a&&F())};try{b=V()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest;b.onerror=b.onabort=function(){l(1)};b.onload=
-b.onloadend=e;j&&(b.timeout=f);i.pnsdk=ta;var h=ha(a.url,i);b.open("GET",h,j);b.send()}catch(r){l(0);U=0;a=ua(a);break a}a=l}return a}var g=ra("script"),e=a.a,t=B(),N=0,W=setTimeout(function(){c(1)},a.timeout||1E4),w=a.b||s(),f=a.data||{},O=a.c||s();window[e]=function(a){c(0,a)};a.g||(g[va]=va);g.onerror=function(){c(1)};f.pnsdk=ta;g.src=ha(a.url,f);T(g,"id",t);oa().appendChild(g);return c},wa=function(){return!("onLine"in navigator)?1:navigator.onLine},V=function(){if(!xa||!xa.get)return 0;var a=
+function ga(a){var c="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c=16*Math.random()|0;return("x"==a?c:c&3|8).toString(16)});a&&a(c);return c}function K(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])}function O(a,c){var b=[];K(a||[],function(a,e){b.push(c(a,e))});return b}
+function L(a){return O(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function la(a){var c=[];K(a,function(a,d){d.j&&c.push(a)});return c.sort()}function P(){setTimeout(function(){v||(v=1,K(ba,function(a){a()}))},y)}
+if(!window.PUBNUB){var Q=function(a){return document.getElementById(a)},ma=function(a){console.error(a)},na=function(a,c){var b=[];K(a.split(/\s+/),function(a){K((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b},S=function(a,c,b){K(a.split(","),function(a){function e(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=q,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,e,q):c.attachEvent?c.attachEvent("on"+
+a,e):c["on"+a]=e})},oa=function(){return na("head")[0]},T=function(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)},qa=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){}},ra=function(a){return document.createElement(a)},sa=function(){return U||V()?0:B()},ua=function(a){function c(a,b){M||(M=1,a||N(b),g.onerror=m,clearTimeout(W),setTimeout(function(){a&&w();var b=
+Q(t),c=b&&b.parentNode;c&&c.removeChild(b)},y))}if(U||V()){a:{var b,d,e=function(){if(!u){u=1;clearTimeout(R);try{d=JSON.parse(b.responseText)}catch(a){return l(1)}k(d)}},p=0,u=0,f=a.timeout||1E4,R=setTimeout(function(){l(1)},f),F=a.b||s(),i=a.data||{},k=a.c||s(),j="undefined"===typeof a.g,l=function(a){p||(p=1,clearTimeout(R),b&&(b.onerror=b.onload=m,b.abort&&b.abort(),b=m),a&&F())};try{b=V()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest;b.onerror=b.onabort=function(){l(1)};b.onload=
+b.onloadend=e;j&&(b.timeout=f);i.pnsdk=ta;var h=ha(a.url,i);b.open("GET",h,j);b.send()}catch(r){l(0);U=0;a=ua(a);break a}a=l}return a}var g=ra("script"),e=a.a,t=B(),M=0,W=setTimeout(function(){c(1)},a.timeout||1E4),w=a.b||s(),f=a.data||{},N=a.c||s();window[e]=function(a){c(0,a)};a.g||(g[va]=va);g.onerror=function(){c(1)};f.pnsdk=ta;g.src=ha(a.url,f);T(g,"id",t);oa().appendChild(g);return c},wa=function(){return!("onLine"in navigator)?1:navigator.onLine},V=function(){if(!xa||!xa.get)return 0;var a=
{id:V.id++,send:s(),abort:function(){a.id={}},open:function(c,b){V[a.id]=a;xa.get(a.id,b)}};return a},va="async",ta="PubNub-JS-Web/3.4.7",U=-1==navigator.userAgent.indexOf("MSIE 6");window.console||(window.console=window.console||{});console.log||(console.log=console.error=(window.opera||{}).postError||s());var ya,X=window.localStorage;ya={get:function(a){try{return X?X.getItem(a):-1==document.cookie.indexOf(a)?m:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||m}catch(c){}},set:function(a,
-c){try{if(X)return X.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};var Y={list:{},unbind:function(a){Y.list[a]=[]},bind:function(a,c){(Y.list[a]=Y.list[a]||[]).push(c)},fire:function(a,c){K(Y.list[a]||[],function(a){a(c)})}},Z=Q("pubnub")||0,za=function(a){function c(){}function b(){x.time(function(a){if(!a)for(;w.length;)w.shift()();setTimeout(b,i)})}function d(){if(!ca())for(;w.length;)w.shift()();setTimeout(d,y)}function e(a){K(la(z),function(b){(b=
-z[b])&&a(b)})}function p(a){a&&(t.h=0);!t.h&&t.length&&(t.h=1,A(t.shift()))}a.jsonp&&(U=0);var u=a.subscribe_key||"";a.uuid||ya.get(u+"uuid");a.xdr=ua;a.db=ya;a.error=ma;a._is_online=wa;a.jsonp_cb=sa;var f,S=+a.windowing||10,F=(+a.timeout||310)*y,i=(+a.keepalive||3600)*y,k=a.publish_key||"",j=a.subscribe_key||"",l=a.ssl?"s":"",h="http"+l+"://"+(a.origin||"pubsub.pubnub.com"),r=E(h),g=E(h),t=[],N=0,W=0,w=[],O=0,H=0,z={},A=a.xdr,n=a.error||s(),ca=a._is_online||function(){return 1},D=a.jsonp_cb||function(){return 0},
+c){try{if(X)return X.setItem(a,c)&&0;document.cookie=a+"="+c+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(b){}}};var Y={list:{},unbind:function(a){Y.list[a]=[]},bind:function(a,c){(Y.list[a]=Y.list[a]||[]).push(c)},fire:function(a,c){K(Y.list[a]||[],function(a){a(c)})}},Z=Q("pubnub")||0,za=function(a){function c(){}function b(){x.time(function(a){a||w&&w();setTimeout(b,i)})}function d(){ca()||w&&w();setTimeout(d,y)}function e(a){var b=0;K(la(z),function(c){if(c=z[c])b++,(a||s())(c)});return b}
+function p(a){a&&(t.h=0);!t.h&&t.length&&(t.h=1,A(t.shift()))}a.jsonp&&(U=0);var u=a.subscribe_key||"";a.uuid||ya.get(u+"uuid");a.xdr=ua;a.db=ya;a.error=ma;a._is_online=wa;a.jsonp_cb=sa;var f,R=+a.windowing||10,F=(+a.timeout||310)*y,i=(+a.keepalive||3600)*y,k=a.publish_key||"",j=a.subscribe_key||"",l=a.ssl?"s":"",h="http"+l+"://"+(a.origin||"pubsub.pubnub.com"),r=E(h),g=E(h),t=[],M=0,W=0,w=0,N=0,H=0,z={},A=a.xdr,n=a.error||s(),ca=a._is_online||function(){return 1},D=a.jsonp_cb||function(){return 0},
I=a.db||{get:s(),set:s()},J=a.uuid||I&&I.get(j+"uuid")||"",x={LEAVE:function(a,b){var c={uuid:J},d=E(h),e=D();0<a.indexOf("-pnpres")||("0"!=e&&(c.callback=e),A({g:b||l,timeout:2E3,a:e,data:c,url:[d,"v2","presence","sub_key",j,"channel",L(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",e=a.error||s(),f=a.channel,g=a.start,k=a.end,h={},i=D();if(!f)return n("Missing Channel");if(!b)return n("Missing Callback");if(!j)return n("Missing Subscribe Key");
h.stringtoken="true";h.count=c;h.reverse=d;i&&(h.callback=i);g&&(h.start=g);k&&(h.end=k);A({a:i,data:h,c:function(a){b(a)},b:e,url:[r,"v2","history","sub-key",j,"channel",L(f)]})},replay:function(a){var b=b||a.callback||s(),c=a.source,d=a.destination,e=a.stop,f=a.start,g=a.end,h=a.reverse,a=a.limit,i=D(),l={};if(!c)return n("Missing Source Channel");if(!d)return n("Missing Destination Channel");if(!k)return n("Missing Publish Key");if(!j)return n("Missing Subscribe Key");"0"!=i&&(l.callback=i);e&&
(l.stop="all");h&&(l.reverse="true");f&&(l.start=f);g&&(l.end=g);a&&(l.count=a);A({a:i,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[r,"v1","replay",k,j,c,d],data:l})},time:function(a){var b=D();A({a:b,timeout:5*y,url:[r,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||s(),c=a.message,d=a.channel,e=D();if(!c)return n("Missing Message");if(!d)return n("Missing Channel");if(!k)return n("Missing Publish Key");if(!j)return n("Missing Subscribe Key");
-c=JSON.stringify(c);d=[r,"publish",k,j,0,L(d),e,L(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:J},c:function(a){b(a);p(1)},b:function(){b([0,"Failed",c]);p(1)}});p()},unsubscribe:function(a){a=a.channel;H=0;O=1;a=M((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){v&&x.LEAVE(a,0);z[a]=0});v&&c()},subscribe:function(a,b){function d(a){a?setTimeout(c,y):(r=E(h,1),g=E(h,1),setTimeout(function(){x.time(d)},y));e(function(b){if(a&&b.d)return b.d=
-0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var f=a.channel,b=(b=b||a.callback)||a.message,i=a.connect||s(),k=a.reconnect||s(),l=a.disconnect||s(),p=a.presence||0,t=a.noheresync||0,u=a.backfill||0,ca=a.timeout||F,pa=a.windowing||S;O=a.restore;H=0;if(!f)return n("Missing Channel");if(!b)return n("Missing Callback");if(!j)return n("Missing Subscribe Key");K((f.join?f.join(","):""+f).split(","),function(a){var c=z[a]||{};z[W=a]={name:a,f:c.f,d:c.d,j:1,a:N=b,k:i,l:l,m:k};p&&(x.subscribe({channel:a+
-"-pnpres",callback:p}),!c.j&&!t&&x.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){p({action:"join",uuid:c,timestamp:C(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){for(;w.length;)w.shift()();var a=D(),b=la(z).join(",");b&&w.push(A({timeout:ca,a:a,b:function(){x.time(d)},data:{uuid:J},url:[g,"subscribe",j,L(b),a,H],c:function(a){if(!a)return setTimeout(c,pa);H=!H&&O&&I.get(j)||a[1];e(function(a){a.f||(a.f=1,a.k(a.name))});u&&(H=1E4,u=0);I.set(j,a[1]);var b,d=
-(2<a.length?a[2]:M(z,function(b){return M(Array(a[0].length).join(",").split(","),function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||W;return[(z[a]||{}).a||N,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,pa)}}))};if(!v)return ba.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||s(),d=a.channel,e=D(),f=m;if(!d)return n("Missing Channel");if(!b)return n("Missing Callback");if(!j)return n("Missing Subscribe Key");"0"!=e&&
-(f={},f.callback=e);A({a:e,data:f,c:function(a){b(a)},b:c,url:[r,"v2","presence","sub_key",j,"channel",L(d)]})},xdr:A,ready:P,db:I,uuid:ga,map:M,each:K,"each-channel":e,grep:ja,supplant:ka,now:C,unique:B,updater:ia};J||(J=x.uuid());I.set(j+"uuid",J);setTimeout(d,y);setTimeout(b,i);x.time(s());f=x;f.css=qa;f.$=Q;f.create=ra;f.bind=R;f.head=oa;f.search=na;f.attr=T;f.events=Y;f.init=za;R("beforeunload",window,function(){f["each-channel"](function(a){f.LEAVE(a.name,1)});return!0});if(a.notest)return f;
-R("offline",window,f._reset_offline);R("offline",document,f._reset_offline);return f};R("load",window,function(){setTimeout(P,0)});var $=Z||{};PUBNUB=za({notest:1,publish_key:T($,"pub-key"),subscribe_key:T($,"sub-key"),ssl:!document.location.href.indexOf("https")||"on"==T($,"ssl"),origin:T($,"origin"),uuid:T($,"uuid")});window.jQuery&&(window.jQuery.PUBNUB=PUBNUB);"undefined"!==typeof module&&(module.exports=PUBNUB)&&P();var xa=Q("pubnubs")||0;if(Z){qa(Z,{position:"absolute",top:-y});if("opera"in
-window||T(Z,"flash"))Z.innerHTML="<object id=pubnubs data=https://pubnub.a.ssl.fastly.net/pubnub.swf><param name=movie value=https://pubnub.a.ssl.fastly.net/pubnub.swf><param name=allowscriptaccess value=always></object>";PUBNUB.rdx=function(a,c){if(!c)return V[a].onerror();V[a].responseText=unescape(c);V[a].onload()};V.id=y}}
+c=JSON.stringify(c);d=[r,"publish",k,j,0,L(d),e,L(c)];t.push({a:e,timeout:5*y,url:d,data:{uuid:J},c:function(a){b(a);p(1)},b:function(){b([0,"Failed",c]);p(1)}});p()},unsubscribe:function(a){a=a.channel;H=0;N=1;a=O((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+"-pnpres"}).join(",");K(a.split(","),function(a){v&&x.LEAVE(a,0);z[a]=0})},subscribe:function(a,b){function d(a){a?setTimeout(c,y):(r=E(h,1),g=E(h,1),setTimeout(function(){x.time(d)},y));e(function(b){if(a&&b.d)return b.d=
+0,b.m(b.name);!a&&!b.d&&(b.d=1,b.l(b.name))})}var f=a.channel,b=(b=b||a.callback)||a.message,i=a.connect||s(),k=a.reconnect||s(),l=a.disconnect||s(),p=a.presence||0,t=a.noheresync||0,u=a.backfill||0,ca=a.timeout||F,pa=a.windowing||R;N=a.restore;H=0;if(!f)return n("Missing Channel");if(!b)return n("Missing Callback");if(!j)return n("Missing Subscribe Key");K((f.join?f.join(","):""+f).split(","),function(a){var c=z[a]||{};z[W=a]={name:a,f:c.f,d:c.d,j:1,a:M=b,k:i,l:l,m:k};p&&(x.subscribe({channel:a+
+"-pnpres",callback:p}),!c.j&&!t&&x.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){p({action:"join",uuid:c,timestamp:C(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){var a=D(),b=la(z).join(",");b&&(w&&w(),w=A({timeout:ca,a:a,b:function(){x.time(d)},data:{uuid:J},url:[g,"subscribe",j,L(b),a,H],c:function(a){if(!a)return setTimeout(c,pa);H=!H&&N&&I.get(j)||a[1];e(function(a){a.f||(a.f=1,a.k(a.name))});u&&(H=1E4,u=0);I.set(j,a[1]);var b,d=(2<a.length?a[2]:O(z,function(b){return O(Array(a[0].length).join(",").split(","),
+function(){return b})}).join(",")).split(",");b=function(){var a=d.shift()||W;return[(z[a]||{}).a||M,a.split("-pnpres")[0]]};K(a[0],function(c){var d=b();d[0](c,a,d[1])});setTimeout(c,pa)}}))};if(!v)return ba.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||s(),d=a.channel,e=D(),f=m;if(!d)return n("Missing Channel");if(!b)return n("Missing Callback");if(!j)return n("Missing Subscribe Key");"0"!=e&&(f={},f.callback=e);A({a:e,data:f,c:function(a){b(a)},b:c,url:[r,"v2","presence","sub_key",
+j,"channel",L(d)]})},xdr:A,ready:P,db:I,uuid:ga,map:O,each:K,"each-channel":e,grep:ja,supplant:ka,now:C,unique:B,updater:ia};J||(J=x.uuid());I.set(j+"uuid",J);setTimeout(d,y);setTimeout(b,i);x.time(s());f=x;f.css=qa;f.$=Q;f.create=ra;f.bind=S;f.head=oa;f.search=na;f.attr=T;f.events=Y;f.init=za;S("beforeunload",window,function(){f["each-channel"](function(a){f.LEAVE(a.name,1)});return!0});if(a.notest)return f;S("offline",window,f._reset_offline);S("offline",document,f._reset_offline);return f};S("load",
+window,function(){setTimeout(P,0)});var $=Z||{};PUBNUB=za({notest:1,publish_key:T($,"pub-key"),subscribe_key:T($,"sub-key"),ssl:!document.location.href.indexOf("https")||"on"==T($,"ssl"),origin:T($,"origin"),uuid:T($,"uuid")});window.jQuery&&(window.jQuery.PUBNUB=PUBNUB);"undefined"!==typeof module&&(module.exports=PUBNUB)&&P();var xa=Q("pubnubs")||0;if(Z){qa(Z,{position:"absolute",top:-y});if("opera"in window||T(Z,"flash"))Z.innerHTML="<object id=pubnubs data=https://pubnub.a.ssl.fastly.net/pubnub.swf><param name=movie value=https://pubnub.a.ssl.fastly.net/pubnub.swf><param name=allowscriptaccess value=always></object>";
+PUBNUB.rdx=function(a,c){if(!c)return V[a].onerror();V[a].responseText=unescape(c);V[a].onload()};V.id=y}}
var Aa=PUBNUB.ws=function(a,c){if(!(this instanceof Aa))return new Aa(a,c);var b=this,a=b.url=a||"";b.protocol=c||"Sec-WebSocket-Protocol";var d=a.split("/"),d={ssl:"wss:"===d[0],origin:d[2],publish_key:d[3],subscribe_key:d[4],channel:d[5]};b.CONNECTING=0;b.OPEN=1;b.CLOSING=2;b.CLOSED=3;b.CLOSE_NORMAL=1E3;b.CLOSE_GOING_AWAY=1001;b.CLOSE_PROTOCOL_ERROR=1002;b.CLOSE_UNSUPPORTED=1003;b.CLOSE_TOO_LARGE=1004;b.CLOSE_NO_STATUS=1005;b.CLOSE_ABNORMAL=1006;b.onclose=b.onerror=b.onmessage=b.onopen=b.onsend=
s();b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=q;b.buffer=[];b.readyState=b.CONNECTING;if(!a)return b.readyState=b.CLOSED,b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),b;b.e=PUBNUB.init(d);b.e.i=d;b.i=d;b.e.subscribe({restore:q,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:q})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
Aa.prototype.send=function(a){var c=this;c.e.publish({channel:c.e.i.channel,message:a,callback:function(a){c.onsend({data:a})}})};
})();
-PUBNUB['crypto'] = (function(){
- var Nr = 14,
- /* Default to 256 Bit Encryption */
- Nk = 8,
- Decrypt = false,
-
- enc_utf8 = function(s)
- {
- try {
- return unescape(encodeURIComponent(s));
- }
- catch(e) {
- throw 'Error on UTF-8 encode';
- }
- },
-
- dec_utf8 = function(s)
- {
- try {
- return decodeURIComponent(escape(s));
- }
- catch(e) {
- throw ('Bad Key');
- }
- },
-
- padBlock = function(byteArr)
- {
- var array = [], cpad, i;
- if (byteArr.length < 16) {
- cpad = 16 - byteArr.length;
- array = [cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad, cpad];
- }
- for (i = 0; i < byteArr.length; i++)
- {
- array[i] = byteArr[i];
- }
- return array;
- },
-
- block2s = function(block, lastBlock)
- {
- var string = '', padding, i;
- if (lastBlock) {
- padding = block[15];
- if (padding > 16) {
- throw ('Decryption error: Maybe bad key');
- }
- if (padding == 16) {
- return '';
- }
- for (i = 0; i < 16 - padding; i++) {
- string += String.fromCharCode(block[i]);
- }
- } else {
- for (i = 0; i < 16; i++) {
- string += String.fromCharCode(block[i]);
- }
- }
- return string;
- },
-
- a2h = function(numArr)
- {
- var string = '', i;
- for (i = 0; i < numArr.length; i++) {
- string += (numArr[i] < 16 ? '0': '') + numArr[i].toString(16);
- }
- return string;
- },
-
- h2a = function(s)
- {
- var ret = [];
- s.replace(/(..)/g,
- function(s) {
- ret.push(parseInt(s, 16));
- });
- return ret;
- },
-
- s2a = function(string, binary) {
- var array = [], i;
-
- if (! binary) {
- string = enc_utf8(string);
- }
-
- for (i = 0; i < string.length; i++)
- {
- array[i] = string.charCodeAt(i);
- }
-
- return array;
- },
-
- size = function(newsize)
- {
- switch (newsize)
- {
- case 128:
- Nr = 10;
- Nk = 4;
- break;
- case 192:
- Nr = 12;
- Nk = 6;
- break;
- case 256:
- Nr = 14;
- Nk = 8;
- break;
- default:
- throw ('Invalid Key Size Specified:' + newsize);
- }
- },
-
- randArr = function(num) {
- var result = [], i;
- for (i = 0; i < num; i++) {
- result = result.concat(Math.floor(Math.random() * 256));
- }
- return result;
- },
-
- openSSLKey = function(passwordArr, saltArr) {
- // Number of rounds depends on the size of the AES in use
- // 3 rounds for 256
- // 2 rounds for the key, 1 for the IV
- // 2 rounds for 128
- // 1 round for the key, 1 round for the IV
- // 3 rounds for 192 since it's not evenly divided by 128 bits
- var rounds = Nr >= 12 ? 3: 2,
- key = [],
- iv = [],
- md5_hash = [],
- result = [],
- data00 = passwordArr.concat(saltArr),
- i;
- md5_hash[0] = GibberishAES.Hash.MD5(data00);
- result = md5_hash[0];
- for (i = 1; i < rounds; i++) {
- md5_hash[i] = GibberishAES.Hash.MD5(md5_hash[i - 1].concat(data00));
- result = result.concat(md5_hash[i]);
- }
- key = result.slice(0, 4 * Nk);
- iv = result.slice(4 * Nk, 4 * Nk + 16);
- return {
- key: key,
- iv: iv
- };
- },
-
- rawEncrypt = function(plaintext, key, iv) {
- // plaintext, key and iv as byte arrays
- key = expandKey(key);
- var numBlocks = Math.ceil(plaintext.length / 16),
- blocks = [],
- i,
- cipherBlocks = [];
- for (i = 0; i < numBlocks; i++) {
- blocks[i] = padBlock(plaintext.slice(i * 16, i * 16 + 16));
- }
- if (plaintext.length % 16 === 0) {
- blocks.push([16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]);
- // CBC OpenSSL padding scheme
- numBlocks++;
- }
- for (i = 0; i < blocks.length; i++) {
- blocks[i] = (i === 0) ? xorBlocks(blocks[i], iv) : xorBlocks(blocks[i], cipherBlocks[i - 1]);
- cipherBlocks[i] = encryptBlock(blocks[i], key);
- }
- return cipherBlocks;
- },
-
- rawDecrypt = function(cryptArr, key, iv, binary) {
- // cryptArr, key and iv as byte arrays
- key = expandKey(key);
- var numBlocks = cryptArr.length / 16,
- cipherBlocks = [],
- i,
- plainBlocks = [],
- string = '';
- for (i = 0; i < numBlocks; i++) {
- cipherBlocks.push(cryptArr.slice(i * 16, (i + 1) * 16));
- }
- for (i = cipherBlocks.length - 1; i >= 0; i--) {
- plainBlocks[i] = decryptBlock(cipherBlocks[i], key);
- plainBlocks[i] = (i === 0) ? xorBlocks(plainBlocks[i], iv) : xorBlocks(plainBlocks[i], cipherBlocks[i - 1]);
- }
- for (i = 0; i < numBlocks - 1; i++) {
- string += block2s(plainBlocks[i]);
- }
- string += block2s(plainBlocks[i], true);
- return binary ? string : dec_utf8(string);
- },
-
- encryptBlock = function(block, words) {
- Decrypt = false;
- var state = addRoundKey(block, words, 0),
- round;
- for (round = 1; round < (Nr + 1); round++) {
- state = subBytes(state);
- state = shiftRows(state);
- if (round < Nr) {
- state = mixColumns(state);
- }
- //last round? don't mixColumns
- state = addRoundKey(state, words, round);
- }
-
- return state;
- },
-
- decryptBlock = function(block, words) {
- Decrypt = true;
- var state = addRoundKey(block, words, Nr),
- round;
- for (round = Nr - 1; round > -1; round--) {
- state = shiftRows(state);
- state = subBytes(state);
- state = addRoundKey(state, words, round);
- if (round > 0) {
- state = mixColumns(state);
- }
- //last round? don't mixColumns
- }
-
- return state;
- },
-
- subBytes = function(state) {
- var S = Decrypt ? SBoxInv: SBox,
- temp = [],
- i;
- for (i = 0; i < 16; i++) {
- temp[i] = S[state[i]];
- }
- return temp;
- },
-
- shiftRows = function(state) {
- var temp = [],
- shiftBy = Decrypt ? [0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3] : [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11],
- i;
- for (i = 0; i < 16; i++) {
- temp[i] = state[shiftBy[i]];
- }
- return temp;
- },
-
- mixColumns = function(state) {
- var t = [],
- c;
- if (!Decrypt) {
- for (c = 0; c < 4; c++) {
- t[c * 4] = G2X[state[c * 4]] ^ G3X[state[1 + c * 4]] ^ state[2 + c * 4] ^ state[3 + c * 4];
- t[1 + c * 4] = state[c * 4] ^ G2X[state[1 + c * 4]] ^ G3X[state[2 + c * 4]] ^ state[3 + c * 4];
- t[2 + c * 4] = state[c * 4] ^ state[1 + c * 4] ^ G2X[state[2 + c * 4]] ^ G3X[state[3 + c * 4]];
- t[3 + c * 4] = G3X[state[c * 4]] ^ state[1 + c * 4] ^ state[2 + c * 4] ^ G2X[state[3 + c * 4]];
- }
- }else {
- for (c = 0; c < 4; c++) {
- t[c*4] = GEX[state[c*4]] ^ GBX[state[1+c*4]] ^ GDX[state[2+c*4]] ^ G9X[state[3+c*4]];
- t[1+c*4] = G9X[state[c*4]] ^ GEX[state[1+c*4]] ^ GBX[state[2+c*4]] ^ GDX[state[3+c*4]];
- t[2+c*4] = GDX[state[c*4]] ^ G9X[state[1+c*4]] ^ GEX[state[2+c*4]] ^ GBX[state[3+c*4]];
- t[3+c*4] = GBX[state[c*4]] ^ GDX[state[1+c*4]] ^ G9X[state[2+c*4]] ^ GEX[state[3+c*4]];
- }
- }
-
- return t;
- },
-
- addRoundKey = function(state, words, round) {
- var temp = [],
- i;
- for (i = 0; i < 16; i++) {
- temp[i] = state[i] ^ words[round][i];
- }
- return temp;
- },
-
- xorBlocks = function(block1, block2) {
- var temp = [],
- i;
- for (i = 0; i < 16; i++) {
- temp[i] = block1[i] ^ block2[i];
- }
- return temp;
- },
-
- expandKey = function(key) {
- // Expects a 1d number array
- var w = [],
- temp = [],
- i,
- r,
- t,
- flat = [],
- j;
-
- for (i = 0; i < Nk; i++) {
- r = [key[4 * i], key[4 * i + 1], key[4 * i + 2], key[4 * i + 3]];
- w[i] = r;
- }
-
- for (i = Nk; i < (4 * (Nr + 1)); i++) {
- w[i] = [];
- for (t = 0; t < 4; t++) {
- temp[t] = w[i - 1][t];
- }
- if (i % Nk === 0) {
- temp = subWord(rotWord(temp));
- temp[0] ^= Rcon[i / Nk - 1];
- } else if (Nk > 6 && i % Nk == 4) {
- temp = subWord(temp);
- }
- for (t = 0; t < 4; t++) {
- w[i][t] = w[i - Nk][t] ^ temp[t];
- }
- }
- for (i = 0; i < (Nr + 1); i++) {
- flat[i] = [];
- for (j = 0; j < 4; j++) {
- flat[i].push(w[i * 4 + j][0], w[i * 4 + j][1], w[i * 4 + j][2], w[i * 4 + j][3]);
- }
- }
- return flat;
- },
-
- subWord = function(w) {
- // apply SBox to 4-byte word w
- for (var i = 0; i < 4; i++) {
- w[i] = SBox[w[i]];
- }
- return w;
- },
-
- rotWord = function(w) {
- // rotate 4-byte word w left by one byte
- var tmp = w[0],
- i;
- for (i = 0; i < 4; i++) {
- w[i] = w[i + 1];
- }
- w[3] = tmp;
- return w;
- },
-
-// jlcooke: 2012-07-12: added strhex + invertArr to compress G2X/G3X/G9X/GBX/GEX/SBox/SBoxInv/Rcon saving over 7KB, and added encString, decString
- strhex = function(str,size) {
- var ret = [];
- for (i=0; i<str.length; i+=size)
- ret[i/size] = parseInt(str.substr(i,size), 16);
- return ret;
- },
- invertArr = function(arr) {
- var ret = [];
- for (i=0; i<arr.length; i++)
- ret[arr[i]] = i;
- return ret;
- },
- Gxx = function(a, b) {
- var i, ret;
-
- ret = 0;
- for (i=0; i<8; i++) {
- ret = ((b&1)==1) ? ret^a : ret;
- /* xmult */
- a = (a>0x7f) ? 0x11b^(a<<1) : (a<<1);
- b >>>= 1;
- }
-
- return ret;
- },
- Gx = function(x) {
- var r = [];
- for (var i=0; i<256; i++)
- r[i] = Gxx(x, i);
- return r;
- },
-
- // S-box
-/*
- SBox = [
- 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171,
- 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164,
- 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113,
- 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226,
- 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214,
- 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203,
- 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69,
- 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245,
- 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68,
- 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42,
- 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73,
- 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109,
- 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37,
- 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62,
- 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225,
- 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223,
- 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187,
- 22], //*/ SBox = strhex('637c777bf26b6fc53001672bfed7ab76ca82c97dfa5947f0add4a2af9ca472c0b7fd9326363ff7cc34a5e5f171d8311504c723c31896059a071280e2eb27b27509832c1a1b6e5aa0523bd6b329e32f8453d100ed20fcb15b6acbbe394a4c58cfd0efaafb434d338545f9027f503c9fa851a3408f929d38f5bcb6da2110fff3d2cd0c13ec5f974417c4a77e3d645d197360814fdc222a908846eeb814de5e0bdbe0323a0a4906245cc2d3ac629195e479e7c8376d8dd54ea96c56f4ea657aae08ba78252e1ca6b4c6e8dd741f4bbd8b8a703eb5664803f60e613557b986c11d9ee1f8981169d98e949b1e87e9ce5528df8ca1890dbfe6426841992d0fb054bb16',2),
-
- // Precomputed lookup table for the inverse SBox
-/* SBoxInv = [
- 82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215,
- 251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222,
- 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66,
- 250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73,
- 109, 139, 209, 37, 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92,
- 204, 93, 101, 182, 146, 108, 112, 72, 80, 253, 237, 185, 218, 94, 21,
- 70, 87, 167, 141, 157, 132, 144, 216, 171, 0, 140, 188, 211, 10, 247,
- 228, 88, 5, 184, 179, 69, 6, 208, 44, 30, 143, 202, 63, 15, 2,
- 193, 175, 189, 3, 1, 19, 138, 107, 58, 145, 17, 65, 79, 103, 220,
- 234, 151, 242, 207, 206, 240, 180, 230, 115, 150, 172, 116, 34, 231, 173,
- 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, 71, 241, 26, 113, 29,
- 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, 252, 86, 62, 75,
- 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, 31, 221, 168,
- 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81,
- 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160,
- 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97,
- 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12,
- 125], //*/ SBoxInv = invertArr(SBox),
-
- // Rijndael Rcon
-/*
- Rcon = [1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154, 47, 94,
- 188, 99, 198, 151, 53, 106, 212, 179, 125, 250, 239, 197, 145],
-//*/ Rcon = strhex('01020408102040801b366cd8ab4d9a2f5ebc63c697356ad4b37dfaefc591',2),
-
-/*
- G2X = [
- 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16,
- 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e,
- 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x40, 0x42, 0x44, 0x46,
- 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
- 0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76,
- 0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e,
- 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa4, 0xa6,
- 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
- 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6,
- 0xd8, 0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee,
- 0xf0,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 0xf3, 0xfd, 0xa7, 0xa9, 0xbb, 0xb5,
- 0x9f, 0x91, 0x83, 0x8d
- ], //*/ GEX = Gx(0xe),
-
- enc = function(string, pass, binary) {
- // string, password in plaintext
- var salt = randArr(8),
- pbe = openSSLKey(s2a(pass, binary), salt),
- key = pbe.key,
- iv = pbe.iv,
- cipherBlocks,
- saltBlock = [[83, 97, 108, 116, 101, 100, 95, 95].concat(salt)];
- string = s2a(string, binary);
- cipherBlocks = rawEncrypt(string, key, iv);
- // Spells out 'Salted__'
- cipherBlocks = saltBlock.concat(cipherBlocks);
- return Base64.encode(cipherBlocks);
- },
-
- dec = function(string, pass, binary) {
- // string, password in plaintext
- var cryptArr = Base64.decode(string),
- salt = cryptArr.slice(8, 16),
- pbe = openSSLKey(s2a(pass, binary), salt),
- key = pbe.key,
- iv = pbe.iv;
- cryptArr = cryptArr.slice(16, cryptArr.length);
- // Take off the Salted__ffeeddcc
- string = rawDecrypt(cryptArr, key, iv, binary);
- return string;
- },
-
- MD5 = function(numArr) {
-
- function rotateLeft(lValue, iShiftBits) {
- return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
- }
-
- function addUnsigned(lX, lY) {
- var lX4,
- lY4,
- lX8,
- lY8,
- lResult;
- lX8 = (lX & 0x80000000);
- lY8 = (lY & 0x80000000);
- lX4 = (lX & 0x40000000);
- lY4 = (lY & 0x40000000);
- lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
- if (lX4 & lY4) {
- return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
- }
- if (lX4 | lY4) {
- if (lResult & 0x40000000) {
- return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
- } else {
- return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
- }
- } else {
- return (lResult ^ lX8 ^ lY8);
- }
- }
-
- function f(x, y, z) {
- return (x & y) | ((~x) & z);
- }
- function g(x, y, z) {
- return (x & z) | (y & (~z));
- }
- function h(x, y, z) {
- return (x ^ y ^ z);
- }
- function funcI(x, y, z) {
- return (y ^ (x | (~z)));
- }
-
- function ff(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(f(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
-
- function gg(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(g(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
-
- function hh(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(h(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
-
- function ii(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(funcI(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
-
- function convertToWordArray(numArr) {
- var lWordCount,
- lMessageLength = numArr.length,
- lNumberOfWords_temp1 = lMessageLength + 8,
- lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64,
- lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16,
- lWordArray = [],
- lBytePosition = 0,
- lByteCount = 0;
- while (lByteCount < lMessageLength) {
- lWordCount = (lByteCount - (lByteCount % 4)) / 4;
- lBytePosition = (lByteCount % 4) * 8;
- lWordArray[lWordCount] = (lWordArray[lWordCount] | (numArr[lByteCount] << lBytePosition));
- lByteCount++;
- }
- lWordCount = (lByteCount - (lByteCount % 4)) / 4;
- lBytePosition = (lByteCount % 4) * 8;
- lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
- lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
- lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
- return lWordArray;
- }
-
- function wordToHex(lValue) {
- var lByte,
- lCount,
- wordToHexArr = [];
- for (lCount = 0; lCount <= 3; lCount++) {
- lByte = (lValue >>> (lCount * 8)) & 255;
- wordToHexArr = wordToHexArr.concat(lByte);
- }
- return wordToHexArr;
- }
-
- /*function utf8Encode(string) {
- string = string.replace(/\r\n/g, "\n");
- var utftext = "",
- n,
- c;
-
- for (n = 0; n < string.length; n++) {
-
- c = string.charCodeAt(n);
-
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }