Permalink
Browse files

added webOS Push API for PubNub Real-time Cloud-Hosted Messaging Serv…

…ice.
  • Loading branch information...
1 parent fc962ed commit 5d5a48e7f907617cabbfdc35a5095df87545628f @stephenlb stephenlb committed Feb 10, 2011
Showing with 858 additions and 0 deletions.
  1. +99 −0 javascript-webos/README
  2. +745 −0 javascript-webos/pubnub.js
  3. +14 −0 javascript-webos/pubnub.min.js
View
99 javascript-webos/README
@@ -0,0 +1,99 @@
+## ---------------------------------------------------
+##
+## YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
+## http://www.pubnub.com/account-javascript-api-include
+##
+## USE "DEMO" INCLUDES (BELOW) FREE! WHILE DEVELOPING
+##
+## ----------------------------------------------------
+
+## ------------------------------------------------------
+## PubNub 3.1 Real-time Cloud Push API - JAVASCRIPT webOS
+## ------------------------------------------------------
+##
+## www.pubnub.com - PubNub Real-time Push Service in the Cloud.
+## http://www.pubnub.com/tutorial/javascript-push-api
+##
+## PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
+## This is a cloud-based service for broadcasting Real-time messages
+## to thousands of web and mobile clients simultaneously.
+
+<!-- ============================= -->
+<!-- INCLUDE SCRIPT PREFERED STYLE -->
+<!-- ============================= -->
+<script src=pubnub.min.js></script>
+<script>(function(){
+ // ----------------------------------
+ // INIT PUBNUB
+ // ----------------------------------
+ var pubnub = PUBNUB.init({
+ publish_key : 'demo',
+ subscribe_key : 'demo',
+ ssl : false,
+ origin : 'pubsub.pubnub.com'
+ });
+
+ // ----------------------------------
+ // LISTEN FOR MESSAGES
+ // ----------------------------------
+ pubnub.subscribe({
+ channel : 'test',
+ callback : function(message) {
+ console.log(JSON.stringify(message));
+ },
+ error : function() {
+ // The internet is gone.
+ console.log("Connection Lost");
+ }
+ });
+
+ // ----------------------------------
+ // SEND MESSAGE
+ // ----------------------------------
+ setInterval( function() {
+ pubnub.publish({
+ channel : 'test',
+ message : { example : "Hello World!" },
+ callback : function(info) {
+ if (info[0])
+ console.log("Successfully Sent Message!");
+ else
+ // The internet is gone.
+ console.log("Failed! -> " + info[1]);
+ }
+ });
+ }, 1000 );
+})();</script>
+
+<!-- ============================= -->
+<!-- SIMPLE EXAMPLE USE PUBNUB API -->
+<!-- ============================= -->
+<script>
+ // ----------------------------------
+ // INIT PUBNUB
+ // ----------------------------------
+ var pubnub = PUBNUB.init({
+ publish_key : 'demo',
+ subscribe_key : 'demo',
+ ssl : false,
+ origin : 'pubsub.pubnub.com'
+ });
+
+
+ // -------------------
+ // LISTEN FOR MESSAGES
+ // -------------------
+ pubnub.subscribe({
+ channel : "hello_world",
+ callback : function(message) { alert(message) }
+ })
+
+ // ------------
+ // SEND MESSAGE
+ // ------------
+ pubnub.publish({
+ channel : "hello_world",
+ message : "Hi."
+ })
+
+</script>
View
745 javascript-webos/pubnub.js
@@ -0,0 +1,745 @@
+/* ---------------------------------------------------------------------------
+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 TopMambo 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.
+--------------------------------------------------------------------------- */
+
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+/* =-========================= JSON =============================-= */
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+
+(window['JSON'] && window['JSON']['stringify']) || (function () {
+ window['JSON'] || (window['JSON'] = {});
+
+ function f(n) {
+ return n < 10 ? '0' + n : n;
+ }
+
+ if (typeof String.prototype.toJSON !== 'function') {
+ String.prototype.toJSON =
+ Number.prototype.toJSON =
+ Boolean.prototype.toJSON = function (key) {
+ return this.valueOf();
+ };
+ }
+
+ 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,
+ mind = gap,
+ partial,
+ value = holder[key];
+
+ if (value && typeof value === 'object' &&
+ typeof value.toJSON === 'function') {
+ value = value.toJSON(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+')')};
+ }
+}());
+
+
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+/* =-======================= DOM UTIL ===========================-= */
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+
+window['PUBNUB'] || (function() {
+
+/**
+ * CONSOLE COMPATIBILITY
+ */
+window.console||(window.console=window.console||{});
+console.log||(console.log=((window.opera||{}).postError||function(){}));
+
+/**
+ * UTIL LOCALS
+ */
+var NOW = 1
+, MAGIC = /\$?{([\w\-]+)}/g
+, ASYNC = 'async'
+, URLBIT = '/'
+, XHRTME = 140000
+, XORIGN = 1;
+
+/**
+ * UNIQUE
+ * ======
+ * var timestamp = unique();
+ */
+function unique() { return'x'+ ++NOW+''+(+new Date) }
+
+/**
+ * $
+ * =
+ * var div = $('divid');
+ */
+function $(id) { return document.getElementById(id) }
+
+/**
+ * LOG
+ * ===
+ * log('message');
+ */
+function log(message) { console['log'](message) }
+
+/**
+ * SEARCH
+ * ======
+ * var elements = search('a div span');
+ */
+function search(elements) {
+ var list = [];
+ each( elements.split(/\s+/), function(el) {
+ each( document.getElementsByTagName(el), function(node) {
+ list.push(node);
+ } );
+ } );
+ return list;
+}
+
+/**
+ * EACH
+ * ====
+ * each( [1,2,3], function(item) { console.log(item) } )
+ */
+function each( o, f ) {
+ if ( !o || !f ) return;
+
+ if ( typeof o[0] != 'undefined' ) for ( var i = 0, l = o.length; i < l; )
+ f.call( o[i], o[i], i++ );
+ else for ( var i in o )
+ o.hasOwnProperty &&
+ o.hasOwnProperty(i) &&
+ f.call( o[i], i, o[i] );
+}
+
+/**
+ * MAP
+ * ===
+ * var list = map( [1,2,3], function(item) { return item + 1 } )
+ */
+function map( list, fun ) {
+ var fin = [];
+ each( list || [], function( k, v ) { fin.push(fun( k, v )) } );
+ return fin;
+}
+
+/**
+ * GREP
+ * ====
+ * var list = grep( [1,2,3], function(item) { return item % 2 } )
+ */
+function grep( list, fun ) {
+ var fin = [];
+ each( list || [], function(l) { fun(l) && fin.push(l) } );
+ return fin
+}
+
+/**
+ * SUPPLANT
+ * ========
+ * var text = supplant( 'Hello {name}!', { name : 'John' } )
+ */
+function supplant( str, values ) {
+ return str.replace( MAGIC, function( _, match ) {
+ return ''+values[match] || ''
+ } );
+}
+
+/**
+ * BIND
+ * ====
+ * bind( 'keydown', search('a')[0], function(element) {
+ * console.log( element, '1st anchor' )
+ * } );
+ */
+function bind( type, el, fun ) {
+ each( type.split(','), function(etype) {
+ var rapfun = function(e) {
+ if (!e) var 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 ) }
+
+/**
+ * jsonp_cb
+ * ========
+ * var callback = jsonp_cb();
+ */
+function jsonp_cb() { return XORIGN ? 0 : unique() }
+
+/**
+ * ENCODE
+ * ======
+ * var encoded_path = encode('path');
+ */
+function encode(path) {
+ return map( (''+path).split(''), function(chr) {
+ return " ~`!@#$%^&*()+=[]\\{}|;':\",./<>?".indexOf(chr) > -1 ?
+ "%"+chr.charCodeAt(0).toString(16).toUpperCase() : chr
+ } ).join('');
+}
+
+/**
+ * XDR Cross Domain Request
+ * ========================
+ * xdr({
+ * url : ['http://www.blah.com/url'],
+ * success : function(response) {},
+ * fail : function() {}
+ * });
+ */
+function xdr( setup ) {
+ if (XORIGN) return ajax(setup);
+
+ var script = create('script')
+ , callback = setup.callback
+ , id = unique()
+ , finished = 0
+ , 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);
+ }, 1000 );
+ };
+
+ window[callback] = function(response) {
+ done( 0, response );
+ };
+
+ script[ASYNC] = ASYNC;
+ script.onerror = function() { done(1) };
+ script.src = setup.url.join(URLBIT);
+
+ 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
+ , finished = function() {
+ if (loaded) return;
+ loaded = 1;
+
+ clearTimeout(timer);
+
+ try { response = JSON['parse'](xhr.responseText); }
+ catch (r) { return done(1); }
+
+ success(response);
+ }
+ , complete = 0
+ , loaded = 0
+ , timer = timeout( function(){done(1)}, XHRTME )
+ , fail = setup.fail || function(){}
+ , success = setup.success || function(){}
+ , done = function(failed) {
+ if (complete) return;
+ complete = 1;
+
+ clearTimeout(timer);
+
+ if (xhr) {
+ xhr.onerror = xhr.onload = null;
+ xhr.abort && xhr.abort();
+ xhr = null;
+ }
+
+ failed && fail();
+ };
+
+ // Send
+ try {
+ xhr = window.XDomainRequest &&
+ new XDomainRequest() ||
+ new XMLHttpRequest();
+
+ xhr.onerror = function(){ done(1) };
+ xhr.onload = finished;
+ xhr.timeout = XHRTME;
+
+ xhr.open( 'GET', setup.url.join(URLBIT), true );
+ xhr.send();
+ }
+ catch(eee) {
+ done(0);
+ XORIGN = 0;
+ return xdr(setup);
+ }
+
+ // Return 'done'
+ return done;
+}
+
+
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+/* =-========================= PUBNUB ===========================-= */
+/* =-====================================================================-= */
+/* =-====================================================================-= */
+
+var DEMO = 'demo'
+, LIMIT = 1800
+, CREATE_PUBNUB = function(setup) {
+ var CHANNELS = {}
+ , PUBLISH_KEY = setup['publish_key'] || DEMO
+ , SUBSCRIBE_KEY = setup['subscribe_key'] || DEMO
+ , SSL = setup['ssl'] ? 's' : ''
+ , ORIGIN = 'http'+SSL+'://'+(setup['origin']||'pubsub.pubnub.com')
+ , SELF = {
+ /*
+ PUBNUB.history({
+ channel : 'my_chat_channel',
+ limit : 100,
+ callback : function(messages) { console.log(messages) }
+ });
+ */
+ 'history' : function( args, callback ) {
+ var callback = args['callback'] || callback
+ , limit = args['limit'] || 100
+ , channel = args['channel']
+ , jsonp = jsonp_cb();
+
+ // Make sure we have a Channel
+ if (!channel) return log('Missing Channel');
+ if (!callback) return log('Missing Callback');
+
+ // Send Message
+ xdr({
+ callback : jsonp,
+ url : [
+ ORIGIN, 'history',
+ SUBSCRIBE_KEY, encode(channel),
+ jsonp, limit
+ ],
+ success : function(response) { callback(response) },
+ fail : function(response) { log(response) }
+ });
+ },
+
+ /*
+ PUBNUB.time(function(time){ console.log(time) });
+ */
+ 'time' : function(callback) {
+ var jsonp = jsonp_cb();
+ xdr({
+ callback : jsonp,
+ url : [ORIGIN, 'time', jsonp],
+ success : function(response) { callback(response[0]) },
+ fail : function() { callback(0) }
+ });
+ },
+
+ /*
+ PUBNUB.uuid(function(uuid) { console.log(uuid) });
+ */
+ 'uuid' : function(callback) {
+ var jsonp = jsonp_cb();
+ xdr({
+ callback : jsonp,
+ url : [
+ 'http' + SSL +
+ '://pubnub-prod.appspot.com/uuid?callback=' + 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(){}
+ , message = args['message']
+ , channel = args['channel']
+ , jsonp = jsonp_cb();
+
+ if (!message) return log('Missing Message');
+ if (!channel) return log('Missing Channel');
+ if (!PUBLISH_KEY) return log('Missing Publish Key');
+
+ // If trying to send Object
+ message = JSON['stringify'](message);
+
+ // Make sure message is small enough.
+ if (message.length > LIMIT) return log('Message Too Big');
+
+ // Send Message
+ xdr({
+ callback : jsonp,
+ success : function(response) { callback(response) },
+ fail : function() { callback([ 0, 'Disconnected' ]) },
+ url : [
+ ORIGIN, 'publish',
+ PUBLISH_KEY, SUBSCRIBE_KEY,
+ 0, encode(channel),
+ jsonp, encode(message)
+ ]
+ });
+ },
+
+ /*
+ PUBNUB.unsubscribe({ channel : 'my_chat' });
+ */
+ 'unsubscribe' : function(args) {
+ var channel = args['channel'];
+
+ // Leave if there never was a channel.
+ if (!(channel in CHANNELS)) return;
+
+ // Disable Channel
+ CHANNELS[channel].connected = 0;
+
+ // Abort and Remove Script
+ CHANNELS[channel].done &&
+ CHANNELS[channel].done(0);
+ },
+
+ /*
+ PUBNUB.subscribe({
+ channel : 'my_chat'
+ callback : function(message) { console.log(message) }
+ });
+ */
+ 'subscribe' : function( args, callback ) {
+ var channel = args['channel']
+ , callback = callback || args['callback']
+ , timetoken = 0
+ , error = args['error'] || function(){};
+
+ // Make sure we have a Channel
+ if (!channel) return log('Missing Channel');
+ if (!callback) return log('Missing Callback');
+ if (!SUBSCRIBE_KEY) return log('Missing Subscribe Key');
+
+ if (!(channel in CHANNELS)) CHANNELS[channel] = {};
+
+ // Make sure we have a Channel
+ if (CHANNELS[channel].connected) return log('Already Connected');
+ CHANNELS[channel].connected = 1;
+
+ // Recurse Subscribe
+ function pubnub() {
+ var jsonp = jsonp_cb();
+
+ // Stop Connection
+ if (!CHANNELS[channel].connected) return;
+
+ // Connect to PubNub Subscribe Servers
+ CHANNELS[channel].done = xdr({
+ callback : jsonp,
+ url : [
+ ORIGIN, 'subscribe',
+ SUBSCRIBE_KEY, encode(channel),
+ jsonp, timetoken
+ ],
+ fail : function() { timeout( pubnub, 1000 ); error() },
+ success : function(message) {
+ if (!CHANNELS[channel].connected) return;
+ timetoken = message[1];
+ timeout( pubnub, 10 );
+ each( message[0], function(msg) { callback(msg) } );
+ }
+ });
+ }
+
+ // Begin Recursive Subscribe
+ pubnub();
+ },
+
+ /*
+ // A Clean No Conflict API (Remove PUBNUB Global)
+ PUBNUB.clean(true)(function(PUBNUB){
+ PUBNUB.subscribe({...})
+ PUBNUB.publish({...})
+ });
+ */
+ 'clean' : function(remove) {
+ return function(cbready) {
+ var ret = cbready(SELF);
+ if (remove) delete window['PUBNUB'];
+ return ret || SELF;
+ };
+ },
+
+ // Expose PUBNUB Functions
+ 'each' : each,
+ 'map' : map,
+ 'css' : css,
+ '$' : $,
+ 'create' : create,
+ 'bind' : bind,
+ 'supplant' : supplant,
+ 'head' : head,
+ 'search' : search,
+ 'attr' : attr,
+ 'now' : unique,
+ 'init' : CREATE_PUBNUB
+ };
+
+ return SELF;
+},
+PUBNUB = CREATE_PUBNUB({
+ 'publish_key' : DEMO,
+ 'subscribe_key' : DEMO,
+ 'ssl' : false,
+ 'origin' : 'pubsub.pubnub.com'
+});
+
+// Provide Global Interfaces
+window['jQuery'] && (window['jQuery']['PUBNUB'] = PUBNUB);
+window['PUBNUB'] = PUBNUB;
+
+})();
View
14 javascript-webos/pubnub.min.js
@@ -0,0 +1,14 @@
+function z(){return function(){}}
+window.JSON&&window.JSON.stringify||function(){function D(p){E.lastIndex=0;return E.test(p)?'"'+p.replace(E,function(q){var j=x[q];return typeof j==="string"?j:"\\u"+("0000"+q.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+p+'"'}function r(p,q){var j,n,t,A,w=g,m,h=q[p];if(h&&typeof h==="object"&&typeof h.toJSON==="function")h=h.toJSON(p);if(typeof u==="function")h=u.call(q,p,h);switch(typeof h){case "string":return D(h);case "number":return isFinite(h)?String(h):"null";case "boolean":case "null":return String(h);
+case "object":if(!h)return"null";g+=B;m=[];if(Object.prototype.toString.apply(h)==="[object Array]"){A=h.length;for(j=0;j<A;j+=1)m[j]=r(j,h)||"null";t=m.length===0?"[]":g?"[\n"+g+m.join(",\n"+g)+"\n"+w+"]":"["+m.join(",")+"]";g=w;return t}if(u&&typeof u==="object"){A=u.length;for(j=0;j<A;j+=1){n=u[j];if(typeof n==="string")if(t=r(n,h))m.push(D(n)+(g?": ":":")+t)}}else for(n in h)if(Object.hasOwnProperty.call(h,n))if(t=r(n,h))m.push(D(n)+(g?": ":":")+t);t=m.length===0?"{}":g?"{\n"+g+m.join(",\n"+g)+
+"\n"+w+"}":"{"+m.join(",")+"}";g=w;return t}}window.JSON||(window.JSON={});if(typeof String.prototype.toJSON!=="function")String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()};var E=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,g,B,x={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},u;if(typeof JSON.stringify!=="function")JSON.stringify=
+function(p,q,j){var n;B=g="";if(typeof j==="number")for(n=0;n<j;n+=1)B+=" ";else if(typeof j==="string")B=j;if((u=q)&&typeof q!=="function"&&(typeof q!=="object"||typeof q.length!=="number"))throw Error("JSON.stringify");return r("",{"":p})};if(typeof JSON.parse!=="function")JSON.parse=function(p){return eval("("+p+")")}}();
+window.PUBNUB||function(){function D(b){var a={},c=b.publish_key||"demo",d=b.subscribe_key||"demo",o=b.ssl?"s":"",k="http"+o+"://"+(b.origin||"pubsub.pubnub.com"),y={history:function(e,f){f=e.callback||f;var i=e.limit||100,l=e.channel,s=C?0:r();if(!l)return g("Missing Channel");if(!f)return g("Missing Callback");m({c:s,url:[k,"history",d,w(l),s,i],b:function(v){f(v)},a:function(v){g(v)}})},time:function(e){var f=C?0:r();m({c:f,url:[k,"time",f],b:function(i){e(i[0])},a:function(){e(0)}})},uuid:function(e){var f=
+C?0:r();m({c:f,url:["http"+o+"://pubnub-prod.appspot.com/uuid?callback="+f],b:function(i){e(i[0])},a:function(){e(0)}})},publish:function(e,f){f=f||e.callback||z();var i=e.message,l=e.channel,s=C?0:r();if(!i)return g("Missing Message");if(!l)return g("Missing Channel");if(!c)return g("Missing Publish Key");i=JSON.stringify(i);if(i.length>1800)return g("Message Too Big");m({c:s,b:function(v){f(v)},a:function(){f([0,"Disconnected"])},url:[k,"publish",c,d,0,w(l),s,w(i)]})},unsubscribe:function(e){e=
+e.channel;if(e in a){a[e].d=0;a[e].e&&a[e].e(0)}},subscribe:function(e,f){function i(){var G=C?0:r();if(a[l].d)a[l].e=m({c:G,url:[k,"subscribe",d,w(l),G,s],a:function(){setTimeout(i,1E3);v()},b:function(H){if(a[l].d){s=H[1];setTimeout(i,10);x(H[0],function(L){f(L)})}}})}var l=e.channel;f=f||e.callback;var s=0,v=e.error||z();if(!l)return g("Missing Channel");if(!f)return g("Missing Callback");if(!d)return g("Missing Subscribe Key");l in a||(a[l]={});if(a[l].d)return g("Already Connected");a[l].d=1;
+i()},clean:function(e){return function(f){f=f(y);e&&delete window.PUBNUB;return f||y}},each:x,map:u,css:t,$:E,create:A,bind:q,supplant:p,head:j,search:B,attr:n,now:r,init:D};return y}function r(){return"x"+ ++M+""+ +new Date}function E(b){return document.getElementById(b)}function g(b){console.log(b)}function B(b){var a=[];x(b.split(/\s+/),function(c){x(document.getElementsByTagName(c),function(d){a.push(d)})});return a}function x(b,a){if(b&&a)if(typeof b[0]!="undefined")for(var c=0,d=b.length;c<
+d;)a.call(b[c],b[c],c++);else for(c in b)b.hasOwnProperty&&b.hasOwnProperty(c)&&a.call(b[c],c,b[c])}function u(b,a){var c=[];x(b||[],function(d,o){c.push(a(d,o))});return c}function p(b,a){return b.replace(N,function(c,d){return""+a[d]||""})}function q(b,a,c){x(b.split(","),function(d){function o(k){if(!k)k=window.event;if(!c(k)){k.cancelBubble=true;k.returnValue=false;k.preventDefault&&k.preventDefault();k.stopPropagation&&k.stopPropagation()}}if(a.addEventListener)a.addEventListener(d,o,false);
+else if(a.attachEvent)a.attachEvent("on"+d,o);else a["on"+d]=o})}function j(){return B("head")[0]}function n(b,a,c){if(c)b.setAttribute(a,c);else return b&&b.getAttribute&&b.getAttribute(a)}function t(b,a){for(var c in a)if(a.hasOwnProperty(c))try{b.style[c]=a[c]+("|width|height|top|left|".indexOf(c)>0&&typeof a[c]=="number"?"px":"")}catch(d){}}function A(b){return document.createElement(b)}function w(b){return u((""+b).split(""),function(a){return" ~`!@#$%^&*()+=[]\\{}|;':\",./<>?".indexOf(a)>-1?
+"%"+a.charCodeAt(0).toString(16).toUpperCase():a}).join("")}function m(b){function a(i,l){if(!k){k=1;i||f(l);c.onerror=null;clearTimeout(y);setTimeout(function(){i&&e();var s=E(o),v=s&&s.parentNode;v&&v.removeChild(s)},1E3)}}if(C)return h(b);var c=A("script"),d=b.c,o=r(),k=0,y=setTimeout(function(){a(1)},F),e=b.a||z(),f=b.b||z();window[d]=function(i){a(0,i)};c[I]=I;c.onerror=function(){a(1)};c.src=b.url.join(J);n(c,"id",o);j().appendChild(c);return a}function h(b){function a(l){if(!o){o=1;clearTimeout(y);
+if(d){d.onerror=d.onload=null;d.abort&&d.abort();d=null}l&&e()}}function c(){if(!k){k=1;clearTimeout(y);try{response=JSON.parse(d.responseText)}catch(l){return a(1)}f(response)}}var d,o=0,k=0,y=setTimeout(function(){a(1)},F),e=b.a||z(),f=b.b||z();try{d=window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest;d.onerror=function(){a(1)};d.onload=c;d.timeout=F;d.open("GET",b.url.join(J),true);d.send()}catch(i){a(0);C=0;return m(b)}return a}window.console||(window.console=window.console||{});console.log||
+(console.log=(window.opera||{}).postError||z());var M=1,N=/\$?{([\w\-]+)}/g,I="async",J="/",F=14E4,C=1,K=D({publish_key:"demo",subscribe_key:"demo",ssl:false,origin:"pubsub.pubnub.com"});window.jQuery&&(window.jQuery.PUBNUB=K);window.PUBNUB=K}();

0 comments on commit 5d5a48e

Please sign in to comment.