Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding pubnub sdk url parameter

  • Loading branch information...
commit 8bacc05a39d08f95c4736772119953f624ee5f98 1 parent 02841bf
@devendram devendram authored
Showing with 3,900 additions and 164 deletions.
  1. +1 −1  Makefile
  2. +0 −2  Makefile.inc
  3. +2 −0  Makefile.post
  4. +24 −1 core/pubnub-common.js
  5. +5 −0 modern/Makefile
  6. +28 −12 modern/pubnub.js
  7. +16 −16 modern/pubnub.min.js
  8. +4 −11 modern/unassembled/platform.js
  9. +9 −10 nodejs/Makefile
  10. +27 −2 nodejs/pubnub.js
  11. +3 −1 nodejs/unassembled/platform.js
  12. +34 −0 phonegap/Makefile
  13. +1 −1  phonegap/index.html
  14. +25 −0 phonegap/pubnub-crypto.min.js
  15. +1,099 −0 phonegap/pubnub.js
  16. +23 −0 phonegap/pubnub.min.js
  17. +34 −0 sencha/Makefile
  18. +1 −1  sencha/examples/here_now/index.html
  19. +1 −1  sencha/examples/history/index.html
  20. +1 −1  sencha/examples/subscribe/index.html
  21. +25 −0 sencha/pubnub-crypto.min.js
  22. +1,099 −0 sencha/pubnub.js
  23. +23 −0 sencha/pubnub.min.js
  24. +2 −0  socket.io/Makefile
  25. +27 −27 socket.io/socket.io.min.js
  26. +2 −0  titanium/Makefile
  27. +26 −2 titanium/examples/desktop/pubnub.js
  28. +26 −2 titanium/examples/mobile/chat-example-app/Resources/pubnub.js
  29. +26 −2 titanium/examples/mobile/detailed-history-example-app/Resources/pubnub.js
  30. +26 −2 titanium/examples/mobile/here-now-example-app/Resources/pubnub.js
  31. +26 −2 titanium/pubnub.js
  32. +5 −0 web/Makefile
  33. +32 −20 web/pubnub.js
  34. +27 −27 web/pubnub.min.js
  35. +8 −19 web/unassembled/platform.js
  36. +34 −0 webos/Makefile
  37. +1 −1  webos/index.html
  38. +25 −0 webos/pubnub-crypto.min.js
  39. +1,099 −0 webos/pubnub.js
  40. +23 −0 webos/pubnub.min.js
View
2  Makefile
@@ -1,4 +1,4 @@
-SUBDIRS = web socket.io nodejs modern titanium
+SUBDIRS = web socket.io nodejs modern titanium phonegap sencha webos
.PHONY: all
all:
View
2  Makefile.inc
@@ -17,5 +17,3 @@ WEBSOCKET_JS=$(CORE_DIR)/websocket.js
ENCRYPT_JS=$(CORE_DIR)/crypto/encrypt-pubnub.js
PUBNUB_MIN_JS=pubnub.min.js
-.PHONY : test
-test : # empty
View
2  Makefile.post
@@ -0,0 +1,2 @@
+.PHONY: test
+test: #empty
View
25 core/pubnub-common.js
@@ -7,6 +7,8 @@ var NOW = 1
, DEF_SUB_TIMEOUT = 310 // SECONDS.
, DEF_KEEPALIVE = 60 // SECONDS.
, SECOND = 1000 // A THOUSAND MILLISECONDS.
+, URLBIT = '/'
+, PARAMSBIT = '&'
, REPL = /{([\w\-]+)}/g;
/**
@@ -33,6 +35,26 @@ var nextorigin = (function() {
}
})();
+
+/**
+ * Build Url
+ * =======
+ *
+ */
+function build_url(url_components, url_params) {
+ var url = url_components.join(URLBIT);
+
+ if (url_params) {
+ var params = [];
+ url += "?";
+ for (var key in url_params) {
+ params.push(key+"="+url_params[key]);
+ }
+ url += params.join(PARAMSBIT);
+ }
+ return url;
+}
+
/**
* UPDATER
* =======
@@ -206,7 +228,7 @@ function PN_API(setup) {
// Announce Leave Event
var SELF = {
'LEAVE' : function( channel, blocking ) {
- var data = { 'uuid' : UUID }
+ var data = { 'uuid' : UUID}
, origin = nextorigin(ORIGIN)
, jsonp = jsonp_cb();
@@ -215,6 +237,7 @@ function PN_API(setup) {
if (jsonp != '0') data['callback'] = jsonp;
+
xdr({
blocking : blocking || SSL,
timeout : 2000,
View
5 modern/Makefile
@@ -1,5 +1,6 @@
include ../Makefile.inc
OUTPUT_FILES=$(PUBNUB_MIN_JS) $(PUBNUB_CRYPTO_MIN_JS)
+PLATFORM=Modern
.PHONY : all
all: build
@@ -11,6 +12,8 @@ $(PUBNUB_MIN_JS) : $(PUBNUB_COMMON_JS) $(WEBSOCKET_JS) $(PUBNUB_PLATFORM_JS)
## Full Version
$(ECHO) "// Version: $(VERSION)" > $(PUBNUB_JS)
cat $(PUBNUB_COMMON_JS) $(PUBNUB_PLATFORM_JS) $(WEBSOCKET_JS) >> $(PUBNUB_JS)
+ sed -i -e "s/VERSION/\'$(VERSION)\'/g" $(PUBNUB_JS)
+ sed -i -e "s/PLATFORM/\'$(PLATFORM)\'/g" $(PUBNUB_JS)
## Minfied Version
$(ECHO) "// Version: $(VERSION)" > $(PUBNUB_MIN_JS)
$(ECHO) "(function(){" >> $(PUBNUB_MIN_JS)
@@ -26,3 +29,5 @@ $(PUBNUB_CRYPTO_MIN_JS) : $(GIBBERISH_JS) $(ENCRYPTO_JS)
.PHONY : clean
clean:
rm -f $(OUTPUT_FILES)
+
+include ../Makefile.post
View
40 modern/pubnub.js
@@ -8,6 +8,8 @@ var NOW = 1
, DEF_SUB_TIMEOUT = 310 // SECONDS.
, DEF_KEEPALIVE = 60 // SECONDS.
, SECOND = 1000 // A THOUSAND MILLISECONDS.
+, URLBIT = '/'
+, PARAMSBIT = '&'
, REPL = /{([\w\-]+)}/g;
/**
@@ -34,6 +36,26 @@ var nextorigin = (function() {
}
})();
+
+/**
+ * Build Url
+ * =======
+ *
+ */
+function build_url(url_components, url_params) {
+ var url = url_components.join(URLBIT);
+
+ if (url_params) {
+ var params = [];
+ url += "?";
+ for (var key in url_params) {
+ params.push(key+"="+url_params[key]);
+ }
+ url += params.join(PARAMSBIT);
+ }
+ return url;
+}
+
/**
* UPDATER
* =======
@@ -207,7 +229,7 @@ function PN_API(setup) {
// Announce Leave Event
var SELF = {
'LEAVE' : function( channel, blocking ) {
- var data = { 'uuid' : UUID }
+ var data = { 'uuid' : UUID}
, origin = nextorigin(ORIGIN)
, jsonp = jsonp_cb();
@@ -216,6 +238,7 @@ function PN_API(setup) {
if (jsonp != '0') data['callback'] = jsonp;
+
xdr({
blocking : blocking || SSL,
timeout : 2000,
@@ -701,8 +724,7 @@ THE SOFTWARE.
* UTIL LOCALS
*/
var NOW = 1
-, URLBIT = '/'
-, PARAMSBIT = '&'
+, PNSDK = encode('PubNub-JS-' + 'Modern' + '/' + '3.4.4')
, XHRTME = 310000;
@@ -758,6 +780,7 @@ function xdr( setup ) {
, complete = 0
, loaded = 0
, timer = timeout( function(){done(1)}, XHRTME )
+ , data = setup.data || {}
, fail = setup.fail || function(){}
, success = setup.success || function(){}
, done = function(failed) {
@@ -784,15 +807,8 @@ function xdr( setup ) {
xhr.onerror = xhr.onabort = function(){ done(1) };
xhr.onload = xhr.onloadend = finished;
xhr.timeout = XHRTME;
- url = setup.url.join(URLBIT);
- if (setup.data) {
- var params = [];
- url += "?";
- for (key in setup.data) {
- params.push(key+"="+setup.data[key]);
- }
- url += params.join(PARAMSBIT);
- }
+ data['pnsdk'] = PNSDK;
+ url = build_url(setup.url, data);
xhr.open( 'GET', url, true );
xhr.send();
}
View
32 modern/pubnub.min.js
@@ -1,21 +1,21 @@
// Version: 3.4.4
(function(){
-var k=!1;function l(){return function(){}}var da=1,q=k,y=[],z="-pnpres",A=1E3,ea=/{([\w\-]+)}/g;function fa(){return"x"+ ++da+""+ +new Date}function E(){return+new Date}var H,I=Math.floor(20*Math.random());H=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?J().split("-")[0]:20>++I?I:I=1))||a};function ga(a,c){function b(){f+c>E()?(clearTimeout(d),d=setTimeout(b,c)):(f=E(),a())}var d,f=0;return b}function ha(a,c){var b=[];K(a||[],function(a){c(a)&&b.push(a)});return b}
-function ia(a,c){return a.replace(ea,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 M(a,c){var b=[];K(a||[],function(a,f){b.push(c(a,f))});return b}
-function N(a){return M(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function O(a){var c=[];K(a,function(a,d){d.g&&c.push(a)});return c.sort()}function ja(){setTimeout(function(){q||(q=1,K(y,function(a){a()}))},A)}
-function S(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&P())}function b(){if(!r){r=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}Q(response)}}var d,f=0,r=0,e;e=setTimeout(function(){c(1)},T);var P=a.b||l(),Q=a.c||l();try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;d.timeout=T;url=a.url.join(ka);if(a.data){var v=[];url+=
-"?";for(key in a.data)v.push(key+"="+a.data[key]);url+=v.join(la)}d.open("GET",url,!0);d.send()}catch(s){return c(0),S(a)}return c}function U(a,c,b){K(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=k,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,k):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function ma(a){console.error(a)}
-function na(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)}function oa(a){return document.getElementById(a)}function pa(a,c){var b=[];K(a.split(/\s+/),function(a){K((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b}function qa(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 ra(a){return document.createElement(a)}
-function V(a){function c(){}function b(){j.time(function(a){a||w&&w(1);setTimeout(b,v)})}function d(){sa()||w&&w(1);setTimeout(d,A)}function f(a){K(O(n),function(b){(b=n[b])&&a(b)})}function r(a){a&&(t.h=0);!t.h&&t.length&&(t.h=1,u(t.shift()))}a.db=W;a.xdr=S;a.error=ma;var e,P=+a.windowing||10,Q=(+a.timeout||310)*A,v=(+a.keepalive||60)*A,s=a.publish_key||"",h=a.subscribe_key||"",L=a.ssl?"s":"",F="http"+L+"://"+(a.origin||"pubsub.pubnub.com"),B=H(F),Z=H(F),t=[],$=0,aa=0,w=0,R=0,ba=0,G=0,n={},u=a.xdr,
-g=a.error||l(),sa=a._is_online||function(){return 1},x=a.jsonp_cb||function(){return 0},C=a.db||{get:l(),set:l()},D=a.uuid||C&&C.get(h+"uuid")||"",j={LEAVE:function(a,b){var c={uuid:D},d=H(F),p=x();0<a.indexOf(z)||("0"!=p&&(c.callback=p),u({n:b||L,timeout:2E3,a:p,data:c,url:[d,"v2","presence","sub_key",h,"channel",N(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",p=a.error||l(),e=a.channel,f=a.start,j=a.end,i={},m=x();if(!e)return g("Missing Channel");
-if(!b)return g("Missing Callback");if(!h)return g("Missing Subscribe Key");i.stringtoken="true";i.count=c;i.reverse=d;m&&(i.callback=m);f&&(i.start=f);j&&(i.end=j);u({a:m,data:i,c:function(a){b(a)},b:p,url:[B,"v2","history","sub-key",h,"channel",N(e)]})},replay:function(a){var b=b||a.callback||l(),c=a.source,d=a.destination,e=a.stop,f=a.start,j=a.end,n=a.reverse,a=a.limit,i=x(),m={};if(!c)return g("Missing Source Channel");if(!d)return g("Missing Destination Channel");if(!s)return g("Missing Publish Key");
-if(!h)return g("Missing Subscribe Key");"0"!=i&&(m.callback=i);e&&(m.stop="all");n&&(m.reverse="true");f&&(m.start=f);j&&(m.end=j);a&&(m.count=a);u({a:i,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[B,"v1","replay",s,h,c,d],data:m})},time:function(a){var b=x();u({a:b,timeout:5*A,url:[B,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||l(),c=a.message,d=a.channel,e=x();if(!c)return g("Missing Message");if(!d)return g("Missing Channel");
-if(!s)return g("Missing Publish Key");if(!h)return g("Missing Subscribe Key");c=JSON.stringify(c);d=[B,"publish",s,h,0,N(d),e,N(c)];t.push({a:e,timeout:5*A,url:d,data:{uuid:D},c:function(a){b(a);r(1)},b:function(){b([0,"Failed",c]);r(1)}});r()},unsubscribe:function(a){a=a.channel;G=0;R=1;a=M((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+z}).join(",");K(a.split(","),function(a){q&&j.LEAVE(a,0);n[a]=0});q&&c()},subscribe:function(a,b){function d(a){a?setTimeout(e,A):(B=H(F,1),Z=H(F,
-1),setTimeout(function(){j.time(d)},A));f(function(b){if(a&&b.d)return b.d=0,b.l(b.name);!a&&!b.d&&(b.d=1,b.k(b.name))})}function e(){var a=x(),b=O(n).join(",");b&&(w=u({timeout:L,a:a,b:function(){j.time(d)},data:{uuid:D},url:[Z,"subscribe",h,N(b),a,G],c:function(a){if(!a)return setTimeout(e,ca);f(function(a){a.f||(a.f=1,a.j(a.name))});G=!G&&R&&C.get(h)||a[1];s&&(Timetoken=1E4,s=0);C.set(h,a[1]);var b,c=(2<a.length?a[2]:"").split(",");b=function(){var a=c.shift()||"";return[(n[a]||{}).a||$,(a||aa).split(z)[0]]};
-K(a[0],function(c){var d=b();if(n[d[1]].g)d[0](c,a,d[1])});setTimeout(e,ca)}}))}var p=a.channel,b=(b=b||a.callback)||a.message,r=a.connect||l(),t=a.reconnect||l(),v=a.disconnect||l(),i=a.presence||0,m=a.noheresync||0,s=a.backfill||0,L=a.timeout||Q,ca=a.windowing||P;a.restore&&(R=1);G=0;if(!p)return g("Missing Channel");if(!b)return g("Missing Callback");if(!h)return g("Missing Subscribe Key");K((p.join?p.join(","):""+p).split(","),function(a){var c=n[a]||{};n[aa=a]={name:a,f:c.f,d:c.d,g:1,a:$=b,j:r,
-k:v,l:t};i&&(j.subscribe({channel:a+z,callback:i}),!c.g&&!m&&j.here_now({channel:a,callback:function(b){K("uuids"in b?b.uuids:[],function(c){i({action:"join",uuid:c,timestamp:E(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){w&&w(1);clearTimeout(ba);ba=setTimeout(e,100)};if(!q)return y.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||l(),d=a.channel,e=x(),f=null;if(!d)return g("Missing Channel");if(!b)return g("Missing Callback");if(!h)return g("Missing Subscribe Key");"0"!=
-e&&(f={},f.callback=e);u({a:e,data:f,c:function(a){b(a)},b:c,url:[B,"v2","presence","sub_key",h,"channel",N(d)]})},xdr:u,ready:ja,db:C,uuid:J,each:K,map:M,grep:ha,supplant:ia,now:E,unique:fa,updater:ga};D||(D=j.uuid());C.set(h+"uuid",D);setTimeout(d,A);setTimeout(b,v);e=j;e.init=V;e.$=oa;e.attr=na;e.search=pa;e.bind=U;e.css=qa;e.create=ra;if(a.notest)return e;U("beforeunload",window,function(){each_channel(function(a){e.LEAVE(a.name,1)});return!0});U("offline",window,e._reset_offline);U("offline",
-document,e._reset_offline);e.ready();return e}var ka="/",la="&",T=31E4,W,X="undefined"!=typeof localStorage&&localStorage;W={get:function(a){try{return X?X.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}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 k=!1;function l(){return function(){}}var da=1,r=k,w=[],z="-pnpres",A=1E3,ea=/{([\w\-]+)}/g;function fa(){return"x"+ ++da+""+ +new Date}function H(){return+new Date}var J,K=Math.floor(20*Math.random());J=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?L().split("-")[0]:20>++K?K:K=1))||a};function ga(a,c){function b(){f+c>H()?(clearTimeout(d),d=setTimeout(b,c)):(f=H(),a())}var d,f=0;return b}function ha(a,c){var b=[];M(a||[],function(a){c(a)&&b.push(a)});return b}
+function ia(a,c){return a.replace(ea,function(a,d){return c[d]||a})}function L(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 M(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 N(a,c){var b=[];M(a||[],function(a,f){b.push(c(a,f))});return b}
+function O(a){return N(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function P(a){var c=[];M(a,function(a,d){d.g&&c.push(a)});return c.sort()}function ja(){setTimeout(function(){r||(r=1,M(w,function(a){a()}))},A)}
+function S(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&Q())}function b(){if(!t){t=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}C(response)}}var d,f=0,t=0,e;e=setTimeout(function(){c(1)},T);var D=a.data||{},Q=a.b||l(),C=a.c||l();try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;d.timeout=T;D.pnsdk=ka;var i=a.url.join("/");
+if(D){var g=[],i=i+"?",u;for(u in D)g.push(u+"="+D[u]);i+=g.join("&")}url=i;d.open("GET",url,!0);d.send()}catch(E){return c(0),S(a)}return c}function U(a,c,b){M(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=k,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,k):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function la(a){console.error(a)}
+function ma(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)}function na(a){return document.getElementById(a)}function oa(a,c){var b=[];M(a.split(/\s+/),function(a){M((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b}function pa(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 qa(a){return document.createElement(a)}
+function V(a){function c(){}function b(){n.time(function(a){a||x&&x(1);setTimeout(b,C)})}function d(){ra()||x&&x(1);setTimeout(d,A)}function f(a){M(P(p),function(b){(b=p[b])&&a(b)})}function t(a){a&&(s.h=0);!s.h&&s.length&&(s.h=1,v(s.shift()))}a.db=W;a.xdr=S;a.error=la;var e,D=+a.windowing||10,Q=(+a.timeout||310)*A,C=(+a.keepalive||60)*A,i=a.publish_key||"",g=a.subscribe_key||"",u=a.ssl?"s":"",E="http"+u+"://"+(a.origin||"pubsub.pubnub.com"),B=J(E),Z=J(E),s=[],$=0,aa=0,x=0,R=0,ba=0,I=0,p={},v=a.xdr,
+h=a.error||l(),ra=a._is_online||function(){return 1},y=a.jsonp_cb||function(){return 0},F=a.db||{get:l(),set:l()},G=a.uuid||F&&F.get(g+"uuid")||"",n={LEAVE:function(a,b){var c={uuid:G},d=J(E),q=y();0<a.indexOf(z)||("0"!=q&&(c.callback=q),v({n:b||u,timeout:2E3,a:q,data:c,url:[d,"v2","presence","sub_key",g,"channel",O(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",q=a.error||l(),e=a.channel,f=a.start,i=a.end,j={},m=y();if(!e)return h("Missing Channel");
+if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");j.stringtoken="true";j.count=c;j.reverse=d;m&&(j.callback=m);f&&(j.start=f);i&&(j.end=i);v({a:m,data:j,c:function(a){b(a)},b:q,url:[B,"v2","history","sub-key",g,"channel",O(e)]})},replay:function(a){var b=b||a.callback||l(),c=a.source,d=a.destination,e=a.stop,f=a.start,n=a.end,p=a.reverse,a=a.limit,j=y(),m={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");if(!i)return h("Missing Publish Key");
+if(!g)return h("Missing Subscribe Key");"0"!=j&&(m.callback=j);e&&(m.stop="all");p&&(m.reverse="true");f&&(m.start=f);n&&(m.end=n);a&&(m.count=a);v({a:j,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[B,"v1","replay",i,g,c,d],data:m})},time:function(a){var b=y();v({a:b,timeout:5*A,url:[B,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||l(),c=a.message,d=a.channel,e=y();if(!c)return h("Missing Message");if(!d)return h("Missing Channel");
+if(!i)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[B,"publish",i,g,0,O(d),e,O(c)];s.push({a:e,timeout:5*A,url:d,data:{uuid:G},c:function(a){b(a);t(1)},b:function(){b([0,"Failed",c]);t(1)}});t()},unsubscribe:function(a){a=a.channel;I=0;R=1;a=N((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+z}).join(",");M(a.split(","),function(a){r&&n.LEAVE(a,0);p[a]=0});r&&c()},subscribe:function(a,b){function d(a){a?setTimeout(e,A):(B=J(E,1),Z=J(E,
+1),setTimeout(function(){n.time(d)},A));f(function(b){if(a&&b.d)return b.d=0,b.l(b.name);!a&&!b.d&&(b.d=1,b.k(b.name))})}function e(){var a=y(),b=P(p).join(",");b&&(x=v({timeout:C,a:a,b:function(){n.time(d)},data:{uuid:G},url:[Z,"subscribe",g,O(b),a,I],c:function(a){if(!a)return setTimeout(e,ca);f(function(a){a.f||(a.f=1,a.j(a.name))});I=!I&&R&&F.get(g)||a[1];s&&(Timetoken=1E4,s=0);F.set(g,a[1]);var b,c=(2<a.length?a[2]:"").split(",");b=function(){var a=c.shift()||"";return[(p[a]||{}).a||$,(a||aa).split(z)[0]]};
+M(a[0],function(c){var d=b();if(p[d[1]].g)d[0](c,a,d[1])});setTimeout(e,ca)}}))}var q=a.channel,b=(b=b||a.callback)||a.message,i=a.connect||l(),t=a.reconnect||l(),u=a.disconnect||l(),j=a.presence||0,m=a.noheresync||0,s=a.backfill||0,C=a.timeout||Q,ca=a.windowing||D;a.restore&&(R=1);I=0;if(!q)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");M((q.join?q.join(","):""+q).split(","),function(a){var c=p[a]||{};p[aa=a]={name:a,f:c.f,d:c.d,g:1,a:$=b,j:i,
+k:u,l:t};j&&(n.subscribe({channel:a+z,callback:j}),!c.g&&!m&&n.here_now({channel:a,callback:function(b){M("uuids"in b?b.uuids:[],function(c){j({action:"join",uuid:c,timestamp:H(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){x&&x(1);clearTimeout(ba);ba=setTimeout(e,100)};if(!r)return w.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||l(),d=a.channel,e=y(),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);v({a:e,data:f,c:function(a){b(a)},b:c,url:[B,"v2","presence","sub_key",g,"channel",O(d)]})},xdr:v,ready:ja,db:F,uuid:L,each:M,map:N,grep:ha,supplant:ia,now:H,unique:fa,updater:ga};G||(G=n.uuid());F.set(g+"uuid",G);setTimeout(d,A);setTimeout(b,C);e=n;e.init=V;e.$=na;e.attr=ma;e.search=oa;e.bind=U;e.css=pa;e.create=qa;if(a.notest)return e;U("beforeunload",window,function(){each_channel(function(a){e.LEAVE(a.name,1)});return!0});U("offline",window,e._reset_offline);U("offline",
+document,e._reset_offline);e.ready();return e}var ka=O("PubNub-JS-Modern/3.4.4"),T=31E4,W,X="undefined"!=typeof localStorage&&localStorage;W={get:function(a){try{return X?X.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}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){}}};
"undefined"!==typeof module&&(module.o=V)||"undefined"!==typeof exports&&(exports.m=V)||(PUBNUB=V);
var Y=PUBNUB.ws=function(a,c){if(!(this instanceof Y))return new Y(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=l();
b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=k;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:k,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:k})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
View
15 modern/unassembled/platform.js
@@ -33,8 +33,7 @@ THE SOFTWARE.
* UTIL LOCALS
*/
var NOW = 1
-, URLBIT = '/'
-, PARAMSBIT = '&'
+, PNSDK = encode('PubNub-JS-' + PLATFORM + '/' + VERSION)
, XHRTME = 310000;
@@ -90,6 +89,7 @@ function xdr( setup ) {
, complete = 0
, loaded = 0
, timer = timeout( function(){done(1)}, XHRTME )
+ , data = setup.data || {}
, fail = setup.fail || function(){}
, success = setup.success || function(){}
, done = function(failed) {
@@ -116,15 +116,8 @@ function xdr( setup ) {
xhr.onerror = xhr.onabort = function(){ done(1) };
xhr.onload = xhr.onloadend = finished;
xhr.timeout = XHRTME;
- url = setup.url.join(URLBIT);
- if (setup.data) {
- var params = [];
- url += "?";
- for (key in setup.data) {
- params.push(key+"="+setup.data[key]);
- }
- url += params.join(PARAMSBIT);
- }
+ data['pnsdk'] = PNSDK;
+ url = build_url(setup.url, data);
xhr.open( 'GET', url, true );
xhr.send();
}
View
19 nodejs/Makefile
@@ -1,27 +1,26 @@
include ../Makefile.inc
-
OUTPUT_FILES=$(PUBNUB_JS)
+PLATFORM=Nodejs
-
-
-
-.PHONY : all
+.PHONY: all
all: build
-.PHONY : build
+.PHONY: build
build: $(PUBNUB_JS)
-
-
$(PUBNUB_JS): $(PUBNUB_COMMON_JS) $(PUBNUB_NODE_JS)
$(ECHO) "// Version: $(VERSION)" > $(PUBNUB_JS)
cat $(PUBNUB_COMMON_JS) $(PUBNUB_PLATFORM_JS) >> $(PUBNUB_JS)
+ sed -i -e "s/VERSION/\'$(VERSION)\'/g" $(PUBNUB_JS)
+ sed -i -e "s/PLATFORM/\'$(PLATFORM)\'/g" $(PUBNUB_JS)
-.PHONY : clean
+.PHONY: clean
clean:
rm -f $(OUTPUT_FILES)
-.PHONY : test
+.PHONY: test
test:
mocha -R spec tests/test.js
+
+include ../Makefile.post
View
29 nodejs/pubnub.js
@@ -8,6 +8,8 @@ var NOW = 1
, DEF_SUB_TIMEOUT = 310 // SECONDS.
, DEF_KEEPALIVE = 60 // SECONDS.
, SECOND = 1000 // A THOUSAND MILLISECONDS.
+, URLBIT = '/'
+, PARAMSBIT = '&'
, REPL = /{([\w\-]+)}/g;
/**
@@ -34,6 +36,26 @@ var nextorigin = (function() {
}
})();
+
+/**
+ * Build Url
+ * =======
+ *
+ */
+function build_url(url_components, url_params) {
+ var url = url_components.join(URLBIT);
+
+ if (url_params) {
+ var params = [];
+ url += "?";
+ for (var key in url_params) {
+ params.push(key+"="+url_params[key]);
+ }
+ url += params.join(PARAMSBIT);
+ }
+ return url;
+}
+
/**
* UPDATER
* =======
@@ -207,7 +229,7 @@ function PN_API(setup) {
// Announce Leave Event
var SELF = {
'LEAVE' : function( channel, blocking ) {
- var data = { 'uuid' : UUID }
+ var data = { 'uuid' : UUID}
, origin = nextorigin(ORIGIN)
, jsonp = jsonp_cb();
@@ -216,6 +238,7 @@ function PN_API(setup) {
if (jsonp != '0') data['callback'] = jsonp;
+
xdr({
blocking : blocking || SSL,
timeout : 2000,
@@ -708,6 +731,7 @@ var NOW = 1
, XHRTME = 310000
, DEF_TIMEOUT = 10000
, SECOND = 1000
+, PNSDK = encode('PubNub-JS-' + 'Nodejs' + '/' + '3.4.4')
, XORIGN = 1;
@@ -728,7 +752,6 @@ function error(message) { console['error'](message) }
* });
*/
function xdr( setup ) {
- //setup.url.unshift('');
var url = setup.url.join(URLBIT)
, request
, response
@@ -776,6 +799,8 @@ function xdr( setup ) {
}
url += params.join(PARAMSBIT);
}
+ url += '&pnsdk=' + PNSDK ;
+ console.log(url);
var options = {
hostname : origin,
port : ssl ? 443 : 80,
View
4 nodejs/unassembled/platform.js
@@ -40,6 +40,7 @@ var NOW = 1
, XHRTME = 310000
, DEF_TIMEOUT = 10000
, SECOND = 1000
+, PNSDK = encode('PubNub-JS-' + PLATFORM + '/' + VERSION)
, XORIGN = 1;
@@ -60,7 +61,6 @@ function error(message) { console['error'](message) }
* });
*/
function xdr( setup ) {
- //setup.url.unshift('');
var url = setup.url.join(URLBIT)
, request
, response
@@ -108,6 +108,8 @@ function xdr( setup ) {
}
url += params.join(PARAMSBIT);
}
+ url += '&pnsdk=' + PNSDK ;
+ console.log(url);
var options = {
hostname : origin,
port : ssl ? 443 : 80,
View
34 phonegap/Makefile
@@ -0,0 +1,34 @@
+include ../Makefile.inc
+OUTPUT_FILES=$(PUBNUB_MIN_JS) $(PUBNUB_CRYPTO_MIN_JS)
+PLATFORM=Phonegap
+MODERN_PLATFORM_JS=../modern/$(PUBNUB_PLATFORM_JS)
+
+.PHONY : all
+all: build
+
+.PHONY : build
+build: $(PUBNUB_MIN_JS) $(PUBNUB_CRYPTO_MIN_JS)
+
+$(PUBNUB_MIN_JS) : $(PUBNUB_COMMON_JS) $(WEBSOCKET_JS) $(MODERN_PLATFORM_JS)
+ ## Full Version
+ $(ECHO) "// Version: $(VERSION)" > $(PUBNUB_JS)
+ cat $(PUBNUB_COMMON_JS) $(MODERN_PLATFORM_JS) $(WEBSOCKET_JS) >> $(PUBNUB_JS)
+ sed -i -e "s/VERSION/\'$(VERSION)\'/g" $(PUBNUB_JS)
+ sed -i -e "s/PLATFORM/\'$(PLATFORM)\'/g" $(PUBNUB_JS)
+ ## Minfied Version
+ $(ECHO) "// Version: $(VERSION)" > $(PUBNUB_MIN_JS)
+ $(ECHO) "(function(){" >> $(PUBNUB_MIN_JS)
+ cat $(PUBNUB_JS) | java -jar $(GOOGLE_MINIFY) --compilation_level=ADVANCED_OPTIMIZATIONS >> $(PUBNUB_MIN_JS)
+ $(ECHO) "})();" >> $(PUBNUB_MIN_JS)
+
+$(PUBNUB_CRYPTO_MIN_JS) : $(GIBBERISH_JS) $(ENCRYPTO_JS)
+ ## Cryptography
+ $(ECHO) "(function(){" > $(PUBNUB_CRYPTO_MIN_JS)
+ cat $(GIBBERISH_JS) $(ENCRYPT_JS) | java -jar $(GOOGLE_MINIFY) >> $(PUBNUB_CRYPTO_MIN_JS)
+ $(ECHO) "})();" >> $(PUBNUB_CRYPTO_MIN_JS)
+
+.PHONY : clean
+clean:
+ rm -f $(OUTPUT_FILES)
+
+include ../Makefile.post
View
2  phonegap/index.html
@@ -46,7 +46,7 @@
</script>
<div id=pubnub></div>
-<script src=../modern/pubnub.min.js></script>
+<script src=./pubnub.min.js></script>
<script>(function(){
function test( t, msg ) {
View
25 phonegap/pubnub-crypto.min.js
@@ -0,0 +1,25 @@
+(function(){
+PUBNUB.crypto=function(){var e=14,j=8,s=!1,v=function(b,f){var c="",d,q;if(f){d=b[15];if(16<d)throw"Decryption error: Maybe bad key";if(16==d)return"";for(q=0;q<16-d;q++)c+=String.fromCharCode(b[q])}else for(q=0;16>q;q++)c+=String.fromCharCode(b[q]);return c},u=function(b,f){var c=[],d;if(!f)try{b=unescape(encodeURIComponent(b))}catch(q){throw"Error on UTF-8 encode";}for(d=0;d<b.length;d++)c[d]=b.charCodeAt(d);return c},p=function(b,f){var c=12<=e?3:2,d=[],q=[],d=[],q=[],T=b.concat(f),A;d[0]=GibberishAES.Hash.MD5(T);
+q=d[0];for(A=1;A<c;A++)d[A]=GibberishAES.Hash.MD5(d[A-1].concat(T)),q=q.concat(d[A]);d=q.slice(0,4*j);q=q.slice(4*j,4*j+16);return{key:d,iv:q}},r=function(b,f,c){var f=x(f),d=Math.ceil(b.length/16),q=[],e,A=[];for(e=0;e<d;e++){var m=q,p=e,j=b.slice(16*e,16*e+16),r=[],t=void 0,t=void 0;16>j.length&&(t=16-j.length,r=[t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t]);for(t=0;t<j.length;t++)r[t]=j[t];m[p]=r}0===b.length%16&&q.push([16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]);for(e=0;e<q.length;e++)q[e]=0===e?B(q[e],
+c):B(q[e],A[e-1]),A[e]=z(q[e],f);return A},w=function(b,f,c,d){var f=x(f),q=b.length/16,e=[],j,m=[],p="";for(j=0;j<q;j++)e.push(b.slice(16*j,16*(j+1)));for(j=e.length-1;0<=j;j--)m[j]=D(e[j],f),m[j]=0===j?B(m[j],c):B(m[j],e[j-1]);for(j=0;j<q-1;j++)p+=v(m[j]);var p=p+v(m[j],!0),r;if(d)r=p;else try{r=decodeURIComponent(escape(p))}catch(s){throw"Bad Key";}return r},z=function(b,f){s=!1;var c=C(b,f,0),d;for(d=1;d<e+1;d++)c=y(c),c=E(c),d<e&&(c=F(c)),c=C(c,f,d);return c},D=function(b,f){s=!0;var c=C(b,f,
+e),d;for(d=e-1;-1<d;d--)c=E(c),c=y(c),c=C(c,f,d),0<d&&(c=F(c));return c},y=function(b){var f=s?U:S,c=[],d;for(d=0;16>d;d++)c[d]=f[b[d]];return c},E=function(b){var f=[],c=s?[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],d;for(d=0;16>d;d++)f[d]=b[c[d]];return f},F=function(b){var f=[],c;if(s)for(c=0;4>c;c++)f[4*c]=L[b[4*c]]^M[b[1+4*c]]^N[b[2+4*c]]^O[b[3+4*c]],f[1+4*c]=O[b[4*c]]^L[b[1+4*c]]^M[b[2+4*c]]^N[b[3+4*c]],f[2+4*c]=N[b[4*c]]^O[b[1+4*c]]^L[b[2+4*c]]^M[b[3+4*c]],
+f[3+4*c]=M[b[4*c]]^N[b[1+4*c]]^O[b[2+4*c]]^L[b[3+4*c]];else for(c=0;4>c;c++)f[4*c]=P[b[4*c]]^Q[b[1+4*c]]^b[2+4*c]^b[3+4*c],f[1+4*c]=b[4*c]^P[b[1+4*c]]^Q[b[2+4*c]]^b[3+4*c],f[2+4*c]=b[4*c]^b[1+4*c]^P[b[2+4*c]]^Q[b[3+4*c]],f[3+4*c]=Q[b[4*c]]^b[1+4*c]^b[2+4*c]^P[b[3+4*c]];return f},C=function(b,f,c){var d=[],q;for(q=0;16>q;q++)d[q]=b[q]^f[c][q];return d},B=function(b,f){var c=[],d;for(d=0;16>d;d++)c[d]=b[d]^f[d];return c},x=function(b){var f=[],c=[],d,q,p=[];for(d=0;d<j;d++)q=[b[4*d],b[4*d+1],b[4*d+
+2],b[4*d+3]],f[d]=q;for(d=j;d<4*(e+1);d++){f[d]=[];for(b=0;4>b;b++)c[b]=f[d-1][b];if(0===d%j){b=c[0];q=void 0;for(q=0;4>q;q++)c[q]=c[q+1];c[3]=b;c=G(c);c[0]^=X[d/j-1]}else 6<j&&4==d%j&&(c=G(c));for(b=0;4>b;b++)f[d][b]=f[d-j][b]^c[b]}for(d=0;d<e+1;d++){p[d]=[];for(c=0;4>c;c++)p[d].push(f[4*d+c][0],f[4*d+c][1],f[4*d+c][2],f[4*d+c][3])}return p},G=function(b){for(var f=0;4>f;f++)b[f]=S[b[f]];return b},H=function(b,f){var c=[];for(i=0;i<b.length;i+=f)c[i/f]=parseInt(b.substr(i,f),16);return c},I=function(b){for(var f=
+[],c=0;256>c;c++){for(var d=f,q=c,e=b,j=c,m=void 0,p=void 0,m=p=0;8>m;m++)p=1==(j&1)?p^e:p,e=127<e?283^e<<1:e<<1,j>>>=1;d[q]=p}return f},S=H("637c777bf26b6fc53001672bfed7ab76ca82c97dfa5947f0add4a2af9ca472c0b7fd9326363ff7cc34a5e5f171d8311504c723c31896059a071280e2eb27b27509832c1a1b6e5aa0523bd6b329e32f8453d100ed20fcb15b6acbbe394a4c58cfd0efaafb434d338545f9027f503c9fa851a3408f929d38f5bcb6da2110fff3d2cd0c13ec5f974417c4a77e3d645d197360814fdc222a908846eeb814de5e0bdbe0323a0a4906245cc2d3ac629195e479e7c8376d8dd54ea96c56f4ea657aae08ba78252e1ca6b4c6e8dd741f4bbd8b8a703eb5664803f60e613557b986c11d9ee1f8981169d98e949b1e87e9ce5528df8ca1890dbfe6426841992d0fb054bb16",
+2),U,V=S,W=[];for(i=0;i<V.length;i++)W[V[i]]=i;U=W;var X=H("01020408102040801b366cd8ab4d9a2f5ebc63c697356ad4b37dfaefc591",2),P=I(2),Q=I(3),O=I(9),M=I(11),N=I(13),L=I(14),R,J="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",K=J.split("");"function"===typeof Array.indexOf&&(J=K);R={encode:function(b){var f=[],c="",d;totalChunks=Math.floor(16*b.length/3);for(d=0;d<16*b.length;d++)f.push(b[Math.floor(d/16)][d%16]);for(d=0;d<f.length;d+=3)c+=K[f[d]>>2],c+=K[(f[d]&3)<<4|f[d+1]>>4],c=void 0!==
+f[d+1]?c+K[(f[d+1]&15)<<2|f[d+2]>>6]:c+"=",c=void 0!==f[d+2]?c+K[f[d+2]&63]:c+"=";b=c.slice(0,64);for(d=1;d<Math.ceil(c.length/64);d++)b+=c.slice(64*d,64*d+64)+(Math.ceil(c.length/64)==d+1?"":"\n");return b},decode:function(b){var b=b.replace(/\n/g,""),f=[],c=[],d=[],e;for(e=0;e<b.length;e+=4)c[0]=J.indexOf(b.charAt(e)),c[1]=J.indexOf(b.charAt(e+1)),c[2]=J.indexOf(b.charAt(e+2)),c[3]=J.indexOf(b.charAt(e+3)),d[0]=c[0]<<2|c[1]>>4,d[1]=(c[1]&15)<<4|c[2]>>2,d[2]=(c[2]&3)<<6|c[3],f.push(d[0],d[1],d[2]);
+return f=f.slice(0,f.length-f.length%16)}};return{size:function(b){switch(b){case 128:e=10;j=4;break;case 192:e=12;j=6;break;case 256:e=14;j=8;break;default:throw"Invalid Key Size Specified:"+b;}},h2a:function(b){var f=[];b.replace(/(..)/g,function(b){f.push(parseInt(b,16))});return f},expandKey:x,encryptBlock:z,decryptBlock:D,Decrypt:s,s2a:u,rawEncrypt:r,rawDecrypt:w,dec:function(b,f,c){var b=R.decode(b),d=b.slice(8,16),d=p(u(f,c),d),f=d.key,d=d.iv,b=b.slice(16,b.length);return b=w(b,f,d,c)},openSSLKey:p,
+a2h:function(b){var f="",c;for(c=0;c<b.length;c++)f+=(16>b[c]?"0":"")+b[c].toString(16);return f},enc:function(b,f,c){var d;d=[];var e;for(e=0;8>e;e++)d=d.concat(Math.floor(256*Math.random()));e=p(u(f,c),d);f=e.key;e=e.iv;d=[[83,97,108,116,101,100,95,95].concat(d)];b=u(b,c);b=r(b,f,e);b=d.concat(b);return R.encode(b)},Hash:{MD5:function(b){function f(b,c){var d,e,f,g,h;f=b&2147483648;g=c&2147483648;d=b&1073741824;e=c&1073741824;h=(b&1073741823)+(c&1073741823);return d&e?h^2147483648^f^g:d|e?h&1073741824?
+h^3221225472^f^g:h^1073741824^f^g:h^f^g}function c(b,c,d,e,g,h,k){b=f(b,f(f(c&d|~c&e,g),k));return f(b<<h|b>>>32-h,c)}function d(b,c,d,e,g,h,k){b=f(b,f(f(c&e|d&~e,g),k));return f(b<<h|b>>>32-h,c)}function e(b,c,d,g,h,k,l){b=f(b,f(f(c^d^g,h),l));return f(b<<k|b>>>32-k,c)}function j(b,c,d,e,g,h,k){b=f(b,f(f(d^(c|~e),g),k));return f(b<<h|b>>>32-h,c)}function p(b){var c,d,e=[];for(d=0;3>=d;d++)c=b>>>8*d&255,e=e.concat(c);return e}var m=[],r,s,w,t,g,h,k,l,n=H("67452301efcdab8998badcfe10325476d76aa478e8c7b756242070dbc1bdceeef57c0faf4787c62aa8304613fd469501698098d88b44f7afffff5bb1895cd7be6b901122fd987193a679438e49b40821f61e2562c040b340265e5a51e9b6c7aad62f105d02441453d8a1e681e7d3fbc821e1cde6c33707d6f4d50d87455a14eda9e3e905fcefa3f8676f02d98d2a4c8afffa39428771f6816d9d6122fde5380ca4beea444bdecfa9f6bb4b60bebfbc70289b7ec6eaa127fad4ef308504881d05d9d4d039e6db99e51fa27cf8c4ac5665f4292244432aff97ab9423a7fc93a039655b59c38f0ccc92ffeff47d85845dd16fa87e4ffe2ce6e0a30143144e0811a1f7537e82bd3af2352ad7d2bbeb86d391",
+8),m=b.length;r=m+8;s=16*((r-r%64)/64+1);w=[];for(g=t=0;g<m;)r=(g-g%4)/4,t=8*(g%4),w[r]|=b[g]<<t,g++;r=(g-g%4)/4;w[r]|=128<<8*(g%4);w[s-2]=m<<3;w[s-1]=m>>>29;m=w;g=n[0];h=n[1];k=n[2];l=n[3];for(b=0;b<m.length;b+=16)r=g,s=h,w=k,t=l,g=c(g,h,k,l,m[b+0],7,n[4]),l=c(l,g,h,k,m[b+1],12,n[5]),k=c(k,l,g,h,m[b+2],17,n[6]),h=c(h,k,l,g,m[b+3],22,n[7]),g=c(g,h,k,l,m[b+4],7,n[8]),l=c(l,g,h,k,m[b+5],12,n[9]),k=c(k,l,g,h,m[b+6],17,n[10]),h=c(h,k,l,g,m[b+7],22,n[11]),g=c(g,h,k,l,m[b+8],7,n[12]),l=c(l,g,h,k,m[b+9],
+12,n[13]),k=c(k,l,g,h,m[b+10],17,n[14]),h=c(h,k,l,g,m[b+11],22,n[15]),g=c(g,h,k,l,m[b+12],7,n[16]),l=c(l,g,h,k,m[b+13],12,n[17]),k=c(k,l,g,h,m[b+14],17,n[18]),h=c(h,k,l,g,m[b+15],22,n[19]),g=d(g,h,k,l,m[b+1],5,n[20]),l=d(l,g,h,k,m[b+6],9,n[21]),k=d(k,l,g,h,m[b+11],14,n[22]),h=d(h,k,l,g,m[b+0],20,n[23]),g=d(g,h,k,l,m[b+5],5,n[24]),l=d(l,g,h,k,m[b+10],9,n[25]),k=d(k,l,g,h,m[b+15],14,n[26]),h=d(h,k,l,g,m[b+4],20,n[27]),g=d(g,h,k,l,m[b+9],5,n[28]),l=d(l,g,h,k,m[b+14],9,n[29]),k=d(k,l,g,h,m[b+3],14,n[30]),
+h=d(h,k,l,g,m[b+8],20,n[31]),g=d(g,h,k,l,m[b+13],5,n[32]),l=d(l,g,h,k,m[b+2],9,n[33]),k=d(k,l,g,h,m[b+7],14,n[34]),h=d(h,k,l,g,m[b+12],20,n[35]),g=e(g,h,k,l,m[b+5],4,n[36]),l=e(l,g,h,k,m[b+8],11,n[37]),k=e(k,l,g,h,m[b+11],16,n[38]),h=e(h,k,l,g,m[b+14],23,n[39]),g=e(g,h,k,l,m[b+1],4,n[40]),l=e(l,g,h,k,m[b+4],11,n[41]),k=e(k,l,g,h,m[b+7],16,n[42]),h=e(h,k,l,g,m[b+10],23,n[43]),g=e(g,h,k,l,m[b+13],4,n[44]),l=e(l,g,h,k,m[b+0],11,n[45]),k=e(k,l,g,h,m[b+3],16,n[46]),h=e(h,k,l,g,m[b+6],23,n[47]),g=e(g,h,
+k,l,m[b+9],4,n[48]),l=e(l,g,h,k,m[b+12],11,n[49]),k=e(k,l,g,h,m[b+15],16,n[50]),h=e(h,k,l,g,m[b+2],23,n[51]),g=j(g,h,k,l,m[b+0],6,n[52]),l=j(l,g,h,k,m[b+7],10,n[53]),k=j(k,l,g,h,m[b+14],15,n[54]),h=j(h,k,l,g,m[b+5],21,n[55]),g=j(g,h,k,l,m[b+12],6,n[56]),l=j(l,g,h,k,m[b+3],10,n[57]),k=j(k,l,g,h,m[b+10],15,n[58]),h=j(h,k,l,g,m[b+1],21,n[59]),g=j(g,h,k,l,m[b+8],6,n[60]),l=j(l,g,h,k,m[b+15],10,n[61]),k=j(k,l,g,h,m[b+6],15,n[62]),h=j(h,k,l,g,m[b+13],21,n[63]),g=j(g,h,k,l,m[b+4],6,n[64]),l=j(l,g,h,k,m[b+
+11],10,n[65]),k=j(k,l,g,h,m[b+2],15,n[66]),h=j(h,k,l,g,m[b+9],21,n[67]),g=f(g,r),h=f(h,s),k=f(k,w),l=f(l,t);return p(g).concat(p(h),p(k),p(l))}},Base64:R}}();
+PUBNUB.secure=function(){function e(e){var j=s.s2a(JSON.stringify(e)),j=s.rawEncrypt(j,v,u);return s.Base64.encode(j)||e.data.message}function j(e,j){j=j?j:{};try{var w=s.Base64.decode(e),z=s.rawDecrypt(w,v,u,!1);return JSON.parse(z)}catch(D){return j.parse_error||null}}var s=PUBNUB.crypto;s.size(256);var v="",u=s.s2a("0123456789012345");return function(p){v=s.s2a(SHA256(p.cipher_key).slice(0,32));var r=PUBNUB.init(p);return{raw_encrypt:e,raw_decrypt:j,time:PUBNUB.time,publish:function(j){j.message=
+e(j.message);return r.publish(j)},subscribe:function(e){var p=e.callback||e.message;e.callback=function(e,r,s){(e=j(e))&&p(e,r,s)};return r.subscribe(e)},history:function(e){var p="",s=e.callback;e.callback=function(e){p=e[0];var r=[];for(a=0;a<p.length;a++){var u=j(p[a],{parse_error:"DECRYPT_ERROR"});r.push(u)}s([r,e[1],e[2]])};r.history(e);return!0}}}}();
+function SHA256(e){function j(e,j){var p=(e&65535)+(j&65535);return(e>>16)+(j>>16)+(p>>16)<<16|p&65535}function s(e,j){return e>>>j|e<<32-j}var v;v=e.replace(/\r\n/g,"\n");for(var e="",u=0;u<v.length;u++){var p=v.charCodeAt(u);128>p?e+=String.fromCharCode(p):(127<p&&2048>p?e+=String.fromCharCode(p>>6|192):(e+=String.fromCharCode(p>>12|224),e+=String.fromCharCode(p>>6&63|128)),e+=String.fromCharCode(p&63|128))}u=e;v=[];for(p=0;p<8*u.length;p+=8)v[p>>5]|=(u.charCodeAt(p/8)&255)<<24-p%32;var r=8*e.length,
+u=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,
+275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],p=Array(64),w,z,D,y,E,F,C,B,x,G,H;v[r>>5]|=128<<24-r%32;v[(r+64>>9<<4)+15]=r;for(B=0;B<v.length;B+=16){r=e[0];w=e[1];z=e[2];D=e[3];y=e[4];E=e[5];F=e[6];C=e[7];for(x=0;64>x;x++)p[x]=16>x?v[x+B]:j(j(j(s(p[x-2],17)^s(p[x-2],19)^p[x-
+2]>>>10,p[x-7]),s(p[x-15],7)^s(p[x-15],18)^p[x-15]>>>3),p[x-16]),G=j(j(j(j(C,s(y,6)^s(y,11)^s(y,25)),y&E^~y&F),u[x]),p[x]),H=j(s(r,2)^s(r,13)^s(r,22),r&w^r&z^w&z),C=F,F=E,E=y,y=j(D,G),D=z,z=w,w=r,r=j(G,H);e[0]=j(r,e[0]);e[1]=j(w,e[1]);e[2]=j(z,e[2]);e[3]=j(D,e[3]);e[4]=j(y,e[4]);e[5]=j(E,e[5]);e[6]=j(F,e[6]);e[7]=j(C,e[7])}v="";for(u=0;u<4*e.length;u++)v+="0123456789abcdef".charAt(e[u>>2]>>8*(3-u%4)+4&15)+"0123456789abcdef".charAt(e[u>>2]>>8*(3-u%4)&15);return v};
+})();
View
1,099 phonegap/pubnub.js
@@ -0,0 +1,1099 @@
+// Version: 3.4.4
+var NOW = 1
+, READY = false
+, READY_BUFFER = []
+, PRESENCE_SUFFIX = '-pnpres'
+, DEF_WINDOWING = 10 // MILLISECONDS.
+, DEF_TIMEOUT = 10000 // MILLISECONDS.
+, DEF_SUB_TIMEOUT = 310 // SECONDS.
+, DEF_KEEPALIVE = 60 // SECONDS.
+, SECOND = 1000 // A THOUSAND MILLISECONDS.
+, URLBIT = '/'
+, PARAMSBIT = '&'
+, REPL = /{([\w\-]+)}/g;
+
+/**
+ * UTILITIES
+ */
+function unique() { return'x'+ ++NOW+''+(+new Date) }
+function rnow() { return+new Date }
+
+/**
+ * NEXTORIGIN
+ * ==========
+ * var next_origin = nextorigin();
+ */
+var nextorigin = (function() {
+ var max = 20
+ , ori = Math.floor(Math.random() * max);
+ return function( origin, failover ) {
+ return origin.indexOf('pubsub.') > 0
+ && origin.replace(
+ 'pubsub', 'ps' + (
+ failover ? uuid().split('-')[0] :
+ (++ori < max? ori : ori=1)
+ ) ) || origin;
+ }
+})();
+
+
+/**
+ * Build Url
+ * =======
+ *
+ */
+function build_url(url_components, url_params) {
+ var url = url_components.join(URLBIT);
+
+ if (url_params) {
+ var params = [];
+ url += "?";
+ for (var key in url_params) {
+ params.push(key+"="+url_params[key]);
+ }
+ url += params.join(PARAMSBIT);
+ }
+ return url;
+}
+
+/**
+ * UPDATER
+ * =======
+ * var timestamp = unique();
+ */
+function updater( fun, rate ) {
+ var timeout
+ , last = 0
+ , runnit = function() {
+ if (last + rate > rnow()) {
+ clearTimeout(timeout);
+ timeout = setTimeout( runnit, rate );
+ }
+ else {
+ last = rnow();
+ fun();
+ }
+ };
+
+ return runnit;
+}
+
+/**
+ * GREP
+ * ====
+ * var list = grep( [1,2,3], function(item) { return item % 2 } )
+ */
+function grep( list, fun ) {
+ var fin = [];
+ each( list || [], function(l) { fun(l) && fin.push(l) } );
+ return fin
+}
+
+/**
+ * SUPPLANT
+ * ========
+ * var text = supplant( 'Hello {name}!', { name : 'John' } )
+ */
+function supplant( str, values ) {
+ return str.replace( REPL, function( _, match ) {
+ return values[match] || _
+ } );
+}
+
+/**
+ * timeout
+ * =======
+ * timeout( function(){}, 100 );
+ */
+function timeout( fun, wait ) {
+ return setTimeout( fun, wait );
+}
+
+/**
+ * uuid
+ * ====
+ * var my_uuid = uuid();
+ */
+function uuid(callback) {
+ var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
+ function(c) {
+ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
+ return v.toString(16);
+ });
+ if (callback) callback(u);
+ return u;
+}
+
+/**
+ * EACH
+ * ====
+ * each( [1,2,3], function(item) { } )
+ */
+function each( o, f ) {
+ if ( !o || !f ) return;
+
+ if ( typeof o[0] != 'undefined' )
+ for ( var i = 0, l = o.length; i < l; )
+ f.call( o[i], o[i], i++ );
+ else
+ for ( var i in o )
+ o.hasOwnProperty &&
+ o.hasOwnProperty(i) &&
+ f.call( o[i], i, o[i] );
+}
+
+/**
+ * MAP
+ * ===
+ * var list = map( [1,2,3], function(item) { return item + 1 } )
+ */
+function map( list, fun ) {
+ var fin = [];
+ each( list || [], function( k, v ) { fin.push(fun( k, v )) } );
+ return fin;
+}
+
+/**
+ * ENCODE
+ * ======
+ * var encoded_path = encode('path');
+ */
+function encode(path) {
+ return map( (encodeURIComponent(path)).split(''), function(chr) {
+ return "-_.!~*'()".indexOf(chr) < 0 ? chr :
+ "%"+chr.charCodeAt(0).toString(16).toUpperCase()
+ } ).join('');
+}
+
+/**
+ * Generate Subscription Channel List
+ * ==================================
+ * generate_channel_list(channels_object);
+ */
+function generate_channel_list(channels) {
+ var list = [];
+ each( channels, function( channel, status ) {
+ if (status.subscribed) list.push(channel);
+ } );
+ return list.sort();
+}
+
+// PUBNUB READY TO CONNECT
+function ready() { timeout( function() {
+ if (READY) return;
+ READY = 1;
+ each( READY_BUFFER, function(connect) { connect() } );
+}, SECOND ); }
+
+function PN_API(setup) {
+ var SUB_WINDOWING = +setup['windowing'] || DEF_WINDOWING
+ , SUB_TIMEOUT = (+setup['timeout'] || DEF_SUB_TIMEOUT) * SECOND
+ , KEEPALIVE = (+setup['keepalive'] || DEF_KEEPALIVE) * SECOND
+ , PUBLISH_KEY = setup['publish_key'] || ''
+ , SUBSCRIBE_KEY = setup['subscribe_key'] || ''
+ , SSL = setup['ssl'] ? 's' : ''
+ , ORIGIN = 'http'+SSL+'://'+(setup['origin']||'pubsub.pubnub.com')
+ , STD_ORIGIN = nextorigin(ORIGIN)
+ , SUB_ORIGIN = nextorigin(ORIGIN)
+ , CONNECT = function(){}
+ , PUB_QUEUE = []
+ , SUB_CALLBACK = 0
+ , SUB_CHANNEL = 0
+ , SUB_RECEIVER = 0
+ , SUB_RESTORE = 0
+ , SUB_BUFF_WAIT = 0
+ , TIMETOKEN = 0
+ , CHANNELS = {}
+ , xdr = setup['xdr']
+ , error = setup['error'] || function() {}
+ , _is_online = setup['_is_online'] || function() { return 1; }
+ , jsonp_cb = setup['jsonp_cb'] || function(){ return 0; }
+ , db = setup['db'] || {'get': function(){}, 'set': function(){}}
+ , UUID = setup['uuid'] || ( db && db['get'](SUBSCRIBE_KEY+'uuid') || '');
+
+ function publish(next) {
+ if (next) PUB_QUEUE.sending = 0;
+ if (PUB_QUEUE.sending || !PUB_QUEUE.length) return;
+ PUB_QUEUE.sending = 1;
+ xdr(PUB_QUEUE.shift());
+ }
+
+ function each_channel(callback) {
+ each( generate_channel_list(CHANNELS), function(channel) {
+ var chan = CHANNELS[channel];
+ if (!chan) return;
+ callback(chan);
+ } );
+ }
+
+ // Announce Leave Event
+ var SELF = {
+ 'LEAVE' : function( channel, blocking ) {
+ var data = { 'uuid' : UUID}
+ , origin = nextorigin(ORIGIN)
+ , jsonp = jsonp_cb();
+
+ // Prevent Leaving a Presence Channel
+ if (channel.indexOf(PRESENCE_SUFFIX) > 0) return;
+
+ if (jsonp != '0') data['callback'] = jsonp;
+
+
+ xdr({
+ blocking : blocking || SSL,
+ timeout : 2000,
+ callback : jsonp,
+ data : data,
+ url : [
+ origin, 'v2', 'presence', 'sub_key',
+ SUBSCRIBE_KEY, 'channel', encode(channel), 'leave'
+ ]
+ });
+ },
+ /*
+ PUBNUB.history({
+ channel : 'my_chat_channel',
+ limit : 100,
+ callback : function(history) { }
+ });
+ */
+ 'history' : function( args, callback ) {
+ var callback = args['callback'] || callback
+ , count = args['count'] || args['limit'] || 100
+ , reverse = args['reverse'] || "false"
+ , err = args['error'] || function(){}
+ , channel = args['channel']
+ , start = args['start']
+ , end = args['end']
+ , params = {}
+ , jsonp = jsonp_cb();
+
+ // Make sure we have a Channel
+ if (!channel) return error('Missing Channel');
+ if (!callback) return error('Missing Callback');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ params['stringtoken'] = 'true';
+ params['count'] = count;
+ params['reverse'] = reverse;
+
+ if (jsonp) params['callback'] = jsonp;
+ if (start) params['start'] = start;
+ if (end) params['end'] = end;
+
+ // Send Message
+ xdr({
+ callback : jsonp,
+ data : params,
+ success : function(response) { callback(response) },
+ fail : err,
+ url : [
+ STD_ORIGIN, 'v2', 'history', 'sub-key',
+ SUBSCRIBE_KEY, 'channel', encode(channel)
+ ]
+ });
+ },
+
+ /*
+ PUBNUB.replay({
+ source : 'my_channel',
+ destination : 'new_channel'
+ });
+ */
+ 'replay' : function(args) {
+ var callback = callback || args['callback'] || function(){}
+ , source = args['source']
+ , destination = args['destination']
+ , stop = args['stop']
+ , start = args['start']
+ , end = args['end']
+ , reverse = args['reverse']
+ , limit = args['limit']
+ , jsonp = jsonp_cb()
+ , data = {}
+ , url;
+
+ // Check User Input
+ if (!source) return error('Missing Source Channel');
+ if (!destination) return error('Missing Destination Channel');
+ if (!PUBLISH_KEY) return error('Missing Publish Key');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ // Setup URL Params
+ if (jsonp != '0') data['callback'] = jsonp;
+ if (stop) data['stop'] = 'all';
+ if (reverse) data['reverse'] = 'true';
+ if (start) data['start'] = start;
+ if (end) data['end'] = end;
+ if (limit) data['count'] = limit;
+
+ // Compose URL Parts
+ url = [
+ STD_ORIGIN, 'v1', 'replay',
+ PUBLISH_KEY, SUBSCRIBE_KEY,
+ source, destination
+ ];
+
+ // Start (or Stop) Replay!
+ xdr({
+ callback : jsonp,
+ success : function(response) { callback(response) },
+ fail : function() { callback([ 0, 'Disconnected' ]) },
+ url : url,
+ data : data
+ });
+ },
+
+ /*
+ PUBNUB.time(function(time){ });
+ */
+ 'time' : function(callback) {
+ var jsonp = jsonp_cb();
+ xdr({
+ callback : jsonp,
+ timeout : SECOND*5,
+ url : [STD_ORIGIN, 'time', jsonp],
+ success : function(response) { callback(response[0]) },
+ fail : function() { callback(0) }
+ });
+ },
+
+ /*
+ PUBNUB.publish({
+ channel : 'my_chat_channel',
+ message : 'hello!'
+ });
+ */
+ 'publish' : function( args, callback ) {
+ var callback = callback || args['callback'] || function(){}
+ , msg = args['message']
+ , channel = args['channel']
+ , jsonp = jsonp_cb()
+ , url;
+
+ if (!msg) return error('Missing Message');
+ if (!channel) return error('Missing Channel');
+ if (!PUBLISH_KEY) return error('Missing Publish Key');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ // If trying to send Object
+ msg = JSON['stringify'](msg);
+
+ // Create URL
+ url = [
+ STD_ORIGIN, 'publish',
+ PUBLISH_KEY, SUBSCRIBE_KEY,
+ 0, encode(channel),
+ jsonp, encode(msg)
+ ];
+
+ // Queue Message Send
+ PUB_QUEUE.push({
+ callback : jsonp,
+ timeout : SECOND*5,
+ url : url,
+ data : { 'uuid' : UUID },
+ success : function(response){callback(response);publish(1)},
+ fail : function(){callback([0,'Failed',msg]);publish(1)}
+ });
+
+ // Send Message
+ publish();
+ },
+
+ /*
+ PUBNUB.unsubscribe({ channel : 'my_chat' });
+ */
+ 'unsubscribe' : function(args) {
+ var channel = args['channel'];
+
+ TIMETOKEN = 0;
+ SUB_RESTORE = 1;
+
+ // Prepare Channel(s)
+ channel = map( (
+ channel.join ? channel.join(',') : ''+channel
+ ).split(','), function(channel) {
+ return channel + ',' + channel + PRESENCE_SUFFIX;
+ } ).join(',');
+
+ // Iterate over Channels
+ each( channel.split(','), function(channel) {
+ if (READY) SELF['LEAVE']( channel, 0 );
+ CHANNELS[channel] = 0;
+ } );
+
+ // ReOpen Connection if Any Channels Left
+ if (READY) CONNECT();
+ },
+
+ /*
+ PUBNUB.subscribe({
+ channel : 'my_chat'
+ callback : function(message) { }
+ });
+ */
+ '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
+ , restore = args['restore'];
+
+ // Restore Enabled?
+ if (restore) SUB_RESTORE = 1;
+
+ TIMETOKEN = 0;
+
+ // Make sure we have a Channel
+ if (!channel) return error('Missing Channel');
+ if (!callback) return error('Missing Callback');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ // Setup Channel(s)
+ each( (channel.join ? channel.join(',') : ''+channel).split(','),
+ function(channel) {
+ var settings = CHANNELS[channel] || {};
+
+ // Store Channel State
+ CHANNELS[SUB_CHANNEL = channel] = {
+ name : channel,
+ connected : settings.connected,
+ disconnected : settings.disconnected,
+ subscribed : 1,
+ callback : SUB_CALLBACK = callback,
+ connect : connect,
+ disconnect : disconnect,
+ reconnect : reconnect
+ };
+
+ // Presence Enabled?
+ if (!presence) return;
+
+ // Subscribe Presence Channel
+ SELF['subscribe']({
+ 'channel' : channel + PRESENCE_SUFFIX,
+ 'callback' : presence
+ });
+
+ // Presence Subscribed?
+ if (settings.subscribed) return;
+
+ // See Who's Here Now?
+ if (noheresync) return;
+ SELF['here_now']({
+ 'channel' : channel,
+ 'callback' : function(here) {
+ each( 'uuids' in here ? here['uuids'] : [],
+ function(uid) { presence( {
+ 'action' : 'join',
+ 'uuid' : uid,
+ 'timestamp' : rnow(),
+ 'occupancy' : here['occupancy'] || 1
+ }, here, channel ); } );
+ }
+ });
+ } );
+
+ // Test Network Connection
+ function _test_connection(success) {
+ if (success) {
+ // Begin Next Socket Connection
+ timeout( _connect, SECOND );
+ }
+ else {
+ // New Origin on Failed Connection
+ STD_ORIGIN = nextorigin( ORIGIN, 1 );
+ SUB_ORIGIN = nextorigin( ORIGIN, 1 );
+
+ // Re-test Connection
+ timeout( function() {
+ SELF['time'](_test_connection);
+ }, SECOND );
+ }
+
+ // Disconnect & Reconnect
+ each_channel(function(channel){
+ // Reconnect
+ if (success && channel.disconnected) {
+ channel.disconnected = 0;
+ return channel.reconnect(channel.name);
+ }
+
+ // Disconnect
+ if (!success && !channel.disconnected) {
+ channel.disconnected = 1;
+ channel.disconnect(channel.name);
+ }
+ });
+ }
+
+ // Evented Subscribe
+ function _connect() {
+ var jsonp = jsonp_cb()
+ , channels = generate_channel_list(CHANNELS).join(',');
+
+ // Stop Connection
+ if (!channels) return;
+
+ // Connect to PubNub Subscribe Servers
+ SUB_RECEIVER = xdr({
+ timeout : sub_timeout,
+ callback : jsonp,
+ fail : function() { SELF['time'](_test_connection) },
+ data : { 'uuid' : UUID },
+ url : [
+ SUB_ORIGIN, 'subscribe',
+ SUBSCRIBE_KEY, encode(channels),
+ jsonp, TIMETOKEN
+ ],
+ success : function(messages) {
+ if (!messages) return timeout( _connect, windowing );
+
+ // Connect
+ each_channel(function(channel){
+ if (channel.connected) return;
+ channel.connected = 1;
+ channel.connect(channel.name);
+ });
+
+ // Restore Previous Connection Point if Needed
+ TIMETOKEN = !TIMETOKEN &&
+ SUB_RESTORE &&
+ db['get'](SUBSCRIBE_KEY) || messages[1];
+
+
+ if (backfill) {
+ Timetoken = 10000;
+ backfill = 0;
+ }
+
+ // Update Saved Timetoken
+ db['set']( SUBSCRIBE_KEY, messages[1] );
+
+ // Route Channel <---> Callback for Message
+ var next_callback = (function() {
+ var channels = (messages.length>2?messages[2]:'')
+ , list = channels.split(',');
+
+ return function() {
+ var channel = list.shift()||'';
+ return [
+ (CHANNELS[channel]||{})
+ .callback||SUB_CALLBACK,
+ (channel||SUB_CHANNEL)
+ .split(PRESENCE_SUFFIX)[0]
+ ];
+ };
+ })();
+
+ each( messages[0], function(msg) {
+ var next = next_callback();
+ if (!CHANNELS[next[1]].subscribed) return;
+ next[0]( msg, messages, next[1] );
+ } );
+
+ timeout( _connect, windowing );
+ }
+ });
+ }
+
+ CONNECT = function() {
+ // Close Previous Subscribe Connection
+ _reset_offline();
+
+ // Begin Recursive Subscribe
+ clearTimeout(SUB_BUFF_WAIT);
+ SUB_BUFF_WAIT = timeout( _connect, 100 );
+ };
+
+ // Reduce Status Flicker
+ if (!READY) return READY_BUFFER.push(CONNECT);
+
+ // Connect Now
+ CONNECT();
+ },
+
+ 'here_now' : function( args, callback ) {
+ var callback = args['callback'] || callback
+ , err = args['error'] || function(){}
+ , channel = args['channel']
+ , jsonp = jsonp_cb()
+ , data = null;
+
+ // Make sure we have a Channel
+ if (!channel) return error('Missing Channel');
+ if (!callback) return error('Missing Callback');
+ if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
+
+ if (jsonp != '0') {
+ data = {};
+ data['callback'] = jsonp;
+ }
+
+ xdr({
+ callback : jsonp,
+ data : data,
+ success : function(response) { callback(response) },
+ fail : err,
+ url : [
+ STD_ORIGIN, 'v2', 'presence',
+ 'sub_key', SUBSCRIBE_KEY,
+ 'channel', encode(channel)
+ ]
+ });
+ },
+
+ // Expose PUBNUB Functions
+ 'xdr' : xdr,
+ 'ready' : ready,
+ 'db' : db,
+ 'uuid' : uuid,
+ 'each' : each,
+ 'map' : map,
+ 'grep' : grep,
+ 'supplant' : supplant,
+ 'now' : rnow,
+ 'unique' : unique,
+ 'updater' : updater
+ };
+
+ function _poll_online() {
+ _is_online() || _reset_offline();
+ timeout( _poll_online, SECOND );
+ }
+
+ function _poll_online2() {
+ SELF['time'](function(success){
+ success || _reset_offline();
+ timeout( _poll_online2, KEEPALIVE );
+ })
+ }
+
+ function _reset_offline() {
+ SUB_RECEIVER && SUB_RECEIVER(1);
+ }
+
+ if (!UUID) UUID = SELF['uuid']();
+ db['set']( SUBSCRIBE_KEY + 'uuid', UUID );
+
+ timeout( _poll_online, SECOND );
+ timeout( _poll_online2, KEEPALIVE );
+
+ return SELF;
+}
+/* ---------------------------------------------------------------------------
+--------------------------------------------------------------------------- */
+
+/* ---------------------------------------------------------------------------
+PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks
+Copyright (c) 2011 PubNub Inc.
+http://www.pubnub.com/
+http://www.pubnub.com/terms
+--------------------------------------------------------------------------- */
+
+/* ---------------------------------------------------------------------------
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+--------------------------------------------------------------------------- */
+(function(){
+
+/**
+ * UTIL LOCALS
+ */
+var NOW = 1
+, PNSDK = encode('PubNub-JS-' + 'Phonegap' + '/' + '3.4.4')
+, XHRTME = 310000;
+
+
+
+/**
+ * LOCAL STORAGE
+ */
+var db = (function(){
+ var ls = typeof localStorage != 'undefined' && localStorage;
+ return {
+ get : function(key) {
+ try {
+ if (ls) return ls.getItem(key);
+ if (document.cookie.indexOf(key) == -1) return null;
+ return ((document.cookie||'').match(
+ RegExp(key+'=([^;]+)')
+ )||[])[1] || null;
+ } catch(e) { return }
+ },
+ set : function( key, value ) {
+ try {
+ if (ls) return ls.setItem( key, value ) && 0;
+ document.cookie = key + '=' + value +
+ '; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/';
+ } catch(e) { return }
+ }
+ };
+})();
+
+
+/**
+ * CORS XHR Request
+ * ================
+ * xdr({
+ * url : ['http://www.blah.com/url'],
+ * success : function(response) {},
+ * fail : function() {}
+ * });
+ */
+function xdr( setup ) {
+ var xhr
+ , finished = function() {
+ if (loaded) return;
+ loaded = 1;
+
+ clearTimeout(timer);
+
+ try { response = JSON['parse'](xhr.responseText); }
+ catch (r) { return done(1); }
+
+ success(response);
+ }
+ , complete = 0
+ , loaded = 0
+ , timer = timeout( function(){done(1)}, XHRTME )
+ , data = setup.data || {}
+ , fail = setup.fail || function(){}
+ , success = setup.success || function(){}
+ , done = function(failed) {
+ if (complete) return;
+ complete = 1;
+
+ clearTimeout(timer);
+
+ if (xhr) {
+ xhr.onerror = xhr.onload = null;
+ xhr.abort && xhr.abort();
+ xhr = null;
+ }
+
+ failed && fail();
+ };
+
+ // Send
+ try {
+ xhr = typeof XDomainRequest !== 'undefined' &&
+ new XDomainRequest() ||
+ new XMLHttpRequest();
+
+ xhr.onerror = xhr.onabort = function(){ done(1) };
+ xhr.onload = xhr.onloadend = finished;
+ xhr.timeout = XHRTME;
+ data['pnsdk'] = PNSDK;
+ url = build_url(setup.url, data);
+ xhr.open( 'GET', url, true );
+ xhr.send();
+ }
+ catch(eee) {
+ done(0);
+ return xdr(setup);
+ }
+
+ // Return 'done'
+ return done;
+}
+
+/**
+ * BIND
+ * ====
+ * bind( 'keydown', search('a')[0], function(element) {
+ * ...
+ * } );
+ */
+function bind( type, el, fun ) {
+ each( type.split(','), function(etype) {
+ var rapfun = function(e) {
+ if (!e) e = window.event;
+ if (!fun(e)) {
+ e.cancelBubble = true;
+ e.returnValue = false;
+ e.preventDefault && e.preventDefault();
+ e.stopPropagation && e.stopPropagation();
+ }
+ };
+
+ if ( el.addEventListener ) el.addEventListener( etype, rapfun, false );
+ else if ( el.attachEvent ) el.attachEvent( 'on' + etype, rapfun );
+ else el[ 'on' + etype ] = rapfun;
+ } );
+}
+
+/**
+ * UNBIND
+ * ======
+ * unbind( 'keydown', search('a')[0] );
+ */
+function unbind( type, el, fun ) {
+ if ( el.removeEventListener ) el.removeEventListener( type, false );
+ else if ( el.detachEvent ) el.detachEvent( 'on' + type, false );
+ else el[ 'on' + type ] = null;
+}
+
+/**
+ * ERROR
+ * ===
+ * error('message');
+ */
+function error(message) { console['error'](message) }
+
+/**
+ * EVENTS
+ * ======
+ * PUBNUB.events.bind( 'you-stepped-on-flower', function(message) {
+ * // Do Stuff with message
+ * } );
+ *
+ * PUBNUB.events.fire( 'you-stepped-on-flower', "message-data" );
+ * PUBNUB.events.fire( 'you-stepped-on-flower', {message:"data"} );
+ * PUBNUB.events.fire( 'you-stepped-on-flower', [1,2,3] );
+ *
+ */
+var events = {
+ 'list' : {},
+ 'unbind' : function( name ) { events.list[name] = [] },
+ 'bind' : function( name, fun ) {
+ (events.list[name] = events.list[name] || []).push(fun);
+ },
+ 'fire' : function( name, data ) {
+ each(
+ events.list[name] || [],
+ function(fun) { fun(data) }
+ );
+ }
+};
+
+/**
+ * ATTR
+ * ====
+ * var attribute = attr( node, 'attribute' );
+ */
+function attr( node, attribute, value ) {
+ if (value) node.setAttribute( attribute, value );
+ else return node && node.getAttribute && node.getAttribute(attribute);
+}
+
+/**
+ * $
+ * =
+ * var div = $('divid');
+ */
+function $(id) { return document.getElementById(id) }
+
+
+/**
+ * SEARCH
+ * ======
+ * var elements = search('a div span');
+ */
+function search( elements, start ) {
+ var list = [];
+ each( elements.split(/\s+/), function(el) {
+ each( (start || document).getElementsByTagName(el), function(node) {
+ list.push(node);
+ } );
+ } );
+ return list;
+}
+
+/**
+ * CSS
+ * ===
+ * var obj = create('div');
+ */
+function css( element, styles ) {
+ for (var style in styles) if (styles.hasOwnProperty(style))
+ try {element.style[style] = styles[style] + (
+ '|width|height|top|left|'.indexOf(style) > 0 &&
+ typeof styles[style] == 'number'
+ ? 'px' : ''
+ )}catch(e){}
+}
+
+/**
+ * CREATE
+ * ======
+ * var obj = create('div');
+ */
+function create(element) { return document.createElement(element) }
+
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+/* =-========================= PUBNUB ===========================-= */
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+
+function PN(setup) {
+
+
+ setup['db'] = db;
+ setup['xdr'] = xdr;
+ setup['error'] = error;
+ var SELF = PN_API(setup);
+
+ SELF['init'] = PN;
+ SELF['$'] = $;
+ SELF['attr'] = attr;
+ SELF['search'] = search;
+ SELF['bind'] = bind;
+ SELF['css'] = css;
+ SELF['create'] = create;
+
+ // Return without Testing
+ if (setup['notest']) return SELF;
+
+ // Add Leave Functions
+ bind( 'beforeunload', window, function() {
+ each_channel(function(ch){ SELF['LEAVE']( ch.name, 1 ) });
+ return true;
+ } );
+
+ bind( 'offline', window, SELF['_reset_offline'] );
+ bind( 'offline', document, SELF['_reset_offline'] );
+
+ SELF['ready']();
+ return SELF;
+}
+
+typeof module !== 'undefined' && (module.exports = PN) ||
+typeof exports !== 'undefined' && (exports.PN = PN) || (PUBNUB = PN);
+
+})();
+(function(){
+
+// ---------------------------------------------------------------------------
+// WEBSOCKET INTERFACE
+// ---------------------------------------------------------------------------
+var WS = PUBNUB['ws'] = function( url, protocols ) {
+ if (!(this instanceof WS)) return new WS( url, protocols );
+
+ var self = this
+ , url = self.url = url || ''
+ , protocol = self.protocol = protocols || 'Sec-WebSocket-Protocol'
+ , bits = url.split('/')
+ , setup = {
+ 'ssl' : bits[0] === 'wss:'
+ ,'origin' : bits[2]
+ ,'publish_key' : bits[3]
+ ,'subscribe_key' : bits[4]
+ ,'channel' : bits[5]
+ };
+
+ // READY STATES
+ self['CONNECTING'] = 0; // The connection is not yet open.
+ self['OPEN'] = 1; // The connection is open and ready to communicate.
+ self['CLOSING'] = 2; // The connection is in the process of closing.
+ self['CLOSED'] = 3; // The connection is closed or couldn't be opened.
+
+ // CLOSE STATES
+ self['CLOSE_NORMAL'] = 1000; // Normal Intended Close; completed.
+ self['CLOSE_GOING_AWAY'] = 1001; // Closed Unexpecttedly.
+ self['CLOSE_PROTOCOL_ERROR'] = 1002; // Server: Not Supported.
+ self['CLOSE_UNSUPPORTED'] = 1003; // Server: Unsupported Protocol.
+ self['CLOSE_TOO_LARGE'] = 1004; // Server: Too Much Data.
+ self['CLOSE_NO_STATUS'] = 1005; // Server: No reason.
+ self['CLOSE_ABNORMAL'] = 1006; // Abnormal Disconnect.
+
+ // Events Default
+ self['onclose'] = self['onerror'] =
+ self['onmessage'] = self['onopen'] =
+ self['onsend'] = function(){};
+
+ // Attributes
+ self['binaryType'] = '';
+ self['extensions'] = '';
+ self['bufferedAmount'] = 0;
+ self['trasnmitting'] = false;
+ self['buffer'] = [];
+ self['readyState'] = self['CONNECTING'];
+
+ // Close if no setup.
+ if (!url) {
+ self['readyState'] = self['CLOSED'];
+ self['onclose']({
+ 'code' : self['CLOSE_ABNORMAL'],
+ 'reason' : 'Missing URL',
+ 'wasClean' : true
+ });
+ return self;
+ }
+
+ // PubNub WebSocket Emulation
+ self.pubnub = PUBNUB['init'](setup);
+ self.pubnub.setup = setup;
+ self.setup = setup;
+
+ self.pubnub['subscribe']({
+ 'restore' : false,
+ 'channel' : setup['channel'],
+ 'disconnect' : self['onerror'],
+ 'reconnect' : self['onopen'],
+ 'error' : function() {
+ self['onclose']({
+ 'code' : self['CLOSE_ABNORMAL'],
+ 'reason' : 'Missing URL',
+ 'wasClean' : false
+ });
+ },
+ 'callback' : function(message) {
+ self['onmessage']({ 'data' : message });
+ },
+ 'connect' : function() {
+ self['readyState'] = self['OPEN'];
+ self['onopen']();
+ }
+ });
+};
+
+// ---------------------------------------------------------------------------
+// WEBSOCKET SEND
+// ---------------------------------------------------------------------------
+WS.prototype.send = function(data) {
+ var self = this;
+ self.pubnub['publish']({
+ 'channel' : self.pubnub.setup['channel'],
+ 'message' : data,
+ 'callback' : function(response) {
+ self['onsend']({ 'data' : response });
+ }
+ });
+};
+
+// ---------------------------------------------------------------------------
+// WEBSOCKET CLOSE
+// ---------------------------------------------------------------------------
+WS.prototype.close = function() {
+ var self = this;
+ self.pubnub['unsubscribe']({ 'channel' : self.pubnub.setup['channel'] });
+ self['readyState'] = self['CLOSED'];
+ self['onclose']({});
+};
+
+})();
View
23 phonegap/pubnub.min.js
@@ -0,0 +1,23 @@
+// Version: 3.4.4
+(function(){
+var k=!1;function l(){return function(){}}var da=1,r=k,w=[],z="-pnpres",A=1E3,ea=/{([\w\-]+)}/g;function fa(){return"x"+ ++da+""+ +new Date}function H(){return+new Date}var J,K=Math.floor(20*Math.random());J=function(a,c){return 0<a.indexOf("pubsub.")&&a.replace("pubsub","ps"+(c?L().split("-")[0]:20>++K?K:K=1))||a};function ga(a,c){function b(){f+c>H()?(clearTimeout(d),d=setTimeout(b,c)):(f=H(),a())}var d,f=0;return b}function ha(a,c){var b=[];M(a||[],function(a){c(a)&&b.push(a)});return b}
+function ia(a,c){return a.replace(ea,function(a,d){return c[d]||a})}function L(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 M(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 N(a,c){var b=[];M(a||[],function(a,f){b.push(c(a,f))});return b}
+function O(a){return N(encodeURIComponent(a).split(""),function(a){return 0>"-_.!~*'()".indexOf(a)?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function P(a){var c=[];M(a,function(a,d){d.g&&c.push(a)});return c.sort()}function ja(){setTimeout(function(){r||(r=1,M(w,function(a){a()}))},A)}
+function S(a){function c(a){f||(f=1,clearTimeout(e),d&&(d.onerror=d.onload=null,d.abort&&d.abort(),d=null),a&&Q())}function b(){if(!t){t=1;clearTimeout(e);try{response=JSON.parse(d.responseText)}catch(a){return c(1)}C(response)}}var d,f=0,t=0,e;e=setTimeout(function(){c(1)},T);var D=a.data||{},Q=a.b||l(),C=a.c||l();try{d="undefined"!==typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=d.onabort=function(){c(1)};d.onload=d.onloadend=b;d.timeout=T;D.pnsdk=ka;var i=a.url.join("/");
+if(D){var g=[],i=i+"?",u;for(u in D)g.push(u+"="+D[u]);i+=g.join("&")}url=i;d.open("GET",url,!0);d.send()}catch(E){return c(0),S(a)}return c}function U(a,c,b){M(a.split(","),function(a){function f(a){a||(a=window.event);b(a)||(a.cancelBubble=!0,a.returnValue=k,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())}c.addEventListener?c.addEventListener(a,f,k):c.attachEvent?c.attachEvent("on"+a,f):c["on"+a]=f})}function la(a){console.error(a)}
+function ma(a,c,b){if(b)a.setAttribute(c,b);else return a&&a.getAttribute&&a.getAttribute(c)}function na(a){return document.getElementById(a)}function oa(a,c){var b=[];M(a.split(/\s+/),function(a){M((c||document).getElementsByTagName(a),function(a){b.push(a)})});return b}function pa(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 qa(a){return document.createElement(a)}
+function V(a){function c(){}function b(){n.time(function(a){a||x&&x(1);setTimeout(b,C)})}function d(){ra()||x&&x(1);setTimeout(d,A)}function f(a){M(P(p),function(b){(b=p[b])&&a(b)})}function t(a){a&&(s.h=0);!s.h&&s.length&&(s.h=1,v(s.shift()))}a.db=W;a.xdr=S;a.error=la;var e,D=+a.windowing||10,Q=(+a.timeout||310)*A,C=(+a.keepalive||60)*A,i=a.publish_key||"",g=a.subscribe_key||"",u=a.ssl?"s":"",E="http"+u+"://"+(a.origin||"pubsub.pubnub.com"),B=J(E),Z=J(E),s=[],$=0,aa=0,x=0,R=0,ba=0,I=0,p={},v=a.xdr,
+h=a.error||l(),ra=a._is_online||function(){return 1},y=a.jsonp_cb||function(){return 0},F=a.db||{get:l(),set:l()},G=a.uuid||F&&F.get(g+"uuid")||"",n={LEAVE:function(a,b){var c={uuid:G},d=J(E),q=y();0<a.indexOf(z)||("0"!=q&&(c.callback=q),v({n:b||u,timeout:2E3,a:q,data:c,url:[d,"v2","presence","sub_key",g,"channel",O(a),"leave"]}))},history:function(a,b){var b=a.callback||b,c=a.count||a.limit||100,d=a.reverse||"false",q=a.error||l(),e=a.channel,f=a.start,i=a.end,j={},m=y();if(!e)return h("Missing Channel");
+if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");j.stringtoken="true";j.count=c;j.reverse=d;m&&(j.callback=m);f&&(j.start=f);i&&(j.end=i);v({a:m,data:j,c:function(a){b(a)},b:q,url:[B,"v2","history","sub-key",g,"channel",O(e)]})},replay:function(a){var b=b||a.callback||l(),c=a.source,d=a.destination,e=a.stop,f=a.start,n=a.end,p=a.reverse,a=a.limit,j=y(),m={};if(!c)return h("Missing Source Channel");if(!d)return h("Missing Destination Channel");if(!i)return h("Missing Publish Key");
+if(!g)return h("Missing Subscribe Key");"0"!=j&&(m.callback=j);e&&(m.stop="all");p&&(m.reverse="true");f&&(m.start=f);n&&(m.end=n);a&&(m.count=a);v({a:j,c:function(a){b(a)},b:function(){b([0,"Disconnected"])},url:[B,"v1","replay",i,g,c,d],data:m})},time:function(a){var b=y();v({a:b,timeout:5*A,url:[B,"time",b],c:function(b){a(b[0])},b:function(){a(0)}})},publish:function(a,b){var b=b||a.callback||l(),c=a.message,d=a.channel,e=y();if(!c)return h("Missing Message");if(!d)return h("Missing Channel");
+if(!i)return h("Missing Publish Key");if(!g)return h("Missing Subscribe Key");c=JSON.stringify(c);d=[B,"publish",i,g,0,O(d),e,O(c)];s.push({a:e,timeout:5*A,url:d,data:{uuid:G},c:function(a){b(a);t(1)},b:function(){b([0,"Failed",c]);t(1)}});t()},unsubscribe:function(a){a=a.channel;I=0;R=1;a=N((a.join?a.join(","):""+a).split(","),function(a){return a+","+a+z}).join(",");M(a.split(","),function(a){r&&n.LEAVE(a,0);p[a]=0});r&&c()},subscribe:function(a,b){function d(a){a?setTimeout(e,A):(B=J(E,1),Z=J(E,
+1),setTimeout(function(){n.time(d)},A));f(function(b){if(a&&b.d)return b.d=0,b.l(b.name);!a&&!b.d&&(b.d=1,b.k(b.name))})}function e(){var a=y(),b=P(p).join(",");b&&(x=v({timeout:C,a:a,b:function(){n.time(d)},data:{uuid:G},url:[Z,"subscribe",g,O(b),a,I],c:function(a){if(!a)return setTimeout(e,ca);f(function(a){a.f||(a.f=1,a.j(a.name))});I=!I&&R&&F.get(g)||a[1];s&&(Timetoken=1E4,s=0);F.set(g,a[1]);var b,c=(2<a.length?a[2]:"").split(",");b=function(){var a=c.shift()||"";return[(p[a]||{}).a||$,(a||aa).split(z)[0]]};
+M(a[0],function(c){var d=b();if(p[d[1]].g)d[0](c,a,d[1])});setTimeout(e,ca)}}))}var q=a.channel,b=(b=b||a.callback)||a.message,i=a.connect||l(),t=a.reconnect||l(),u=a.disconnect||l(),j=a.presence||0,m=a.noheresync||0,s=a.backfill||0,C=a.timeout||Q,ca=a.windowing||D;a.restore&&(R=1);I=0;if(!q)return h("Missing Channel");if(!b)return h("Missing Callback");if(!g)return h("Missing Subscribe Key");M((q.join?q.join(","):""+q).split(","),function(a){var c=p[a]||{};p[aa=a]={name:a,f:c.f,d:c.d,g:1,a:$=b,j:i,
+k:u,l:t};j&&(n.subscribe({channel:a+z,callback:j}),!c.g&&!m&&n.here_now({channel:a,callback:function(b){M("uuids"in b?b.uuids:[],function(c){j({action:"join",uuid:c,timestamp:H(),occupancy:b.occupancy||1},b,a)})}}))});c=function(){x&&x(1);clearTimeout(ba);ba=setTimeout(e,100)};if(!r)return w.push(c);c()},here_now:function(a,b){var b=a.callback||b,c=a.error||l(),d=a.channel,e=y(),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);v({a:e,data:f,c:function(a){b(a)},b:c,url:[B,"v2","presence","sub_key",g,"channel",O(d)]})},xdr:v,ready:ja,db:F,uuid:L,each:M,map:N,grep:ha,supplant:ia,now:H,unique:fa,updater:ga};G||(G=n.uuid());F.set(g+"uuid",G);setTimeout(d,A);setTimeout(b,C);e=n;e.init=V;e.$=na;e.attr=ma;e.search=oa;e.bind=U;e.css=pa;e.create=qa;if(a.notest)return e;U("beforeunload",window,function(){each_channel(function(a){e.LEAVE(a.name,1)});return!0});U("offline",window,e._reset_offline);U("offline",
+document,e._reset_offline);e.ready();return e}var ka=O("PubNub-JS-Phonegap/3.4.4"),T=31E4,W,X="undefined"!=typeof localStorage&&localStorage;W={get:function(a){try{return X?X.getItem(a):-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}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){}}};
+"undefined"!==typeof module&&(module.o=V)||"undefined"!==typeof exports&&(exports.m=V)||(PUBNUB=V);
+var Y=PUBNUB.ws=function(a,c){if(!(this instanceof Y))return new Y(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=l();
+b.binaryType="";b.extensions="";b.bufferedAmount=0;b.trasnmitting=k;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:k,channel:d.channel,disconnect:b.onerror,reconnect:b.onopen,error:function(){b.onclose({code:b.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:k})},callback:function(a){b.onmessage({data:a})},connect:function(){b.readyState=b.OPEN;b.onopen()}})};
+Y.prototype.send=function(a){var c=this;c.e.publish({channel:c.e.i.channel,message:a,callback:function(a){c.onsend({data:a})}})};
+})();
View
34 sencha/Makefile
@@ -0,0 +1,34 @@
+include ../Makefile.inc
+OUTPUT_FILES=$(PUBNUB_MIN_JS) $(PUBNUB_CRYPTO_MIN_JS)
+PLATFORM=Sencha
+MODERN_PLATFORM_JS=../modern/$(PUBNUB_PLATFORM_JS)
+
+.PHONY : all
+all: build
+
+.PHONY : build
+build: $(PUBNUB_MIN_JS) $(PUBNUB_CRYPTO_MIN_JS)
+
+$(PUBNUB_MIN_JS) : $(PUBNUB_COMMON_JS) $(WEBSOCKET_JS) $(MODERN_PLATFORM_JS)
+ ## Full Version
+ $(ECHO) "// Version: $(VERSION)" > $(PUBNUB_JS)
+ cat $(PUBNUB_COMMON_JS) $(MODERN_PLATFORM_JS) $(WEBSOCKET_JS) >> $(PUBNUB_JS)
+ sed -i -e "s/VERSION/\'$(VERSION)\'/g" $(PUBNUB_JS)
+ sed -i -e "s/PLATFORM/\'$(PLATFORM)\'/g" $(PUBNUB_JS)
+ ## Minfied Version
+ $(ECHO) "// Version: $(VERSION)" > $(PUBNUB_MIN_JS)
+ $(ECHO) "(function(){" >> $(PUBNUB_MIN_JS)
+ cat $(PUBNUB_JS) | java -jar $(GOOGLE_MINIFY) --compilation_level=ADVANCED_OPTIMIZATIONS >> $(PUBNUB_MIN_JS)
+ $(ECHO) "})();" >> $(PUBNUB_MIN_JS)
+
+$(PUBNUB_CRYPTO_MIN_JS) : $(GIBBERISH_JS) $(ENCRYPTO_JS)
+ ## Cryptography
+ $(ECHO) "(function(){" > $(PUBNUB_CRYPTO_MIN_JS)
+ cat $(GIBBERISH_JS) $(ENCRYPT_JS) | java -jar $(GOOGLE_MINIFY) >> $(PUBNUB_CRYPTO_MIN_JS)
+ $(ECHO) "})();" >> $(PUBNUB_CRYPTO_MIN_JS)
+
+.PHONY : clean
+clean:
+ rm -f $(OUTPUT_FILES)
+
+include ../Makefile.post
View
2  sencha/examples/here_now/index.html
@@ -52,7 +52,7 @@
<!-- The line below must be kept intact for Sencha Command to build your application -->
<link href=sencha-touch.css rel="stylesheet" type="text/css" />
<script src=sencha-touch-all.js type="text/javascript"></script>
- <script src=../../../modern/pubnub.min.js type="text/javascript"></script>
+ <script src=../../pubnub.min.js type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
View
2  sencha/examples/history/index.html
@@ -52,7 +52,7 @@
<!-- The line below must be kept intact for Sencha Command to build your application -->
<link href=sencha-touch.css rel="stylesheet" type="text/css" />
<script src=sencha-touch-all.js type="text/javascript"></script>
- <script src=../../../modern/pubnub.min.js type="text/javascript"></script>
+ <script src=../../pubnub.min.js type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
View
2  sencha/examples/subscribe/index.html
@@ -52,7 +52,7 @@
<!-- The line below must be kept intact for Sencha Command to build your application -->
<link href=sencha-touch.css rel="stylesheet" type="text/css" />
<script src=sencha-touch-all.js type="text/javascript"></script>
- <script src=../../../modern/pubnub.min.js type="text/javascript"></script>
+ <script src=../../pubnub.min.js type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
View
25 sencha/pubnub-crypto.min.js
@@ -0,0 +1,25 @@
+(function(){
+PUBNUB.crypto=function(){var e=14,j=8,s=!1,v=function(b,f){var c="",d,q;if(f){d=b[15];if(16<d)throw"Decryption error: Maybe bad key";if(16==d)return"";for(q=0;q<16-d;q++)c+=String.fromCharCode(b[q])}else for(q=0;16>q;q++)c+=String.fromCharCode(b[q]);return c},u=function(b,f){var c=[],d;if(!f)try{b=unescape(encodeURIComponent(b))}catch(q){throw"Error on UTF-8 encode";}for(d=0;d<b.length;d++)c[d]=b.charCodeAt(d);return c},p=function(b,f){var c=12<=e?3:2,d=[],q=[],d=[],q=[],T=b.concat(f),A;d[0]=GibberishAES.Hash.MD5(T);
+q=d[0];for(A=1;A<c;A++)d[A]=GibberishAES.Hash.MD5(d[A-1].concat(T)),q=q.concat(d[A]);d=q.slice(0,4*j);q=q.slice(4*j,4*j+16);return{key:d,iv:q}},r=function(b,f,c){var f=x(f),d=Math.ceil(b.length/16),q=[],e,A=[];for(e=0;e<d;e++){var m=q,p=e,j=b.slice(16*e,16*e+16),r=[],t=void 0,t=void 0;16>j.length&&(t=16-j.length,r=[t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t]);for(t=0;t<j.length;t++)r[t]=j[t];m[p]=r}0===b.length%16&&q.push([16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]);for(e=0;e<q.length;e++)q[e]=0===e?B(q[e],
+c):B(q[e],A[e-1]),A[e]=z(q[e],f);return A},w=function(b,f,c,d){var f=x(f),q=b.length/16,e=[],j,m=[],p="";for(j=0;j<q;j++)e.push(b.slice(16*j,16*(j+1)));for(j=e.length-1;0<=j;j--)m[j]=D(e[j],f),m[j]=0===j?B(m[j],c):B(m[j],e[j-1]);for(j=0;j<q-1;j++)p+=v(m[j]);var p=p+v(m[j],!0),r;if(d)r=p;else try{r=decodeURIComponent(escape(p))}catch(s){throw"Bad Key";}return r},z=function(b,f){s=!1;var c=C(b,f,0),d;for(d=1;d<e+1;d++)c=y(c),c=E(c),d<e&&(c=F(c)),c=C(c,f,d);return c},D=function(b,f){s=!0;var c=C(b,f,
+e),d;for(d=e-1;-1<d;d--)c=E(c),c=y(c),c=C(c,f,d),0<d&&(c=F(c));return c},y=function(b){var f=s?U:S,c=[],d;for(d=0;16>d;d++)c[d]=f[b[d]];return c},E=function(b){var f=[],c=s?[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],d;for(d=0;16>d;d++)f[d]=b[c[d]];return f},F=function(b){var f=[],c;if(s)for(c=0;4>c;c++)f[4*c]=L[b[4*c]]^M[b[1+4*c]]^N[b[2+4*c]]^O[b[3+4*c]],f[1+4*c]=O[b[4*c]]^L[b[1+4*c]]^M[b[2+4*c]]^N[b[3+4*c]],f[2+4*c]=N[b[4*c]]^O[b[1+4*c]]^L[b[2+4*c]]^M[b[3+4*c]],
+f[3+4*c]=M[b[4*c]]^N[b[1+4*c]]^O[b[2+4*c]]^L[b[3+4*c]];else for(c=0;4>c;c++)f[4*c]=P[b[4*c]]^Q[b[1+4*c]]^b[2+4*c]^b[3+4*c],f[1+4*c]=b[4*c]^P[b[1+4*c]]^Q[b[2+4*c]]^b[3+4*c],f[2+4*c]=b[4*c]^b[1+4*c]^P[b[2+4*c]]^Q[b[3+4*c]],f[3+4*c]=Q[b[4*c]]^b[1+4*c]^b[2+4*c]^P[b[3+4*c]];return f},C=function(b,f,c){var d=[],q;for(q=0;16>q;q++)d[q]=b[q]^f[c][q];return d},B=function(b,f){var c=[],d;for(d=0;16>d;d++)c[d]=b[d]^f[d];return c},x=function(b){var f=[],c=[],d,q,p=[];for(d=0;d<j;d++)q=[b[4*d],b[4*d+1],b[4*d+
+2],b[4*d+3]],f[d]=q;for(d=j;d<4*(e+1);d++){f[d]=[];for(b=0;4>b;b++)c[b]=f[d-1][b];if(0===d%j){b=c[0];q=void 0;for(q=0;4>q;q++)c[q]=c[q+1];c[3]=b;c=G(c);c[0]^=X[d/j-1]}else 6<j&&4==d%j&&(c=G(c));for(b=0;4>b;b++)f[d][b]=f[d-j][b]^c[b]}for(d=0;d<e+1;d++){p[d]=[];for(c=0;4>c;c++)p[d].push(f[4*d+c][0],f[4*d+c][1],f[4*d+c][2],f[4*d+c][3])}return p},G=function(b){for(var f=0;4>f;f++)b[f]=S[b[f]];return b},H=function(b,f){var c=[];for(i=0;i<b.length;i+=f)c[i/f]=parseInt(b.substr(i,f),16);return c},I=function(b){for(var f=
+[],c=0;256>c;c++){for(var d=f,q=c,e=b,j=c,m=void 0,p=void 0,m=p=0;8>m;m++)p=1==(j&1)?p^e:p,e=127<e?283^e<<1:e<<1,j>>>=1;d[q]=p}return f},S=H("637c777bf26b6fc53001672bfed7ab76ca82c97dfa5947f0add4a2af9ca472c0b7fd9326363ff7cc34a5e5f171d8311504c723c31896059a071280e2eb27b27509832c1a1b6e5aa0523bd6b329e32f8453d100ed20fcb15b6acbbe394a4c58cfd0efaafb434d338545f9027f503c9fa851a3408f929d38f5bcb6da2110fff3d2cd0c13ec5f974417c4a77e3d645d197360814fdc222a908846eeb814de5e0bdbe0323a0a4906245cc2d3ac629195e479e7c8376d8dd54ea96c56f4ea657aae08ba78252e1ca6b4c6e8dd741f4bbd8b8a703eb5664803f60e613557b986c11d9ee1f8981169d98e949b1e87e9ce5528df8ca1890dbfe6426841992d0fb054bb16",
+2),U,V=S,W=[];for(i=0;i<V.length;i++)W[V[i]]=i;U=W;var X=H("01020408102040801b366cd8ab4d9a2f5ebc63c697356ad4b37dfaefc591",2),P=I(2),Q=I(3),O=I(9),M=I(11),N=I(13),L=I(14),R,J="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",K=J.split("");"function"===typeof Array.indexOf&&(J=K);R={encode:function(b){var f=[],c="",d;totalChunks=Math.floor(16*b.length/3);for(d=0;d<16*b.length;d++)f.push(b[Math.floor(d/16)][d%16]);for(d=0;d<f.length;d+=3)c+=K[f[d]>>2],c+=K[(f[d]&3)<<4|f[d+1]>>4],c=void 0!==
+f[d+1]?c+K[(f[d+1]&15)<<2|f[d+2]>>6]:c+"=",c=void 0!==f[d+2]?c+K[f[d+2]&63]:c+"=";b=c.slice(0,64);for(d=1;d<Math.ceil(c.length/64);d++)b+=c.slice(64*d,64*d+64)+(Math.ceil(c.length/64)==d+1?"":"\n");return b},decode:function(b){var b=b.replace(/\n/g,""),f=[],c=[],d=[],e;for(e=0;e<b.length;e+=4)c[0]=J.indexOf(b.charAt(e)),c[1]=J.indexOf(b.charAt(e+1)),c[2]=J.indexOf(b.charAt(e+2)),c[3]=J.indexOf(b.charAt(e+3)),d[0]=c[0]<<2|c[1]>>4,d[1]=(c[1]&15)<<4|c[2]>>2,d[2]=(c[2]&3)<<6|c[3],f.push(d[0],d[1],d[2]);
+return f=f.slice(0,f.length-f.length%16)}};return{size:function(b){switch(b){case 128:e=10;j=4;break;case 192:e=12;j=6;break;case 256:e=14;j=8;break;default:throw"Invalid Key Size Specified:"+b;}},h2a:function(b){var f=[];b.replace(/(..)/g,function(b){f.push(parseInt(b,16))});return f},expandKey:x,encryptBlock:z,decryptBlock:D,Decrypt:s,s2a:u,rawEncrypt:r,rawDecrypt:w,dec:function(b,f,c){var b=R.decode(b),d=b.slice(8,16),d=p(u(f,c),d),f=d.key,d=d.iv,b=b.slice(16,b.length);return b=w(b,f,d,c)},openSSLKey:p,
+a2h:function(b){var f="",c;for(c=0;c<b.length;c++)f+=(16>b[c]?"0":"")+b[c].toString(16);return f},enc:function(b,f,c){var d;d=[];var e;for(e=0;8>e;e++)d=d.concat(Math.floor(256*Math.random()));e=p(u(f,c),d);f=e.key;e=e.iv;d=[[83,97,108,116,101,100,95,95].concat(d)];b=u(b,c);b=r(b,f,e);b=d.concat(b);return R.encode(b)},Hash:{MD5:function(b){function f(b,c){var d,e,f,g,h;f=b&2147483648;g=c&2147483648;d=b&1073741824;e=c&1073741824;h=(b&1073741823)+(c&1073741823);return d&e?h^2147483648^f^g:d|e?h&1073741824?
+h^3221225472^f^g:h^1073741824^f^g:h^f^g}function c(b,c,d,e,g,h,k){b=f(b,f(f(c&d|~c&e,g),k));return f(b<<h|b>>>32-h,c)}function d(b,c,d,e,g,h,k){b=f(b,f(f(c&e|d&~e,g),k));return f(b<<h|b>>>32-h,c)}function e(b,c,d,g,h,k,l){b=f(b,f(f(c^d^g,h),l));return f(b<<k|b>>>32-k,c)}function j(b,c,d,e,g,h,k){b=f(b,f(f(d^(c|~e),g),k));return f(b<<h|b>>>32-h,c)}function p(b){var c,d,e=[];for(d=0;3>=d;d++)c=b>>>8*d&255,e=e.concat(c);return e}var m=[],r,s,w,t,g,h,k,l,n=H("67452301efcdab8998badcfe10325476d76aa478e8c7b756242070dbc1bdceeef57c0faf4787c62aa8304613fd469501698098d88b44f7afffff5bb1895cd7be6b901122fd987193a679438e49b40821f61e2562c040b340265e5a51e9b6c7aad62f105d02441453d8a1e681e7d3fbc821e1cde6c33707d6f4d50d87455a14eda9e3e905fcefa3f8676f02d98d2a4c8afffa39428771f6816d9d6122fde5380ca4beea444bdecfa9f6bb4b60bebfbc70289b7ec6eaa127fad4ef308504881d05d9d4d039e6db99e51fa27cf8c4ac5665f4292244432aff97ab9423a7fc93a039655b59c38f0ccc92ffeff47d85845dd16fa87e4ffe2ce6e0a30143144e0811a1f7537e82bd3af2352ad7d2bbeb86d391",
+8),m=b.length;r=m+8;s=16*