Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'CL-225'

  • Loading branch information...
commit 0466f6a3fbb5def1e8803c9c2021265ffab8ab38 2 parents 0594448 + e9d5a47
geremy cohen authored
View
0  javascript-modern/README.md → javascript-modern/3.1/README.md
File renamed without changes
View
0  javascript-modern/pubnub-3.1.js → javascript-modern/3.1/pubnub-3.1.js
File renamed without changes
View
0  javascript-modern/pubnub-3.1.min.js → javascript-modern/3.1/pubnub-3.1.min.js
File renamed without changes
View
0  javascript-modern/pubnub-3.1.min.js.gz → javascript-modern/3.1/pubnub-3.1.min.js.gz
File renamed without changes
View
0  javascript-modern/tests/example.html → javascript-modern/3.1/tests/example.html
File renamed without changes
View
0  javascript-modern/tests/test.js → javascript-modern/3.1/tests/test.js
File renamed without changes
View
0  javascript-modern/tests/test.sh → javascript-modern/3.1/tests/test.sh
File renamed without changes
View
0  javascript-modern/tests/unit-test.html → javascript-modern/3.1/tests/unit-test.html
File renamed without changes
View
0  javascript-modern/tests/webworker.html → javascript-modern/3.1/tests/webworker.html
File renamed without changes
View
0  javascript-modern/tests/webworker.js → javascript-modern/3.1/tests/webworker.js
File renamed without changes
View
59 javascript-modern/3.3/README.md
@@ -0,0 +1,59 @@
+# PubNub HTML5 Modern JavaScript Library
+
+For a faster PubNub load, use the PubNub HTML5 Modern JavaScript
+Library which is `CommonJS` and HTML5 `WebWorker` Ready.
+
+#### Supported Browsers:
+
+ - firefox/3.6'
+ - firefox/9.0'
+ - firefox/10.0'
+ - chrome/16.0'
+ - chrome/17.0'
+ - iexplore/9.0'
+ - safari/5.1'
+
+```html
+<script src=pubnub-3.3.js></script>
+<script>(function(){
+ // ----------------------------------
+ // INIT PUBNUB
+ // ----------------------------------
+ var pubnub = PUBNUB({
+ publish_key : 'PUBLISH_KEY_HERE',
+ subscribe_key : 'SUBSCRIBE_KEY_HERE',
+ ssl : false,
+ origin : 'pubsub.pubnub.com'
+ });
+
+ // ----------------------------------
+ // LISTEN FOR MESSAGES
+ // ----------------------------------
+ pubnub.subscribe({
+ restore : true,
+ connect : send_hello,
+ channel : 'my_channel',
+ callback : function(message) {
+ console.log(JSON.stringify(message));
+ },
+ disconnect : function() {
+ console.log("Connection Lost");
+ }
+ });
+
+ // ----------------------------------
+ // SEND MESSAGE
+ // ----------------------------------
+ function send_hello() {
+ pubnub.publish({
+ channel : 'my_channel',
+ message : { example : "Hello World!" },
+ callback : function(info) {
+ console.log(JSON.stringify(info));
+ }
+ });
+ }
+})();</script>
+
+```
+
View
406 javascript-modern/3.3/pubnub-3.3-common.js
@@ -0,0 +1,406 @@
+
+/**
+ * NEXTORIGIN
+ * ==========
+ * var next_origin = nextorigin();
+ */
+var nextorigin = (function() {
+ var ori = Math.floor(Math.random() * 9) + 1;
+ return function(origin) {
+ return origin.indexOf('pubsub') > 0
+ && origin.replace(
+ 'pubsub', 'ps' + (++ori < 10 ? ori : ori=1)
+ ) || origin;
+ }
+})();
+
+/**
+ * EACH
+ * ====
+ * each( [1,2,3], function(item) { console.log(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;
+}
+
+/**
+ * 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
+}
+
+/**
+ * timeout
+ * =======
+ * timeout( function(){}, 100 );
+ */
+function timeout( fun, wait ) {
+ return setTimeout( fun, wait );
+}
+
+/**
+ * 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('');
+}
+
+
+function PN_API(setup) {
+ var CHANNELS = {}
+ , PUBLISH_KEY = setup['publish_key'] || ''
+ , SUBSCRIBE_KEY = setup['subscribe_key'] || ''
+ , ORIGIN = setup['origin'] || 'pubsub.pubnub.com'
+ , db = setup['db'] || {'set' : function(){}, 'get': function(){}}
+ , jsonp_cb = setup['jsonp_cb'] || function(){}
+ , UUID = setup['uuid'] || db.get(SUBSCRIBE_KEY+'uuid') || ''
+ , xdr = setup['xdr']
+ , ssl = setup['ssl']
+ , timeout_sec = setup['timeout'] || 1000
+ , log = setup['log'] || function(){}
+
+
+
+ SELF = {
+ /*
+ PUBNUB.history({
+ channel : 'my_chat_channel',
+ limit : 100,
+ callback : function(messages) { console.log(messages) }
+ });
+ */
+ 'history' : function( args, callback ) {
+ var callback = args['callback'] || callback
+ , limit = args['limit'] || 100
+ , channel = args['channel'];
+
+ // Make sure we have a Channel
+ if (!channel) return log('Missing Channel');
+ if (!callback) return log('Missing Callback');
+
+ // Send Message
+ xdr({
+ ssl : ssl,
+ origin : ORIGIN,
+ url : [
+ 'history', SUBSCRIBE_KEY, encode(channel),
+ 0, limit
+ ],
+ success : function(response) { callback(response) },
+ fail : function(response) { callback(response) }
+ });
+ },
+ /*
+ PUBNUB.detailedHistory({
+ channel : 'my_chat_channel',
+ count : 100,
+ callback : function(messages) { console.log(messages) }
+ });
+ */
+ 'detailedHistory' : function( args, callback ) {
+ var callback = args['callback'] || callback
+ , count = args['count'] || 100
+ , channel = args['channel']
+ , reverse = args['reverse'] || "false"
+ , start = args['start']
+ , end = args['end']
+ , jsonp = jsonp_cb();
+
+ // Make sure we have a Channel
+ if (!channel) return log('Missing Channel');
+ if (!callback) return log('Missing Callback');
+
+ var params = {};
+ params["count"] = count;
+ params["reverse"] = reverse;
+ if (start) params["start"] = start;
+ if (end) params["end"] = end;
+
+ // Send Message
+ xdr({
+ callback : jsonp,
+ ssl : ssl,
+ origin : ORIGIN,
+ url : [
+ 'v2', 'history',
+ 'sub-key', SUBSCRIBE_KEY, 'channel', encode(channel)
+ ],
+ data : params,
+ success : function(response) { callback(response) },
+ fail : function(response) { log(response) }
+ });
+ },
+
+ /*
+ PUBNUB.time(function(time){ console.log(time) });
+ */
+ 'time' : function(callback) {
+ xdr({
+ ssl : ssl,
+ origin : ORIGIN,
+ url : ['time', 0],
+ success : function(response) { callback(response[0]) },
+ fail : function() { callback(0) }
+ });
+ },
+
+ /*
+ PUBNUB.uuid(function(uuid) { console.log(uuid) });
+ */
+ 'uuid' : function(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;
+ },
+
+ /*
+ PUBNUB.publish({
+ channel : 'my_chat_channel',
+ message : 'hello!'
+ });
+ */
+ 'publish' : function( args, callback ) {
+ var callback = callback || args['callback'] || function(){}
+ , message = args['message']
+ , channel = args['channel']
+ , url;
+
+ if (!message) return log('Missing Message');
+ if (!channel) return log('Missing Channel');
+ if (!PUBLISH_KEY) return log('Missing Publish Key');
+
+ // If trying to send Object
+ message = JSON['stringify'](message);
+
+ // Create URL
+ url = [
+ 'publish',
+ PUBLISH_KEY, SUBSCRIBE_KEY,
+ 0, encode(channel),
+ 0, encode(message)
+ ];
+
+ // Send Message
+ xdr({
+ success : function(response) { callback(response) },
+ fail : function() { callback([ 0, 'Disconnected' ]) },
+ ssl : ssl,
+ origin : ORIGIN,
+ url : url
+ });
+ },
+
+ /*
+ PUBNUB.unsubscribe({ channel : 'my_chat' });
+ */
+ 'unsubscribe' : function(args) {
+ var channel = args['channel'];
+
+ // Leave if there never was a channel.
+ if (!(channel in CHANNELS)) return;
+
+ // Disable Channel
+ CHANNELS[channel].connected = 0;
+
+ // Abort and Remove Script
+ CHANNELS[channel].done &&
+ CHANNELS[channel].done(0);
+
+ },
+ 'here_now' : function( args, callback ) {
+ var callback = args['callback'] || callback
+ , channel = args['channel']
+ , jsonp = jsonp_cb()
+ , origin = nextorigin(ORIGIN);
+
+ // Make sure we have a Channel
+ if (!channel) return log('Missing Channel');
+ if (!callback) return log('Missing Callback');
+
+ data = null;
+ if (jsonp != '0') { data['callback']=jsonp; }
+
+ // Send Message
+ xdr({
+ callback : jsonp,
+ ssl : ssl,
+ origin : origin,
+ url : [
+ 'v2', 'presence',
+ 'sub_key', SUBSCRIBE_KEY,
+ 'channel', encode(channel)
+ ],
+ data: data,
+ success : function(response) { callback(response) },
+ fail : function(response) { log(response) }
+ });
+ },
+ 'subscribe' : function( args, callback ) {
+ var channel = args['channel']
+ , callback = callback || args['callback']
+ , subscribe_key= args['subscribe_key'] || SUBSCRIBE_KEY
+ , restore = args['restore']
+ , timetoken = 0
+ , error = args['error'] || function(){}
+ , connect = args['connect'] || function(){}
+ , reconnect = args['reconnect'] || function(){}
+ , disconnect = args['disconnect'] || function(){}
+ , presence = args['presence'] || function(){}
+ , disconnected = 0
+ , connected = 0
+ , origin = nextorigin(ORIGIN);
+
+ // Make sure we have a Channel
+ if (!channel) return log('Missing Channel');
+ if (!callback) return log('Missing Callback');
+ if (!SUBSCRIBE_KEY) return log('Missing Subscribe Key');
+
+ if (!(channel in CHANNELS)) CHANNELS[channel] = {};
+
+ // Make sure we have a Channel
+ if (CHANNELS[channel].connected) return log('Already Connected');
+ CHANNELS[channel].connected = 1;
+
+ // Recurse Subscribe
+ function _connect() {
+ var jsonp = jsonp_cb();
+
+ // Stop Connection
+ if (!CHANNELS[channel].connected) return;
+ // Connect to PubNub Subscribe Servers
+ CHANNELS[channel].done = xdr({
+ callback : jsonp,
+ ssl : ssl,
+ origin : origin,
+ url : [
+ 'subscribe',
+ subscribe_key, encode(channel),
+ jsonp, timetoken
+ ],
+ data : { uuid: UUID },
+ fail : function() {
+ // Disconnect
+ if (!disconnected) {
+ disconnected = 1;
+ disconnect();
+ }
+ timeout( _connect, timeout_sec);
+ SELF['time'](function(success){
+ // Reconnect
+ if (success && disconnected) {
+ disconnected = 0;
+ reconnect();
+ }
+ else {
+ error();
+ }
+ });
+ },
+ success : function(messages) {
+ if (!CHANNELS[channel].connected) return;
+
+ // Connect
+ if (!connected) {
+ connected = 1;
+ connect();
+ }
+
+ // Reconnect
+ if (disconnected) {
+ disconnected = 0;
+ reconnect();
+ }
+
+ // Restore Previous Connection Point if Needed
+ // Also Update Timetoken
+ restore = db.set(
+ SUBSCRIBE_KEY + channel,
+ timetoken = restore && db.get(
+ subscribe_key + channel
+ ) || messages[1]
+ );
+ each( messages[0], function(msg) {
+ callback( msg, messages );
+ } );
+
+ timeout( _connect, 10 );
+ }
+ });
+ }
+
+ // Presence Subscribe
+ if (args['presence']) SELF.subscribe({
+ channel : args['channel'] + PRESENCE_SUFFIX,
+ callback : presence,
+ restore : args['restore']
+ });
+
+ // Begin Recursive Subscribe
+ _connect();
+ },
+ /*
+ *PUBNUB.time(function(time){ console.log(time) });
+ */
+ 'time' : function(callback) {
+ var jsonp = jsonp_cb();
+ xdr({
+ callback : jsonp,
+ origin : ORIGIN,
+ url : ['time', jsonp],
+ success : function(response) { callback(response[0]) },
+ fail : function() { callback(0) }
+ });
+ },
+ /*
+ *PUBNUB.presence({
+ * channel : 'my_chat'
+ * callback : function(message) { console.log(message) }
+ *});
+ */
+ 'presence' : function( args, callback ) {
+ args['channel'] = args['channel'] + '-pnpres';
+ SELF.subscribe(args,callback );
+ },
+ };
+
+ if(!xdr) return log('Missing xdr function');
+
+
+ if (UUID == '') UUID = SELF.uuid();
+ db.set(SUBSCRIBE_KEY+'uuid', UUID);
+
+ return SELF;
+};
View
206 javascript-modern/3.3/pubnub-3.3.js
@@ -0,0 +1,206 @@
+/* ---------------------------------------------------------------------------
+--------------------------------------------------------------------------- */
+
+/* ---------------------------------------------------------------------------
+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
+, URLBIT = '/'
+, PARAMSBIT = '&'
+, XHRTME = 310000;
+
+/**
+ * UTILITIES
+ */
+function unique() { return'x'+ ++NOW+''+(+new Date) }
+function rnow() { return+new Date }
+
+/**
+ * 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 )
+ , 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;
+ url = 'http' + ((setup.ssl)?'s':'') + '://' + setup.origin + URLBIT + 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);
+ }
+ xhr.open( 'GET', url, true );
+ xhr.send();
+ }
+ catch(eee) {
+ done(0);
+ return xdr(setup);
+ }
+
+ // Return 'done'
+ return done;
+}
+
+
+
+/**
+ * LOG
+ * ===
+ * var list = grep( [1,2,3], function(item) { return item % 2 } )
+ */
+var log = function(){};
+
+/**
+ * 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) }
+ );
+ }
+};
+
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+/* =-========================= PUBNUB ===========================-= */
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+
+function PN(setup) {
+ var SELF = {
+ // Expose PUBNUB Functions
+ 'xdr' : xdr,
+ 'db' : db,
+ 'each' : each,
+ 'map' : map,
+ 'events' : events
+ };
+ setup['db'] = db;
+ setup['xdr'] = xdr;
+ setup['log'] = function(message) { console.log(message);};
+ setup['jsonp_cb'] = function(){ return '0'};
+ SELF.__proto__ = PN_API(setup);
+
+ return SELF;
+}
+
+typeof module !== 'undefined' && (module.exports = PN) ||
+typeof exports !== 'undefined' && (exports.PN = PN) || (PUBNUB = PN);
+
+})();
View
7 javascript-modern/3.3/pubnub-3.3.min.js
@@ -0,0 +1,7 @@
+(function(){function p(b,a){if(b&&a)if(typeof b[0]!="undefined")for(var e=0,g=b.length;e<g;)a.call(b[e],b[e],e++);else for(e in b)b.hasOwnProperty&&b.hasOwnProperty(e)&&a.call(b[e],e,b[e])}function u(b,a){var e=[];p(b||[],function(g,j){e.push(a(g,j))});return e}function q(b){return u(encodeURIComponent(b).split(""),function(a){return"-_.!~*'()".indexOf(a)<0?a:"%"+a.charCodeAt(0).toString(16).toUpperCase()}).join("")}function k(b){var a,e=function(){if(!j){j=1;clearTimeout(l);try{response=JSON.parse(a.responseText)}catch(f){return d(1)}c(response)}},
+g=0,j=0,l=setTimeout(function(){d(1)},v),r=b.fail||function(){},c=b.success||function(){},d=function(f){if(!g){g=1;clearTimeout(l);if(a){a.onerror=a.onload=null;a.abort&&a.abort();a=null}f&&r()}};try{a=typeof XDomainRequest!=="undefined"&&new XDomainRequest||new XMLHttpRequest;a.onerror=a.onabort=function(){d(1)};a.onload=a.onloadend=e;a.timeout=v;a.open("GET",b.url.join(z),true);a.send()}catch(h){d(0);return k(b)}return d}function s(b){var a={},e=b.publish_key||"",g=b.subscribe_key||"",j=b.ssl?"s":
+"",l="http"+j+"://"+(b.origin||"pubsub.pubnub.com"),r={history:function(c,d){d=c.callback||d;var h=c.limit||100,f=c.channel;f&&d&&k({url:[l,"history",g,q(f),0,h],success:function(i){d(i)},fail:function(i){d(i)}})},time:function(c){k({url:[l,"time",0],success:function(d){c(d[0])},fail:function(){c(0)}})},uuid:function(c){k({url:["http"+j+"://pubnub-prod.appspot.com/uuid"],success:function(d){c(d[0])},fail:function(){c(0)}})},publish:function(c,d){d=d||c.callback||function(){};var h=c.message,f=c.channel;
+if(h)if(f)if(e){h=JSON.stringify(h);h=[l,"publish",e,g,0,q(f),0,q(h)];k({success:function(i){d(i)},fail:function(){d([0,"Disconnected"])},url:h})}},unsubscribe:function(c){c=c.channel;if(c in a){a[c].connected=0;a[c].done&&a[c].done(0)}},subscribe:function(c,d){function h(){if(a[f].connected)a[f].done=k({callback:0,url:[A,"subscribe",g,q(f),0,w],fail:function(){if(!m){m=1;B()}setTimeout(h,1E3);r.time(function(n){if(n&&m){m=0;x()}n||C()})},success:function(n){if(a[f].connected){if(!y){y=1;D()}if(m){m=
+0;x()}i=t.set(g+f,w=i&&t.get(g+f)||n[1]);p(n[0],function(E){d(E,n)});setTimeout(h,10)}}})}var f=c.channel;d=d||c.callback;var i=c.restore,w=0,C=c.error||function(){},D=c.connect||function(){},x=c.reconnect||function(){},B=c.disconnect||function(){},m=0,y=0,A=F(l);if(f)if(d)if(g){f in a||(a[f]={});if(!a[f].connected){a[f].connected=1;h()}}},xdr:k,db:t,each:p,map:u,events:o};return r}var t=function(){var b=typeof localStorage!="undefined"&&localStorage;return{get:function(a){try{if(b)return b.getItem(a);
+if(document.cookie.indexOf(a)==-1)return null;return((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null}catch(e){}},set:function(a,e){try{if(b)return b.setItem(a,e)&&0;document.cookie=a+"="+e+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"}catch(g){}}}}(),z="/",v=31E4,F=function(){var b=Math.floor(Math.random()*9)+1;return function(a){return a.indexOf("pubsub")>0&&a.replace("pubsub","ps"+(++b<10?b:b=1))||a}}(),o={list:{},unbind:function(b){o.list[b]=[]},bind:function(b,a){(o.list[b]=
+o.list[b]||[]).push(a)},fire:function(b,a){p(o.list[b]||[],function(e){e(a)})}};typeof module!=="undefined"&&(module.exports=s)||typeof exports!=="undefined"&&(exports.PN=s)||(PUBNUB=s)})();
View
BIN  javascript-modern/3.3/pubnub-3.3.min.js.gz
Binary file not shown
View
83 javascript-modern/3.3/tests/example.html
@@ -0,0 +1,83 @@
+<!doctype html>
+<html>
+<head>
+ <title>PubNub JavaScript CommonJS</title>
+ <link
+ rel=stylesheet
+ href=http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css
+ >
+</head>
+<body><div class=container>
+
+</div>
+<script src=../pubnub-3.3.js></script>
+<script>(function() {
+ // ----------------------------------------------
+ // INIT
+ // ----------------------------------------------
+ var channel = 'my_channel'
+ , pubnub = PUBNUB({
+ publish_key : 'demo',
+ subscribe_key : 'demo',
+ ssl : false,
+ origin : 'pubsub.pubnub.com'
+ });
+
+ // ----------------------------------------------
+ // Establish a Connection
+ // ----------------------------------------------
+ log('Opening a Connection.');
+ pubnub.subscribe({
+ channel : channel,
+ connect : ready,
+ callback : receive
+ });
+
+ // ----------------------------------------------
+ // Connection Is Open Now and Ready
+ // ----------------------------------------------
+ function ready() {
+ log('Connection Established.');
+ send('hello');
+ }
+
+ // ----------------------------------------------
+ // Received Message
+ // ----------------------------------------------
+ function receive(message) {
+ log('Received a Message.');
+ log(message);
+ log('Closing Connection');
+ pubnub.unsubscribe({ channel : channel });
+ }
+
+ // ----------------------------------------------
+ // Send a Message
+ // ----------------------------------------------
+ function send(message) {
+ log('Starting to Send a Message.');
+ pubnub.publish({
+ channel : channel,
+ message : message,
+ callback : send_complete
+ });
+ }
+
+ // ----------------------------------------------
+ // Send Request Finished with Status
+ // ----------------------------------------------
+ function send_complete(details) {
+ log('Message Sent Done.');
+ log(details);
+ }
+
+ // ----------------------------------------------
+ // Send Request Finished with Status
+ // ----------------------------------------------
+ function log(message) {
+ console.log(message);
+ }
+
+})();</script>
+</body>
+</html>
View
69 javascript-modern/3.3/tests/test.js
@@ -0,0 +1,69 @@
+var test = require('testling');
+var PUBNUB = require('./pubnub-3.3');
+var channel = 'unit-test-pubnub-channel';
+
+test('PUBNUB JavaScript API', function (test) {
+ var pubnub = PUBNUB({
+ publish_key : 'demo',
+ subscribe_key : 'demo'
+ });
+
+ test.plan(14);
+
+ test.ok(PUBNUB);
+
+ test.ok(pubnub);
+ test.ok(pubnub.publish);
+ test.ok(pubnub.subscribe);
+ test.ok(pubnub.history);
+ test.ok(pubnub.time);
+
+ function publish_test() {
+ pubnub.publish({
+ channel : channel,
+ message : { test : "test" },
+ callback : function(response) {
+ test.ok(response[0]);
+ test.equal( response[1], 'Demo' );
+ }
+ });
+ }
+
+ function time_test() {
+ pubnub.time(function(time){
+ test.ok(time);
+ uuid_test();
+ });
+ }
+
+ function uuid_test() {
+ pubnub.uuid(function(uuid){
+ test.ok(uuid);
+ history_test();
+ });
+ }
+
+ function history_test(history) {
+ pubnub.history({
+ limit : 1,
+ channel : channel,
+ callback : function(messages) {
+ test.ok(messages);
+ test.equal( messages[0].test, "test" );
+ test.end();
+ }
+ });
+ }
+
+ pubnub.subscribe({
+ channel : channel,
+ connect : publish_test,
+ callback : function(message) {
+ test.ok(message);
+ test.equal( message.test, "test" );
+ time_test();
+ }
+ });
+
+});
+
View
39 javascript-modern/3.3/tests/test.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+## ------------------------------------------------
+## PubNub 3.3 Real-time Cloud Push API - JAVASCRIPT
+## ------------------------------------------------
+
+## ----------------------------------------------------
+##
+## TESTLING - PubNub JavaScript API for Web Browsers
+## uses Testling Cloud Service
+## for QA and Deployment.
+##
+## http://www.testling.com/
+## You need this to run './test.sh' unit test.
+##
+## ----------------------------------------------------
+
+if [ -z "$1" ]
+then
+ echo -e "\n\tUSER:PASSWD Required: http://testling.com/\n"
+ exit
+fi
+
+browsers='firefox/3.6'
+browsers=$browsers',firefox/9.0'
+browsers=$browsers',firefox/10.0'
+browsers=$browsers',chrome/16.0'
+browsers=$browsers',chrome/17.0'
+browsers=$browsers',iexplore/9.0'
+browsers=$browsers',safari/5.1'
+
+echo -e "Testing: $browsers"
+
+noinstrument='pubnub-3.3.js'
+
+tar -cf- test.js ../pubnub-3.3.js | \
+ curl -u $1 -sSNT- \
+ "testling.com/?noinstrument=$noinstrument&browsers=$browsers"
+
View
334 javascript-modern/3.3/tests/unit-test.html
@@ -0,0 +1,334 @@
+<!doctype html>
+<html>
+<head>
+ <title>PubNub JavaScript Unit Test</title>
+ <link
+ rel=stylesheet
+ href=http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css
+ >
+ <style type=text/css>
+ #stop-test,
+ #finished-fail,
+ #finished-success,
+ .tpl {display:none}
+ </style>
+</head>
+<body><div class=container>
+
+<!-- NOTICE / TITLE -->
+<div class="alert-message warning">
+ <a class="close" href="#">&#215;</a>
+ <p><strong>PubNub Unit Tests</strong> for JavaScript on Mobile and Desktop Web Browser</p>
+</div>
+
+<!-- BUTTON PANNEL -->
+<div class=well>
+ <button id=start-test class='btn info'>Start Test</button>
+ <button id=stop-test class='btn danger'>STOP</button>
+ <span id=finished-success class='label success'>100% Successful</span>
+ <span id=finished-fail class='label important'>Finished With Errors</span>
+ <span
+ id=test-status
+ class=label
+ template='Result: {pass}/{fail} (pass/fail) - Total: {total}'
+ >...</span>
+</div>
+
+<!-- OUTPUT -->
+<table id=unit-test-out class="zebra-striped">
+ <tr><th><span class=label>Pass/Fail</span><th>Test Ready
+</table>
+
+<!-- TEMPLATES -->
+<script type=text/template id=test_template class=tpl>
+ <td><span class="label {result}">{display}</span></td>
+ <td>{message}</td>
+</script>
+
+<script src=../pubnub-3.3-common.js></script>
+<script src=../pubnub-3.3.js></script>
+<script>(function(){
+
+
+ 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;
+ }
+
+ /**
+ * 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] || _
+ } );
+ }
+
+ function test( t, msg ) {
+ if (!test.run) return;
+
+ var entry = p.create('tr');
+
+ entry.innerHTML = p.supplant( test_tpl, {
+ result : t ? 'success' : 'important',
+ display : t ? 'pass' : 'fail',
+ message : msg
+ } );
+
+ t ? test.pass++ : test.fail++;
+ test.done++;
+
+ out.insertBefore( entry, out.firstChild );
+ console.log( t, msg );
+
+ status_area.innerHTML = p.supplant( status_tpl, {
+ pass : test.pass+'',
+ fail : test.fail+'',
+ total : test.done+''
+ } );
+
+ if (test.done === test.plan) {
+ stop_test();
+ test.fail ||
+ p.css( p.$('finished-success'), { display : 'inline-block' } ) &&
+ p.css( p.$('finished-fail'), { display : 'inline-block' } );
+ }
+ }
+
+
+ var REPL = /{([\w\-]+)}/g
+ , p = PUBNUB({ publish_key : 'demo', subscribe_key : 'demo' });
+
+ p.supplant = function supplant( str, values ) {
+ return str.replace( REPL, function( _, match ) {
+ return values[match] || _
+ } );
+ }
+ p.$ = function $(id) { return document.getElementById(id) };
+ p.attr = function attr( node, attribute, value ) {
+ if (value) node.setAttribute( attribute, value );
+ else return node && node.getAttribute && node.getAttribute(attribute);
+ };
+ p.create = function create(element) {
+ return document.createElement(element)
+ };
+ p.css = 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){}
+ };
+
+ p.bind = 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;
+ } );
+ };
+
+ var many_con_tst = 'opera' in window ? -1 : 10
+ , channel = 'pn-javascript-unit-test'
+ , out = p.$('unit-test-out')
+ , test_tpl = p.$('test_template').innerHTML
+ , start_button = p.$('start-test')
+ , stop_button = p.$('stop-test')
+ , status_area = p.$('test-status')
+ , status_tpl = p.attr( status_area, 'template' );
+
+ /* ======================================================================
+ Stop Test
+ ====================================================================== */
+ p.bind( 'mousedown,touchstart', stop_button, stop_test );
+ function stop_test() {
+ p.css( start_button, { display : 'inline-block' } );
+ p.css( stop_button, { display : 'none' } );
+ test.run = 0;
+ }
+
+ /* ======================================================================
+ Start Test
+ ====================================================================== */
+ p.bind( 'mousedown,touchstart', start_button, start_test );
+ function start_test() {
+ test.plan = 19 + many_con_tst*3; // # of tests
+ test.done = 0; // 0 tests done so far
+ test.pass = 0; // 0 passes so far
+ test.fail = 0; // 0 failes so far
+ test.run = 1; // continue running?
+
+ p.css( stop_button, { display : 'inline-block' } );
+ p.css( start_button, { display : 'none' } );
+ p.css( p.$('finished-fail'), { display : 'none' } );
+ p.css( p.$('finished-success'), { display : 'none' } );
+
+ test( 1, 'Ready to Test' );
+ test( PUBNUB, 'PubNub Lib Exists' );
+
+ p.time(function(time){
+ test( time, 'TimeToken' );
+ test( time > 0, 'Time Value' );
+ });
+
+ p.uuid(function(uuid){
+ test( uuid, 'UUID Response');
+ test( uuid.length > 10, 'UUID Long Enough');
+ });
+
+ function publish_test(con) {
+ con || test( 1, 'Connection Established' );
+
+ p.publish({
+ channel : channel,
+ message : { test : "test" },
+ callback : function(response) {
+ test( response[0], 'Successful Publish' );
+ test( response[1] === 'Sent', 'Success With Demo' );
+ history_test();
+ }
+ });
+ }
+
+ publish_test(1);
+
+ function history_test() {
+ p.history({
+ limit : 1,
+ channel : channel,
+ callback : function(messages) {
+ test( messages, 'History Response' );
+ test( messages[0].test === "test", 'History Content' );
+ }
+ });
+ }
+
+ p.subscribe({
+ channel : channel,
+ connect : publish_test,
+ callback : function( message, stack ) {
+ p.unsubscribe({ channel : channel });
+ test( message, 'Subscribe Message' );
+ test( message.test === "test", 'Subscribe Message Data' );
+ test( stack[1], 'TimeToken Returned: ' + stack[1] );
+ }
+ });
+
+ /* ------------------------------------------------------------------
+ --- MANY CONNECTIONS TESTS
+ ------------------------------------------------------------------ */
+ p.map( Array(many_con_tst).join('-').split('-'), function( _, conn ) {
+ var chan = 'many-conn-test-' + conn;
+ test( chan, 'Many Connections: ' + conn + ' Connecting...' );
+
+ p.subscribe({
+ channel : chan,
+ connect : function() {
+ test( chan, 'Many Connections: ' + conn + ' Connected!' );
+ p.publish({ channel : chan, message : chan });
+ },
+ callback : function(message) {
+ test(
+ chan === message,
+ 'Many Connections: ' + conn + ' Received'
+ );
+ setTimeout(
+ function() { p.unsubscribe({ channel : chan }) },
+ 5000
+ );
+ }
+ });
+ } );
+
+ /* ------------------------------------------------------------------
+ --- TESTING NEW CONNECTION RESTORE FEATURE
+ ------------------------------------------------------------------ */
+ var restore_channel = 'restore-channel'+Math.random();
+ p.subscribe({
+ restore : true,
+ channel : restore_channel,
+ callback : function(){},
+ connect : function() {
+ p.unsubscribe({ channel : restore_channel });
+
+ // Send Message While Not Connected
+ p.publish({
+ channel : restore_channel,
+ message : 'test',
+ callback : function() {
+ p.subscribe({
+ restore : true,
+ channel : restore_channel,
+ callback : function( message, stack ) {
+ p.unsubscribe({ channel : restore_channel });
+ test(
+ message === "test",
+ 'Subscribe Restore'
+ );
+ }
+ });
+ }
+ });
+ }
+ });
+
+
+ /*
+ restore : true,
+ disconnect : function() {
+ },
+ reconnect : function() {
+ },
+ connect : function() {
+ },
+ */
+
+ }
+ start_test();
+
+})();</script>
+</div></body>
+</html>
View
21 javascript-modern/3.3/tests/webworker.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+<head>
+ <title>PubNub JavaScript CommonJS</title>
+ <link
+ rel=stylesheet
+ href=http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css
+ >
+</head>
+<body><div class=container></div>
+<script>(function() {
+
+ var worker = new Worker("./webworker.js")
+
+ worker.onmessage = function(evt){
+ console.log(JSON.stringify(evt.data))
+ };
+
+})();</script>
+</body>
+</html>
View
52 javascript-modern/3.3/tests/webworker.js
@@ -0,0 +1,52 @@
+(function(){
+
+ "use strict"
+
+ importScripts('../pubnub-3.3-common.js')
+ importScripts('../pubnub-3.3.js')
+
+ var app = PUBNUB({
+ publish_key : 'demo',
+ subscribe_key : 'demo'
+ });
+ var channel = 'webworker-test-channel' + '-' + app.uuid();
+ app.publish({
+ channel : channel,
+ message : 'It Works!',
+ callback : function(info) {
+ postMessage(info);
+ app.history({
+ channel : channel,
+ limit : 1,
+ message : 123,
+ callback : postMessage
+ });
+ app.detailedHistory({
+ channel : channel,
+ count : 1,
+ message : 123,
+ callback : postMessage
+ })
+ }
+ });
+ app.subscribe({
+ channel : channel,
+ connect : function() {
+
+ setTimeout(function(){
+ app.here_now({
+ channel : channel,
+ callback : postMessage
+ })}, 5000);
+
+ setTimeout(function(){
+ app.publish({
+ channel : channel,
+ message : "Subscribe Test Message",
+ callback : postMessage
+ })}, 5000);
+ },
+ callback : function(response) { postMessage(response); }
+ })
+
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.