From 1479a3c8206fa1469eb80cffdaecc18badb0869f Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 15:29:51 +0530 Subject: [PATCH 01/17] checking testling integration --- README.md | 3 ++ package.json | 18 ++++++++ web/tests/test.js | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 package.json create mode 100644 web/tests/test.js diff --git a/README.md b/README.md index e23e0c3c9..c34cc3e0f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ + +[![browser support](http://ci.testling.com/devendram/pubnub-javascript-test.png)](http://ci.testling.com/devendram/pubnub-javascript-test) + # YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API. http://www.pubnub.com/account diff --git a/package.json b/package.json new file mode 100644 index 000000000..259c068b0 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "pubnub-javascript", + "version": "0.0.0", + "devDependencies": { + "mocha": "~1.7.4", + "should": "~1.2.1" + }, + "testling": { + "browsers": [ + "ie6", "ie7", "ie8", "ie9", + "firefox/15", "chrome/22", "opera/12", "safari/5.1" + ], + "harness" : "mocha", + "scripts" : "web/pubnub-3.4.2.js", + "files": "web/tests/test/test.js" + }, + "license": "MIT" +} diff --git a/web/tests/test.js b/web/tests/test.js new file mode 100644 index 000000000..5a27ac127 --- /dev/null +++ b/web/tests/test.js @@ -0,0 +1,103 @@ + var should = require('should'); + + var pubnub = PUBNUB.init({ + publish_key : 'demo', + subscribe_key : 'demo' + }); + + var pubnub_enc = PUBNUB.init({ + publish_key : 'demo', + subscribe_key : 'demo', + secret_key : 'demo', + cipher_key : 'demo' + }); + + var channel = 'javascript-test-channel'; + var channel_enc = 'javascript-encrypted-test-channel'; + + var message_string = 'Hi from Javascript'; + var message_jsono = {'message': 'Hi from Javascript'}; + var message_jsona = ['message' , 'Hi Hi from javascript']; + + describe('Pubnub', function() { + this.timeout(10000); + describe('#publish()', function(){ + it('should publish strings without error', function(done){ + pubnub.publish({channel: channel , message : message_string, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json objects without error', function(done){ + pubnub.publish({channel: channel , message : message_jsono, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json arrays without error', function(done){ + pubnub.publish({channel: channel , message : message_jsona, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish strings with encryption enabled without error', function(done){ + pubnub_enc.publish({channel: channel_enc , message : message_string, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json objects with encryption enabled without error', function(done){ + pubnub_enc.publish({channel: channel_enc , message : message_jsono, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json arrays with encryption enabled without error', function(done){ + pubnub_enc.publish({channel: channel_enc , message : message_jsona, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + }) + describe('#history', function(){ + var history_channel = channel + '-' + Date.now(); + this.timeout(60000); + before(function(done){ + pubnub.publish({channel: history_channel, + message : message_string, + callback : function(response){ + response[0].should.eql(1); } + }); + pubnub.publish({channel: history_channel, + message : message_string, + callback : function(response){ + response[0].should.eql(1); + done(); + } + }); + + }) + it('should return 2 messages when 2 messages were published on channel @slow', function(done) { + + pubnub.history({channel : history_channel, + callback : function(response) { + response[0].length.should.eql(2); + done(); + } + }) + }) + }) + +}) From 86147bd70350dacb961c926372e9d7cf957a6db0 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 15:34:17 +0530 Subject: [PATCH 02/17] fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 259c068b0..280bd7065 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ ], "harness" : "mocha", "scripts" : "web/pubnub-3.4.2.js", - "files": "web/tests/test/test.js" + "files": "web/tests/test.js" }, "license": "MIT" } From 0a7be499373130421870f57b839aad712eab8611 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 15:36:10 +0530 Subject: [PATCH 03/17] test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 280bd7065..97f29718c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "pubnub-javascript", + "name": "javascript", "version": "0.0.0", "devDependencies": { "mocha": "~1.7.4", From 79b7bbad7657c006350dc28b408537d045e12f5e Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 15:45:04 +0530 Subject: [PATCH 04/17] changed badge url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c34cc3e0f..44638fb11 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![browser support](http://ci.testling.com/devendram/pubnub-javascript-test.png)](http://ci.testling.com/devendram/pubnub-javascript-test) +[![browser support](http://ci.testling.com/devendram/javascript.png)](http://ci.testling.com/devendram/javascript) # YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API. http://www.pubnub.com/account From 5cc32f0d9e989169e39fa720c5077e287d92fe92 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 16:08:16 +0530 Subject: [PATCH 05/17] fix --- package.json | 4 +- pubnub-3.4.2.js | 1370 ++++++++++++++++++++++++++++++++++++++++ test/crypto.html | 180 ++++++ test/disconnect.html | 31 + test/multiplexing.html | 99 +++ test/test.js | 103 +++ test/unit-test.html | 346 ++++++++++ test/websocket.html | 51 ++ 8 files changed, 2182 insertions(+), 2 deletions(-) create mode 100644 pubnub-3.4.2.js create mode 100644 test/crypto.html create mode 100644 test/disconnect.html create mode 100644 test/multiplexing.html create mode 100644 test/test.js create mode 100644 test/unit-test.html create mode 100644 test/websocket.html diff --git a/package.json b/package.json index 97f29718c..1ff581c66 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "firefox/15", "chrome/22", "opera/12", "safari/5.1" ], "harness" : "mocha", - "scripts" : "web/pubnub-3.4.2.js", - "files": "web/tests/test.js" + "scripts" : "pubnub-3.4.2.js", + "files": "test/test.js" }, "license": "MIT" } diff --git a/pubnub-3.4.2.js b/pubnub-3.4.2.js new file mode 100644 index 000000000..d334b5c72 --- /dev/null +++ b/pubnub-3.4.2.js @@ -0,0 +1,1370 @@ +// 3.4.2 +/* =-====================================================================-= */ +/* =-====================================================================-= */ +/* =-========================= JSON =============================-= */ +/* =-====================================================================-= */ +/* =-====================================================================-= */ + +(window['JSON'] && window['JSON']['stringify']) || (function () { + window['JSON'] || (window['JSON'] = {}); + + function toJSON(key) { + try { return this.valueOf() } + catch(e) { return null } + } + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + function quote(string) { + escapable.lastIndex = 0; + return escapable.test(string) ? + '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : + '"' + string + '"'; + } + + function str(key, holder) { + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + partial, + mind = gap, + value = holder[key]; + + if (value && typeof value === 'object') { + value = toJSON.call( value, key ); + } + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + return String(value); + + case 'object': + + if (!value) { + return 'null'; + } + + gap += indent; + partial = []; + + if (Object.prototype.toString.apply(value) === '[object Array]') { + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + + v = partial.length === 0 ? '[]' : + gap ? '[\n' + gap + + partial.join(',\n' + gap) + '\n' + + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + k = rep[i]; + if (typeof k === 'string') { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + + v = partial.length === 0 ? '{}' : + gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + + mind + '}' : '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + + if (typeof JSON['stringify'] !== 'function') { + JSON['stringify'] = function (value, replacer, space) { + var i; + gap = ''; + indent = ''; + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + } else if (typeof space === 'string') { + indent = space; + } + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + return str('', {'': value}); + }; + } + + if (typeof JSON['parse'] !== 'function') { + // JSON is parsed on the server for security. + JSON['parse'] = function (text) {return eval('('+text+')')}; + } +}()); +/* --------------------------------------------------------------------------- +WAIT! - This file depends on instructions from the PUBNUB Cloud. +http://www.pubnub.com/account-javascript-api-include +--------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------- +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. +--------------------------------------------------------------------------- */ + +/* =-====================================================================-= */ +/* =-====================================================================-= */ +/* =-========================= UTIL =============================-= */ +/* =-====================================================================-= */ +/* =-====================================================================-= */ + +window['PUBNUB'] || (function() { + +/** + * UTIL LOCALS + */ +var NOW = 1 +, SWF = 'https://pubnub.a.ssl.fastly.net/pubnub.swf' +, REPL = /{([\w\-]+)}/g +, ASYNC = 'async' +, URLBIT = '/' +, PARAMSBIT = '&' +, DEF_WINDOWING = 10 // MILLISECONDS. +, DEF_TIMEOUT = 10000 // MILLISECONDS. +, DEF_SUB_TIMEOUT = 310 // SECONDS. +, DEF_KEEPALIVE = 60 // SECONDS. +, SECOND = 1000 // A THOUSAND MILLISECONDS. +, PRESENCE_SUFFIX = '-pnpres' +, UA = navigator.userAgent +, XORIGN = UA.indexOf('MSIE 6') == -1; + +/** + * CONSOLE COMPATIBILITY + */ +window.console || (window.console=window.console||{}); +console.log || ( + console.log = + console.error = + ((window.opera||{}).postError||function(){}) +); + +/** + * UTILITIES + */ +function unique() { return'x'+ ++NOW+''+(+new Date) } +function rnow() { return+new Date } + +/** + * LOCAL STORAGE OR COOKIE + */ +var db = (function(){ + var ls = window['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 } + } + }; +})(); + +/** + * 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; + } +})(); + +/** + * 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; +} + +/** + * $ + * = + * var div = $('divid'); + */ +function $(id) { return document.getElementById(id) } + +/** + * ERROR + * ===== + * error('message'); + */ +function error(message) { console['error'](message) } + +/** + * 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; +} + +/** + * 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; +} + +/** + * 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] || _ + } ); +} + +/** + * 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; +} + +/** + * HEAD + * ==== + * head().appendChild(elm); + */ +function head() { return search('head')[0] } + +/** + * 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); +} + +/** + * 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) } + +/** + * 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; +} + +/** + * jsonp_cb + * ======== + * var callback = jsonp_cb(); + */ +function jsonp_cb() { return XORIGN || FDomainRequest() ? 0 : unique() } + +/** + * 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(''); +} + +/** + * 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) } + ); + } +}; + +/** + * XDR Cross Domain Request + * ======================== + * xdr({ + * url : ['http://www.blah.com/url'], + * success : function(response) {}, + * fail : function() {} + * }); + */ +function xdr( setup ) { + if (XORIGN || FDomainRequest()) return ajax(setup); + + var script = create('script') + , callback = setup.callback + , id = unique() + , finished = 0 + , xhrtme = setup.timeout || DEF_TIMEOUT + , timer = timeout( function(){done(1)}, xhrtme ) + , fail = setup.fail || function(){} + , success = setup.success || function(){} + + , append = function() { + head().appendChild(script); + } + + , done = function( failed, response ) { + if (finished) return; + finished = 1; + + failed || success(response); + script.onerror = null; + clearTimeout(timer); + + timeout( function() { + failed && fail(); + var s = $(id) + , p = s && s.parentNode; + p && p.removeChild(s); + }, SECOND ); + }; + + window[callback] = function(response) { + done( 0, response ); + }; + + if (!setup.blocking) script[ASYNC] = ASYNC; + + script.onerror = function() { done(1) }; + script.src = setup.url.join(URLBIT); + + if (setup.data) { + var params = []; + script.src += "?"; + for (var key in setup.data) { + params.push(key+"="+setup.data[key]); + } + script.src += params.join(PARAMSBIT); + } + attr( script, 'id', id ); + + append(); + return done; +} + +/** + * CORS XHR Request + * ================ + * xdr({ + * url : ['http://www.blah.com/url'], + * success : function(response) {}, + * fail : function() {} + * }); + */ +function ajax( setup ) { + var xhr, response + , 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 + , xhrtme = setup.timeout || DEF_TIMEOUT + , 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 = FDomainRequest() || + window.XDomainRequest && + new XDomainRequest() || + new XMLHttpRequest(); + + xhr.onerror = xhr.onabort = function(){ done(1) }; + xhr.onload = xhr.onloadend = finished; + xhr.timeout = xhrtme; + + var url = setup.url.join(URLBIT); + if (setup.data) { + var params = []; + var key; + url += "?"; + for (key in setup.data) params.push(key+"="+setup.data[key]); + url += params.join(PARAMSBIT); + } + + xhr.open( 'GET', url, (typeof(setup.blocking === 'undefined')) ); + xhr.send(); + } + catch(eee) { + done(0); + XORIGN = 0; + return xdr(setup); + } + + // Return 'done' + return done; +} + +/** + * 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 ===========================-= */ +/* =-====================================================================-= */ +/* =-====================================================================-= */ + +var PDIV = $('pubnub') || 0 +, READY = 0 +, READY_BUFFER = [] +, CREATE_PUBNUB = function(setup) { + + // Force JSONP if requested from user. + if (setup['jsonp']) XORIGN = 0; + + var CHANNELS = {} + , PUB_QUEUE = [] + , SUB_CALLBACK = 0 + , SUB_CHANNEL = 0 + , SUB_RECEIVER = 0 + , SUB_RESTORE = 0 + , SUB_BUFF_WAIT = 0 + , TIMETOKEN = 0 + , 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' : '' + , UUID = setup['uuid'] || db['get'](SUBSCRIBE_KEY+'uuid') || '' + , ORIGIN = 'http'+SSL+'://'+(setup['origin']||'pubsub.pubnub.com') + , STD_ORIGIN = nextorigin(ORIGIN) + , SUB_ORIGIN = nextorigin(ORIGIN) + , LEAVE = function(){} + , CONNECT = function(){} + , SELF = { + /* + 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) 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 + , sub_timeout = args['timeout'] || SUB_TIMEOUT + , windowing = args['windowing'] || SUB_WINDOWING + , restore = args['restore']; + + // Restore Enabled? + if (restore) SUB_RESTORE = 1; + + // 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]; + + // 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 = {}; + + // 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['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, + 'css' : css, + '$' : $, + 'create' : create, + 'bind' : bind, + 'supplant' : supplant, + 'head' : head, + 'search' : search, + 'attr' : attr, + 'now' : rnow, + 'unique' : unique, + 'events' : events, + 'updater' : updater, + 'init' : CREATE_PUBNUB + }; + + PUB_QUEUE.sending = 0; + 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); + } ); + } + + if (!UUID) UUID = uuid(); + db['set']( SUBSCRIBE_KEY + 'uuid', UUID ); + + // Return without Testing + if (setup['notest']) return SELF; + + // Announce Leave Event + 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' + ] + }); + }; + + // Add Leave Functions + bind( 'beforeunload', window, function() { + each_channel(function(ch){ LEAVE( ch.name, 1 ) }); + return true; + } ); + + // Test Connection State + function _is_online() { + if (!('onLine' in navigator)) return 1; + return navigator['onLine']; + } + 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); + } + timeout( _poll_online, SECOND ); + timeout( _poll_online2, KEEPALIVE ); + + bind( 'offline', window, _reset_offline ); + bind( 'offline', document, _reset_offline ); + + // Return PUBNUB Socket Object + return SELF; +}; + +// PUBNUB READY TO CONNECT +function ready() { timeout( function() { + if (READY) return; + READY = 1; + each( READY_BUFFER, function(connect) { connect() } ); +}, SECOND ); } + +// Bind for PUBNUB Readiness to Subscribe +bind( 'load', window, function(){ timeout( ready, 0 ) } ); + +var pdiv = PDIV || {}; + +// CREATE A PUBNUB GLOBAL OBJECT +PUBNUB = CREATE_PUBNUB({ + 'notest' : 1, + 'publish_key' : attr( pdiv, 'pub-key' ), + 'subscribe_key' : attr( pdiv, 'sub-key' ), + 'ssl' : !document.location.href.indexOf('https') || + attr( pdiv, 'ssl' ) == 'on', + 'origin' : attr( pdiv, 'origin' ), + 'uuid' : attr( pdiv, 'uuid' ) +}); + +// jQuery Interface +window['jQuery'] && (window['jQuery']['PUBNUB'] = PUBNUB); + +// For Modern JS + Testling.js - http://testling.com/ +typeof(module) !== 'undefined' && (module['exports'] = PUBNUB) && ready(); + +var pubnubs = $('pubnubs') || 0; + +// LEAVE NOW IF NO PDIV. +if (!PDIV) return; + +// PUBNUB Flash Socket +css( PDIV, { 'position' : 'absolute', 'top' : -SECOND } ); + +if ('opera' in window || attr( PDIV, 'flash' )) PDIV['innerHTML'] = + ''; + +// Create Interface for Opera Flash +PUBNUB['rdx'] = function( id, data ) { + if (!data) return FDomainRequest[id]['onerror'](); + FDomainRequest[id]['responseText'] = unescape(data); + FDomainRequest[id]['onload'](); +}; + +function FDomainRequest() { + if (!pubnubs || !pubnubs['get']) return 0; + + var fdomainrequest = { + 'id' : FDomainRequest['id']++, + 'send' : function() {}, + 'abort' : function() { fdomainrequest['id'] = {} }, + 'open' : function( method, url ) { + FDomainRequest[fdomainrequest['id']] = fdomainrequest; + pubnubs['get']( fdomainrequest['id'], url ); + } + }; + + return fdomainrequest; +} +FDomainRequest['id'] = SECOND; + +})(); +(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']({}); +}; + +})(); diff --git a/test/crypto.html b/test/crypto.html new file mode 100644 index 000000000..3bc21f9dc --- /dev/null +++ b/test/crypto.html @@ -0,0 +1,180 @@ + + + + PubNub Crypto + + + + + + + + +
+ +

PubNub Cryptography in JavaScript

+

+ This HTML page demonstrates with PubNub Cryptography for sensitive data. + Use this page and source code to provide high levels of security + for data intended to be private and unreadable. + The Cipher Key specifies the particular transformation + of plaintext into ciphertext, or vice versa during decryption. +

+

Cryptographic Cipher Key

+ + +
+
+

Secure Entropic Channel

+ +

Publish Key

+ +

Subscribe Key

+ +
+
+

Cloud Cluster Origin

+ +

2048bit SSL Encryption

+ +

Secure Message

+ +
+
+ +

Encrypted Traffic

+

+ View the Source Code of index.html to see how Encryption is handled. + See the encrypt-pubnub.js file to learn more about the + implementation used by PubNub JavaScript client. +

+ +

+Start Encrypted Message Traffic +

+
+ +
+ + + +
+ diff --git a/test/disconnect.html b/test/disconnect.html new file mode 100644 index 000000000..b46781817 --- /dev/null +++ b/test/disconnect.html @@ -0,0 +1,31 @@ + + + + + PubNub JavaScript Unit Test + + + + + + + + + diff --git a/test/multiplexing.html b/test/multiplexing.html new file mode 100644 index 000000000..713d2eb04 --- /dev/null +++ b/test/multiplexing.html @@ -0,0 +1,99 @@ + + + + + PubNub JavaScript Multiplexing Test + + + +
+ +
...
+ +
+ + +
+ diff --git a/test/test.js b/test/test.js new file mode 100644 index 000000000..5a27ac127 --- /dev/null +++ b/test/test.js @@ -0,0 +1,103 @@ + var should = require('should'); + + var pubnub = PUBNUB.init({ + publish_key : 'demo', + subscribe_key : 'demo' + }); + + var pubnub_enc = PUBNUB.init({ + publish_key : 'demo', + subscribe_key : 'demo', + secret_key : 'demo', + cipher_key : 'demo' + }); + + var channel = 'javascript-test-channel'; + var channel_enc = 'javascript-encrypted-test-channel'; + + var message_string = 'Hi from Javascript'; + var message_jsono = {'message': 'Hi from Javascript'}; + var message_jsona = ['message' , 'Hi Hi from javascript']; + + describe('Pubnub', function() { + this.timeout(10000); + describe('#publish()', function(){ + it('should publish strings without error', function(done){ + pubnub.publish({channel: channel , message : message_string, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json objects without error', function(done){ + pubnub.publish({channel: channel , message : message_jsono, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json arrays without error', function(done){ + pubnub.publish({channel: channel , message : message_jsona, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish strings with encryption enabled without error', function(done){ + pubnub_enc.publish({channel: channel_enc , message : message_string, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json objects with encryption enabled without error', function(done){ + pubnub_enc.publish({channel: channel_enc , message : message_jsono, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + it('should publish json arrays with encryption enabled without error', function(done){ + pubnub_enc.publish({channel: channel_enc , message : message_jsona, + callback : function(response) { + response[0].should.eql(1); + done(); + } + }) + }) + }) + describe('#history', function(){ + var history_channel = channel + '-' + Date.now(); + this.timeout(60000); + before(function(done){ + pubnub.publish({channel: history_channel, + message : message_string, + callback : function(response){ + response[0].should.eql(1); } + }); + pubnub.publish({channel: history_channel, + message : message_string, + callback : function(response){ + response[0].should.eql(1); + done(); + } + }); + + }) + it('should return 2 messages when 2 messages were published on channel @slow', function(done) { + + pubnub.history({channel : history_channel, + callback : function(response) { + response[0].length.should.eql(2); + done(); + } + }) + }) + }) + +}) diff --git a/test/unit-test.html b/test/unit-test.html new file mode 100644 index 000000000..a9a55e376 --- /dev/null +++ b/test/unit-test.html @@ -0,0 +1,346 @@ + + + + + PubNub JavaScript Unit Test + + + + + +
+ + +
+ × + +

PubNub Unit Tests for JavaScript on Mobile and Desktop Web Browser

+
+ + +
+ + + 100% Successful + Finished With Errors + ... +
+ + + +
+ + + + +
+ + + + +
+ + diff --git a/test/websocket.html b/test/websocket.html new file mode 100644 index 000000000..b29d3a093 --- /dev/null +++ b/test/websocket.html @@ -0,0 +1,51 @@ + + + + + PubNub JavaScript Unit Test + + + + +
+ +
+ + + + + From 9c6cf3bdb8124665e8a3ab30872a9b8b21597292 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 16:09:38 +0530 Subject: [PATCH 06/17] changed package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ff581c66..f9567d190 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "javascript", + "name": "pubnub-javascript", "version": "0.0.0", "devDependencies": { "mocha": "~1.7.4", From 106446fd7dbd01783371c704099f47ecc302dfe1 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 16:44:48 +0530 Subject: [PATCH 07/17] removing test files --- package.json | 4 +- pubnub-3.4.2.js | 1370 ---------------------------------------- test/crypto.html | 180 ------ test/disconnect.html | 31 - test/multiplexing.html | 99 --- test/test.js | 103 --- test/unit-test.html | 346 ---------- test/websocket.html | 51 -- 8 files changed, 2 insertions(+), 2182 deletions(-) delete mode 100644 pubnub-3.4.2.js delete mode 100644 test/crypto.html delete mode 100644 test/disconnect.html delete mode 100644 test/multiplexing.html delete mode 100644 test/test.js delete mode 100644 test/unit-test.html delete mode 100644 test/websocket.html diff --git a/package.json b/package.json index f9567d190..280bd7065 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "firefox/15", "chrome/22", "opera/12", "safari/5.1" ], "harness" : "mocha", - "scripts" : "pubnub-3.4.2.js", - "files": "test/test.js" + "scripts" : "web/pubnub-3.4.2.js", + "files": "web/tests/test.js" }, "license": "MIT" } diff --git a/pubnub-3.4.2.js b/pubnub-3.4.2.js deleted file mode 100644 index d334b5c72..000000000 --- a/pubnub-3.4.2.js +++ /dev/null @@ -1,1370 +0,0 @@ -// 3.4.2 -/* =-====================================================================-= */ -/* =-====================================================================-= */ -/* =-========================= JSON =============================-= */ -/* =-====================================================================-= */ -/* =-====================================================================-= */ - -(window['JSON'] && window['JSON']['stringify']) || (function () { - window['JSON'] || (window['JSON'] = {}); - - function toJSON(key) { - try { return this.valueOf() } - catch(e) { return null } - } - - var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - gap, - indent, - meta = { // table of character substitutions - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '\\': '\\\\' - }, - rep; - - function quote(string) { - escapable.lastIndex = 0; - return escapable.test(string) ? - '"' + string.replace(escapable, function (a) { - var c = meta[a]; - return typeof c === 'string' ? c : - '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); - }) + '"' : - '"' + string + '"'; - } - - function str(key, holder) { - var i, // The loop counter. - k, // The member key. - v, // The member value. - length, - partial, - mind = gap, - value = holder[key]; - - if (value && typeof value === 'object') { - value = toJSON.call( value, key ); - } - - if (typeof rep === 'function') { - value = rep.call(holder, key, value); - } - - switch (typeof value) { - case 'string': - return quote(value); - - case 'number': - return isFinite(value) ? String(value) : 'null'; - - case 'boolean': - case 'null': - return String(value); - - case 'object': - - if (!value) { - return 'null'; - } - - gap += indent; - partial = []; - - if (Object.prototype.toString.apply(value) === '[object Array]') { - - length = value.length; - for (i = 0; i < length; i += 1) { - partial[i] = str(i, value) || 'null'; - } - - v = partial.length === 0 ? '[]' : - gap ? '[\n' + gap + - partial.join(',\n' + gap) + '\n' + - mind + ']' : - '[' + partial.join(',') + ']'; - gap = mind; - return v; - } - if (rep && typeof rep === 'object') { - length = rep.length; - for (i = 0; i < length; i += 1) { - k = rep[i]; - if (typeof k === 'string') { - v = str(k, value); - if (v) { - partial.push(quote(k) + (gap ? ': ' : ':') + v); - } - } - } - } else { - for (k in value) { - if (Object.hasOwnProperty.call(value, k)) { - v = str(k, value); - if (v) { - partial.push(quote(k) + (gap ? ': ' : ':') + v); - } - } - } - } - - v = partial.length === 0 ? '{}' : - gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + - mind + '}' : '{' + partial.join(',') + '}'; - gap = mind; - return v; - } - } - - if (typeof JSON['stringify'] !== 'function') { - JSON['stringify'] = function (value, replacer, space) { - var i; - gap = ''; - indent = ''; - - if (typeof space === 'number') { - for (i = 0; i < space; i += 1) { - indent += ' '; - } - } else if (typeof space === 'string') { - indent = space; - } - rep = replacer; - if (replacer && typeof replacer !== 'function' && - (typeof replacer !== 'object' || - typeof replacer.length !== 'number')) { - throw new Error('JSON.stringify'); - } - return str('', {'': value}); - }; - } - - if (typeof JSON['parse'] !== 'function') { - // JSON is parsed on the server for security. - JSON['parse'] = function (text) {return eval('('+text+')')}; - } -}()); -/* --------------------------------------------------------------------------- -WAIT! - This file depends on instructions from the PUBNUB Cloud. -http://www.pubnub.com/account-javascript-api-include ---------------------------------------------------------------------------- */ - -/* --------------------------------------------------------------------------- -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. ---------------------------------------------------------------------------- */ - -/* =-====================================================================-= */ -/* =-====================================================================-= */ -/* =-========================= UTIL =============================-= */ -/* =-====================================================================-= */ -/* =-====================================================================-= */ - -window['PUBNUB'] || (function() { - -/** - * UTIL LOCALS - */ -var NOW = 1 -, SWF = 'https://pubnub.a.ssl.fastly.net/pubnub.swf' -, REPL = /{([\w\-]+)}/g -, ASYNC = 'async' -, URLBIT = '/' -, PARAMSBIT = '&' -, DEF_WINDOWING = 10 // MILLISECONDS. -, DEF_TIMEOUT = 10000 // MILLISECONDS. -, DEF_SUB_TIMEOUT = 310 // SECONDS. -, DEF_KEEPALIVE = 60 // SECONDS. -, SECOND = 1000 // A THOUSAND MILLISECONDS. -, PRESENCE_SUFFIX = '-pnpres' -, UA = navigator.userAgent -, XORIGN = UA.indexOf('MSIE 6') == -1; - -/** - * CONSOLE COMPATIBILITY - */ -window.console || (window.console=window.console||{}); -console.log || ( - console.log = - console.error = - ((window.opera||{}).postError||function(){}) -); - -/** - * UTILITIES - */ -function unique() { return'x'+ ++NOW+''+(+new Date) } -function rnow() { return+new Date } - -/** - * LOCAL STORAGE OR COOKIE - */ -var db = (function(){ - var ls = window['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 } - } - }; -})(); - -/** - * 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; - } -})(); - -/** - * 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; -} - -/** - * $ - * = - * var div = $('divid'); - */ -function $(id) { return document.getElementById(id) } - -/** - * ERROR - * ===== - * error('message'); - */ -function error(message) { console['error'](message) } - -/** - * 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; -} - -/** - * 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; -} - -/** - * 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] || _ - } ); -} - -/** - * 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; -} - -/** - * HEAD - * ==== - * head().appendChild(elm); - */ -function head() { return search('head')[0] } - -/** - * 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); -} - -/** - * 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) } - -/** - * 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; -} - -/** - * jsonp_cb - * ======== - * var callback = jsonp_cb(); - */ -function jsonp_cb() { return XORIGN || FDomainRequest() ? 0 : unique() } - -/** - * 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(''); -} - -/** - * 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) } - ); - } -}; - -/** - * XDR Cross Domain Request - * ======================== - * xdr({ - * url : ['http://www.blah.com/url'], - * success : function(response) {}, - * fail : function() {} - * }); - */ -function xdr( setup ) { - if (XORIGN || FDomainRequest()) return ajax(setup); - - var script = create('script') - , callback = setup.callback - , id = unique() - , finished = 0 - , xhrtme = setup.timeout || DEF_TIMEOUT - , timer = timeout( function(){done(1)}, xhrtme ) - , fail = setup.fail || function(){} - , success = setup.success || function(){} - - , append = function() { - head().appendChild(script); - } - - , done = function( failed, response ) { - if (finished) return; - finished = 1; - - failed || success(response); - script.onerror = null; - clearTimeout(timer); - - timeout( function() { - failed && fail(); - var s = $(id) - , p = s && s.parentNode; - p && p.removeChild(s); - }, SECOND ); - }; - - window[callback] = function(response) { - done( 0, response ); - }; - - if (!setup.blocking) script[ASYNC] = ASYNC; - - script.onerror = function() { done(1) }; - script.src = setup.url.join(URLBIT); - - if (setup.data) { - var params = []; - script.src += "?"; - for (var key in setup.data) { - params.push(key+"="+setup.data[key]); - } - script.src += params.join(PARAMSBIT); - } - attr( script, 'id', id ); - - append(); - return done; -} - -/** - * CORS XHR Request - * ================ - * xdr({ - * url : ['http://www.blah.com/url'], - * success : function(response) {}, - * fail : function() {} - * }); - */ -function ajax( setup ) { - var xhr, response - , 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 - , xhrtme = setup.timeout || DEF_TIMEOUT - , 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 = FDomainRequest() || - window.XDomainRequest && - new XDomainRequest() || - new XMLHttpRequest(); - - xhr.onerror = xhr.onabort = function(){ done(1) }; - xhr.onload = xhr.onloadend = finished; - xhr.timeout = xhrtme; - - var url = setup.url.join(URLBIT); - if (setup.data) { - var params = []; - var key; - url += "?"; - for (key in setup.data) params.push(key+"="+setup.data[key]); - url += params.join(PARAMSBIT); - } - - xhr.open( 'GET', url, (typeof(setup.blocking === 'undefined')) ); - xhr.send(); - } - catch(eee) { - done(0); - XORIGN = 0; - return xdr(setup); - } - - // Return 'done' - return done; -} - -/** - * 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 ===========================-= */ -/* =-====================================================================-= */ -/* =-====================================================================-= */ - -var PDIV = $('pubnub') || 0 -, READY = 0 -, READY_BUFFER = [] -, CREATE_PUBNUB = function(setup) { - - // Force JSONP if requested from user. - if (setup['jsonp']) XORIGN = 0; - - var CHANNELS = {} - , PUB_QUEUE = [] - , SUB_CALLBACK = 0 - , SUB_CHANNEL = 0 - , SUB_RECEIVER = 0 - , SUB_RESTORE = 0 - , SUB_BUFF_WAIT = 0 - , TIMETOKEN = 0 - , 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' : '' - , UUID = setup['uuid'] || db['get'](SUBSCRIBE_KEY+'uuid') || '' - , ORIGIN = 'http'+SSL+'://'+(setup['origin']||'pubsub.pubnub.com') - , STD_ORIGIN = nextorigin(ORIGIN) - , SUB_ORIGIN = nextorigin(ORIGIN) - , LEAVE = function(){} - , CONNECT = function(){} - , SELF = { - /* - 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) 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 - , sub_timeout = args['timeout'] || SUB_TIMEOUT - , windowing = args['windowing'] || SUB_WINDOWING - , restore = args['restore']; - - // Restore Enabled? - if (restore) SUB_RESTORE = 1; - - // 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]; - - // 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 = {}; - - // 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['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, - 'css' : css, - '$' : $, - 'create' : create, - 'bind' : bind, - 'supplant' : supplant, - 'head' : head, - 'search' : search, - 'attr' : attr, - 'now' : rnow, - 'unique' : unique, - 'events' : events, - 'updater' : updater, - 'init' : CREATE_PUBNUB - }; - - PUB_QUEUE.sending = 0; - 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); - } ); - } - - if (!UUID) UUID = uuid(); - db['set']( SUBSCRIBE_KEY + 'uuid', UUID ); - - // Return without Testing - if (setup['notest']) return SELF; - - // Announce Leave Event - 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' - ] - }); - }; - - // Add Leave Functions - bind( 'beforeunload', window, function() { - each_channel(function(ch){ LEAVE( ch.name, 1 ) }); - return true; - } ); - - // Test Connection State - function _is_online() { - if (!('onLine' in navigator)) return 1; - return navigator['onLine']; - } - 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); - } - timeout( _poll_online, SECOND ); - timeout( _poll_online2, KEEPALIVE ); - - bind( 'offline', window, _reset_offline ); - bind( 'offline', document, _reset_offline ); - - // Return PUBNUB Socket Object - return SELF; -}; - -// PUBNUB READY TO CONNECT -function ready() { timeout( function() { - if (READY) return; - READY = 1; - each( READY_BUFFER, function(connect) { connect() } ); -}, SECOND ); } - -// Bind for PUBNUB Readiness to Subscribe -bind( 'load', window, function(){ timeout( ready, 0 ) } ); - -var pdiv = PDIV || {}; - -// CREATE A PUBNUB GLOBAL OBJECT -PUBNUB = CREATE_PUBNUB({ - 'notest' : 1, - 'publish_key' : attr( pdiv, 'pub-key' ), - 'subscribe_key' : attr( pdiv, 'sub-key' ), - 'ssl' : !document.location.href.indexOf('https') || - attr( pdiv, 'ssl' ) == 'on', - 'origin' : attr( pdiv, 'origin' ), - 'uuid' : attr( pdiv, 'uuid' ) -}); - -// jQuery Interface -window['jQuery'] && (window['jQuery']['PUBNUB'] = PUBNUB); - -// For Modern JS + Testling.js - http://testling.com/ -typeof(module) !== 'undefined' && (module['exports'] = PUBNUB) && ready(); - -var pubnubs = $('pubnubs') || 0; - -// LEAVE NOW IF NO PDIV. -if (!PDIV) return; - -// PUBNUB Flash Socket -css( PDIV, { 'position' : 'absolute', 'top' : -SECOND } ); - -if ('opera' in window || attr( PDIV, 'flash' )) PDIV['innerHTML'] = - ''; - -// Create Interface for Opera Flash -PUBNUB['rdx'] = function( id, data ) { - if (!data) return FDomainRequest[id]['onerror'](); - FDomainRequest[id]['responseText'] = unescape(data); - FDomainRequest[id]['onload'](); -}; - -function FDomainRequest() { - if (!pubnubs || !pubnubs['get']) return 0; - - var fdomainrequest = { - 'id' : FDomainRequest['id']++, - 'send' : function() {}, - 'abort' : function() { fdomainrequest['id'] = {} }, - 'open' : function( method, url ) { - FDomainRequest[fdomainrequest['id']] = fdomainrequest; - pubnubs['get']( fdomainrequest['id'], url ); - } - }; - - return fdomainrequest; -} -FDomainRequest['id'] = SECOND; - -})(); -(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']({}); -}; - -})(); diff --git a/test/crypto.html b/test/crypto.html deleted file mode 100644 index 3bc21f9dc..000000000 --- a/test/crypto.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - PubNub Crypto - - - - - - - - -
- -

PubNub Cryptography in JavaScript

-

- This HTML page demonstrates with PubNub Cryptography for sensitive data. - Use this page and source code to provide high levels of security - for data intended to be private and unreadable. - The Cipher Key specifies the particular transformation - of plaintext into ciphertext, or vice versa during decryption. -

-

Cryptographic Cipher Key

- - -
-
-

Secure Entropic Channel

- -

Publish Key

- -

Subscribe Key

- -
-
-

Cloud Cluster Origin

- -

2048bit SSL Encryption

- -

Secure Message

- -
-
- -

Encrypted Traffic

-

- View the Source Code of index.html to see how Encryption is handled. - See the encrypt-pubnub.js file to learn more about the - implementation used by PubNub JavaScript client. -

- -

-Start Encrypted Message Traffic -

-
- -
- - - -
- diff --git a/test/disconnect.html b/test/disconnect.html deleted file mode 100644 index b46781817..000000000 --- a/test/disconnect.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - PubNub JavaScript Unit Test - - - - - - - - - diff --git a/test/multiplexing.html b/test/multiplexing.html deleted file mode 100644 index 713d2eb04..000000000 --- a/test/multiplexing.html +++ /dev/null @@ -1,99 +0,0 @@ - - - - - PubNub JavaScript Multiplexing Test - - - -
- -
...
- -
- - -
- diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5a27ac127..000000000 --- a/test/test.js +++ /dev/null @@ -1,103 +0,0 @@ - var should = require('should'); - - var pubnub = PUBNUB.init({ - publish_key : 'demo', - subscribe_key : 'demo' - }); - - var pubnub_enc = PUBNUB.init({ - publish_key : 'demo', - subscribe_key : 'demo', - secret_key : 'demo', - cipher_key : 'demo' - }); - - var channel = 'javascript-test-channel'; - var channel_enc = 'javascript-encrypted-test-channel'; - - var message_string = 'Hi from Javascript'; - var message_jsono = {'message': 'Hi from Javascript'}; - var message_jsona = ['message' , 'Hi Hi from javascript']; - - describe('Pubnub', function() { - this.timeout(10000); - describe('#publish()', function(){ - it('should publish strings without error', function(done){ - pubnub.publish({channel: channel , message : message_string, - callback : function(response) { - response[0].should.eql(1); - done(); - } - }) - }) - it('should publish json objects without error', function(done){ - pubnub.publish({channel: channel , message : message_jsono, - callback : function(response) { - response[0].should.eql(1); - done(); - } - }) - }) - it('should publish json arrays without error', function(done){ - pubnub.publish({channel: channel , message : message_jsona, - callback : function(response) { - response[0].should.eql(1); - done(); - } - }) - }) - it('should publish strings with encryption enabled without error', function(done){ - pubnub_enc.publish({channel: channel_enc , message : message_string, - callback : function(response) { - response[0].should.eql(1); - done(); - } - }) - }) - it('should publish json objects with encryption enabled without error', function(done){ - pubnub_enc.publish({channel: channel_enc , message : message_jsono, - callback : function(response) { - response[0].should.eql(1); - done(); - } - }) - }) - it('should publish json arrays with encryption enabled without error', function(done){ - pubnub_enc.publish({channel: channel_enc , message : message_jsona, - callback : function(response) { - response[0].should.eql(1); - done(); - } - }) - }) - }) - describe('#history', function(){ - var history_channel = channel + '-' + Date.now(); - this.timeout(60000); - before(function(done){ - pubnub.publish({channel: history_channel, - message : message_string, - callback : function(response){ - response[0].should.eql(1); } - }); - pubnub.publish({channel: history_channel, - message : message_string, - callback : function(response){ - response[0].should.eql(1); - done(); - } - }); - - }) - it('should return 2 messages when 2 messages were published on channel @slow', function(done) { - - pubnub.history({channel : history_channel, - callback : function(response) { - response[0].length.should.eql(2); - done(); - } - }) - }) - }) - -}) diff --git a/test/unit-test.html b/test/unit-test.html deleted file mode 100644 index a9a55e376..000000000 --- a/test/unit-test.html +++ /dev/null @@ -1,346 +0,0 @@ - - - - - PubNub JavaScript Unit Test - - - - - -
- - -
- × - -

PubNub Unit Tests for JavaScript on Mobile and Desktop Web Browser

-
- - -
- - - 100% Successful - Finished With Errors - ... -
- - - -
- - - - -
- - - - -
- - diff --git a/test/websocket.html b/test/websocket.html deleted file mode 100644 index b29d3a093..000000000 --- a/test/websocket.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - PubNub JavaScript Unit Test - - - - -
- -
- - - - - From 8833abe5c72a48a491af7dd80b04094ed37f0483 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 17:16:46 +0530 Subject: [PATCH 08/17] testing --- web/tests/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/tests/test.js b/web/tests/test.js index 5a27ac127..5a50320da 100644 --- a/web/tests/test.js +++ b/web/tests/test.js @@ -16,7 +16,7 @@ var channel_enc = 'javascript-encrypted-test-channel'; var message_string = 'Hi from Javascript'; - var message_jsono = {'message': 'Hi from Javascript'}; + var message_jsono = {'message': 'Hi Hi from Javascript'}; var message_jsona = ['message' , 'Hi Hi from javascript']; describe('Pubnub', function() { From 58b62681de5aa94425fe82885f1588adf022e40d Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 7 Mar 2013 17:32:44 +0530 Subject: [PATCH 09/17] testing --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 280bd7065..aec58dc4e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ }, "testling": { "browsers": [ - "ie6", "ie7", "ie8", "ie9", + "ie6", "ie7", "ie8", "ie9", "iphone/6.0","ipad/6.0", "firefox/15", "chrome/22", "opera/12", "safari/5.1" ], "harness" : "mocha", From 7e359d22b978a9f5045cd8da21a4aabe8c48cbeb Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 8 Mar 2013 00:47:01 +0530 Subject: [PATCH 10/17] adding all browsers --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index aec58dc4e..1b3e98416 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,7 @@ "should": "~1.2.1" }, "testling": { - "browsers": [ - "ie6", "ie7", "ie8", "ie9", "iphone/6.0","ipad/6.0", - "firefox/15", "chrome/22", "opera/12", "safari/5.1" - ], + "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/4.0","chrome/5.0","chrome/6.0","chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0","chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0","chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","firefox/3.0","firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0","firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0","firefox/15.0","firefox/16.0","firefox/17.0","opera/10.0","opera/10.5","opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","firefox/nightly","opera/next","chrome/canary","iphone/6.0","ipad/6.0","safari/6.0"], "harness" : "mocha", "scripts" : "web/pubnub-3.4.2.js", "files": "web/tests/test.js" From 9fe0c33fb358c19378f9611143ab7e59f2cd8ff6 Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 8 Mar 2013 01:07:44 +0530 Subject: [PATCH 11/17] removed chrome 4 , replaced should with assert --- package.json | 2 +- web/tests/test.js | 43 +++++++------------------------------------ 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 1b3e98416..33448aa85 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "should": "~1.2.1" }, "testling": { - "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/4.0","chrome/5.0","chrome/6.0","chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0","chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0","chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","firefox/3.0","firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0","firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0","firefox/15.0","firefox/16.0","firefox/17.0","opera/10.0","opera/10.5","opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","firefox/nightly","opera/next","chrome/canary","iphone/6.0","ipad/6.0","safari/6.0"], + "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/5.0","chrome/6.0","chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0","chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0","chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","firefox/3.0","firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0","firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0","firefox/15.0","firefox/16.0","firefox/17.0","opera/10.0","opera/10.5","opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","firefox/nightly","opera/next","chrome/canary","iphone/6.0","ipad/6.0","safari/6.0"], "harness" : "mocha", "scripts" : "web/pubnub-3.4.2.js", "files": "web/tests/test.js" diff --git a/web/tests/test.js b/web/tests/test.js index 5a50320da..b12e36102 100644 --- a/web/tests/test.js +++ b/web/tests/test.js @@ -1,4 +1,4 @@ - var should = require('should'); + var assert = require('assert'); var pubnub = PUBNUB.init({ publish_key : 'demo', @@ -25,7 +25,7 @@ it('should publish strings without error', function(done){ pubnub.publish({channel: channel , message : message_string, callback : function(response) { - response[0].should.eql(1); + assert.equal(response[0],1); done(); } }) @@ -33,7 +33,7 @@ it('should publish json objects without error', function(done){ pubnub.publish({channel: channel , message : message_jsono, callback : function(response) { - response[0].should.eql(1); + assert.equal(response[0],1); done(); } }) @@ -41,7 +41,7 @@ it('should publish json arrays without error', function(done){ pubnub.publish({channel: channel , message : message_jsona, callback : function(response) { - response[0].should.eql(1); + assert.equal(response[0],1); done(); } }) @@ -49,7 +49,7 @@ it('should publish strings with encryption enabled without error', function(done){ pubnub_enc.publish({channel: channel_enc , message : message_string, callback : function(response) { - response[0].should.eql(1); + assert.equal(response[0],1); done(); } }) @@ -57,7 +57,7 @@ it('should publish json objects with encryption enabled without error', function(done){ pubnub_enc.publish({channel: channel_enc , message : message_jsono, callback : function(response) { - response[0].should.eql(1); + assert.equal(response[0],1); done(); } }) @@ -65,39 +65,10 @@ it('should publish json arrays with encryption enabled without error', function(done){ pubnub_enc.publish({channel: channel_enc , message : message_jsona, callback : function(response) { - response[0].should.eql(1); + assert.equal(response[0],1); done(); } }) }) }) - describe('#history', function(){ - var history_channel = channel + '-' + Date.now(); - this.timeout(60000); - before(function(done){ - pubnub.publish({channel: history_channel, - message : message_string, - callback : function(response){ - response[0].should.eql(1); } - }); - pubnub.publish({channel: history_channel, - message : message_string, - callback : function(response){ - response[0].should.eql(1); - done(); - } - }); - - }) - it('should return 2 messages when 2 messages were published on channel @slow', function(done) { - - pubnub.history({channel : history_channel, - callback : function(response) { - response[0].length.should.eql(2); - done(); - } - }) - }) - }) - }) From ee67694adbbb2eaf24da4f973ec97d44dc3db054 Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 8 Mar 2013 01:14:37 +0530 Subject: [PATCH 12/17] removing should from dependency, replaced with asserts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33448aa85..c2409e46a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "devDependencies": { "mocha": "~1.7.4", - "should": "~1.2.1" + "asserts": "~3.1.0" }, "testling": { "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/5.0","chrome/6.0","chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0","chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0","chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","firefox/3.0","firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0","firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0","firefox/15.0","firefox/16.0","firefox/17.0","opera/10.0","opera/10.5","opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","firefox/nightly","opera/next","chrome/canary","iphone/6.0","ipad/6.0","safari/6.0"], From 7e255236b1dc03840bd71fff38912d25bf2199f8 Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 8 Mar 2013 01:17:25 +0530 Subject: [PATCH 13/17] fixed typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2409e46a..cde5bc169 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "devDependencies": { "mocha": "~1.7.4", - "asserts": "~3.1.0" + "assert": "~0.4.9" }, "testling": { "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/5.0","chrome/6.0","chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0","chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0","chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","firefox/3.0","firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0","firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0","firefox/15.0","firefox/16.0","firefox/17.0","opera/10.0","opera/10.5","opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","firefox/nightly","opera/next","chrome/canary","iphone/6.0","ipad/6.0","safari/6.0"], From 626d82597903785b32b1a29bebf49e107765075c Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 8 Mar 2013 01:26:47 +0530 Subject: [PATCH 14/17] reduced browsers list --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cde5bc169..56e8bd2ec 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "assert": "~0.4.9" }, "testling": { - "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/5.0","chrome/6.0","chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0","chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0","chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","firefox/3.0","firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0","firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0","firefox/15.0","firefox/16.0","firefox/17.0","opera/10.0","opera/10.5","opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","firefox/nightly","opera/next","chrome/canary","iphone/6.0","ipad/6.0","safari/6.0"], + "browsers": ["iexplore/6.0","chrome/20.0","chrome/21.0","chrome/22.0"], "harness" : "mocha", "scripts" : "web/pubnub-3.4.2.js", "files": "web/tests/test.js" From aefa1edbc87e074074b455dfbff4195ebb598235 Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 8 Mar 2013 02:01:34 +0530 Subject: [PATCH 15/17] testing --- web/tests/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/tests/test.js b/web/tests/test.js index b12e36102..b170fcadf 100644 --- a/web/tests/test.js +++ b/web/tests/test.js @@ -1,5 +1,6 @@ var assert = require('assert'); + var pubnub = PUBNUB.init({ publish_key : 'demo', subscribe_key : 'demo' @@ -71,4 +72,4 @@ }) }) }) -}) + }) From bc2705b3abb5446b812af806e3df60686147bbe7 Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 13 Mar 2013 14:26:34 +0530 Subject: [PATCH 16/17] trying to get testling working --- empty.js | 0 web/tests/test.js | 1 + 2 files changed, 1 insertion(+) create mode 100644 empty.js diff --git a/empty.js b/empty.js new file mode 100644 index 000000000..e69de29bb diff --git a/web/tests/test.js b/web/tests/test.js index b170fcadf..6d39e824a 100644 --- a/web/tests/test.js +++ b/web/tests/test.js @@ -1,3 +1,4 @@ + var empty = require('../../../empty'); var assert = require('assert'); From c68395931865dd5ba25c4392711350cc70da47c8 Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 13 Mar 2013 21:41:42 +0530 Subject: [PATCH 17/17] adding more browsers --- package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 56e8bd2ec..d4aa1c771 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,14 @@ "assert": "~0.4.9" }, "testling": { - "browsers": ["iexplore/6.0","chrome/20.0","chrome/21.0","chrome/22.0"], + "browsers": ["iexplore/6.0","iexplore/7.0","iexplore/8.0","iexplore/10.0","iexplore/9.0","chrome/6.0", + "chrome/7.0","chrome/8.0","chrome/9.0","chrome/10.0","chrome/11.0", + "chrome/12.0","chrome/13.0","chrome/14.0","chrome/15.0","chrome/16.0","chrome/17.0","chrome/18.0", + "chrome/19.0","chrome/20.0","chrome/21.0","chrome/22.0","chrome/23.0","chrome/24.0","chrome/25.0", + "firefox/3.5","firefox/3.6","firefox/4.0","firefox/5.0","firefox/6.0","firefox/7.0", + "firefox/8.0","firefox/9.0","firefox/10.0","firefox/11.0","firefox/12.0","firefox/13.0","firefox/14.0", + "firefox/15.0","firefox/16.0","firefox/17.0","firefox/18.0","firefox/19.0","opera/10.0","opera/10.5", + "opera/11.0","opera/11.5","opera/11.6","opera/12.0","safari/5.0.5","safari/5.1","iphone/6.0","ipad/6.0","safari/6.0"], "harness" : "mocha", "scripts" : "web/pubnub-3.4.2.js", "files": "web/tests/test.js"