Skip to content

Commit

Permalink
adding support for PUBNUB({}) PUBNUB.init({})
Browse files Browse the repository at this point in the history
  • Loading branch information
Devendra committed Nov 27, 2013
1 parent ffd0429 commit 0a4a87c
Show file tree
Hide file tree
Showing 32 changed files with 1,708 additions and 1,354 deletions.
1,300 changes: 649 additions & 651 deletions core/pubnub-common.js

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions firefox-plugin/examples/pubnub-firefox-plugin/bootstrap.js
Expand Up @@ -42,7 +42,7 @@ var idPrefix = "pubnub-";

function alert(string) {
Services.prompt.alert(Services.wm.getMostRecentWindow("navigator:browser"), "", string);
}
}

var subscribed_channel;

Expand Down Expand Up @@ -77,7 +77,7 @@ function onSubscribeCommand(event) {
tag: "pubnub",
icon: "chrome://pubnub/skin/icon.png"
});
}
}
};

subscribed_channel = input_channel.value;
Expand All @@ -90,7 +90,7 @@ function onSubscribeCommand(event) {
tag: "pubnub",
icon: "chrome://pubnub/skin/icon.png"
});
};
};
}

if (result1) {
Expand Down Expand Up @@ -147,16 +147,16 @@ function loadIntoWindow(window) {
toolbar.insertItem(idPrefix + "buttonSubscribe", nextSibling);
}
window.addEventListener("aftercustomization", saveButtonPosition, false);
window.addEventListener("command", onSubscribeCommand, false);
window.addEventListener("command", onSubscribeCommand, false);
}
}

function unloadFromWindow(window) {
if (!window || window.document.documentElement.getAttribute("windowtype") != "navigator:browser")
return;
let doc = window.document;
}

var windowListener = {
onOpenWindow: function(aWindow) {
// Wait for the window to finish loading
Expand All @@ -166,7 +166,7 @@ var windowListener = {
loadIntoWindow(domWindow);
}, false);
},

onCloseWindow: function(aWindow) {},
onWindowTitleChange: function(aWindow, aTitle) {}
};
Expand All @@ -176,32 +176,32 @@ function startup(aData, aReason) {
sss.loadAndRegisterSheet(Services.io.newURI("chrome://pubnub/skin/pubnub.css", null, null), sss.USER_SHEET);

let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);

// Load into any existing windows
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
loadIntoWindow(domWindow);
}

// Load into any new windows
wm.addListener(windowListener);
init();
init();
}

function shutdown(aData, aReason) {
// When the application is shutting down we normally don't have to clean
// up any UI changes made
if (aReason == APP_SHUTDOWN)
return;

sss.unregisterSheet(Services.io.newURI("chrome://pubnub/skin/pubnub.css", null, null), sss.USER_SHEET);

let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);

// Stop listening for new windows
wm.removeListener(windowListener);

// Unload from any existing windows
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
Expand All @@ -215,7 +215,7 @@ function shutdown(aData, aReason) {
}
scopes = null;
}

function install(aData, aReason) {
Services.prefs.setCharPref(prefsPrefix + "toolbarID", "nav-bar");
var win = Services.wm.getMostRecentWindow("navigator:browser");
Expand Down
Expand Up @@ -580,7 +580,7 @@ Services.console.logStringMessage(JSON.stringify(url));
SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() {
fail : function() {
SUB_RECEIVER = null;
SELF['time'](_test_connection);
},
Expand Down
2 changes: 1 addition & 1 deletion firefox-plugin/pubnub.js
Expand Up @@ -580,7 +580,7 @@ Services.console.logStringMessage(JSON.stringify(url));
SUB_RECEIVER = xdr({
timeout : sub_timeout,
callback : jsonp,
fail : function() {
fail : function() {
SUB_RECEIVER = null;
SELF['time'](_test_connection);
},
Expand Down
82 changes: 45 additions & 37 deletions modern/pubnub.js
Expand Up @@ -186,8 +186,6 @@ function ready() { timeout( function() {
each( READY_BUFFER, function(connect) { connect() } );
}, SECOND ); }



function PN_API(setup) {
var SUB_WINDOWING = +setup['windowing'] || DEF_WINDOWING
, SUB_TIMEOUT = (+setup['timeout'] || DEF_SUB_TIMEOUT) * SECOND
Expand Down Expand Up @@ -315,9 +313,9 @@ function PN_API(setup) {
, jsonp = jsonp_cb();

// Make sure we have a Channel
if (!channel) return error_common('Missing Channel', err);
if (!callback) return error_common('Missing Callback', err);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', err);
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;
Expand Down Expand Up @@ -368,10 +366,10 @@ function PN_API(setup) {
, url;

// Check User Input
if (!source) return error_common('Missing Source Channel', err);
if (!destination) return error_common('Missing Destination Channel', err);
if (!PUBLISH_KEY) return error_common('Missing Publish Key', err);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', err);
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;
Expand Down Expand Up @@ -447,10 +445,10 @@ function PN_API(setup) {

if (args['prepend']) add_msg = 'unshift'

if(typeof(msg) === "undefined") return error_common('Missing Message', err);
if (!channel) return error_common('Missing Channel', err);
if (!PUBLISH_KEY) return error_common('Missing Publish Key', err);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', err);
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);
Expand Down Expand Up @@ -549,9 +547,9 @@ function PN_API(setup) {
TIMETOKEN = timetoken;

// Make sure we have a Channel
if (!channel) return error_common('Missing Channel', errcb);
if (!callback) return error_common('Missing Callback', errcb);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', errcb);
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(','),
Expand Down Expand Up @@ -747,9 +745,9 @@ function PN_API(setup) {
, data = { 'uuid' : UUID, 'auth' : auth_key };

// Make sure we have a Channel
if (!channel) return error_common('Missing Channel', err);
if (!callback) return error_common('Missing Callback', err);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', err);
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; }

Expand Down Expand Up @@ -794,11 +792,11 @@ function PN_API(setup) {
, auth_key = args['auth_key'];

// Make sure we have a Channel
if (!channel) return error_common('Missing Channel', err);
if (!callback) return error_common('Missing Callback', err);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', err);
if (!PUBLISH_KEY) return error_common('Missing Publish Key', err);
if (!SECRET_KEY) return error_common('Missing Secret Key', err);
if (!channel) return error('Missing Channel');
if (!callback) return error('Missing Callback');
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
if (!PUBLISH_KEY) return error('Missing Publish Key');
if (!SECRET_KEY) return error('Missing Secret Key');

if (jsonp != '0') { data['callback'] = jsonp; }

Expand All @@ -825,12 +823,12 @@ function PN_API(setup) {
'w' : w,
'r' : r,
'signature' : signature,
'channel' : channel,
'channel' : encode(channel),
'timestamp' : timestamp
};

if (ttl > -1) data['ttl'] = ttl;
if (auth_key) data['auth'] = auth_key;
if (auth_key) data['auth'] = encode(auth_key);

xdr({
callback : jsonp,
Expand Down Expand Up @@ -862,10 +860,10 @@ function PN_API(setup) {
, jsonp = jsonp_cb();

// Make sure we have a Channel
if (!callback) return error_common('Missing Callback', err);
if (!SUBSCRIBE_KEY) return error_common('Missing Subscribe Key', err);
if (!PUBLISH_KEY) return error_common('Missing Publish Key', err);
if (!SECRET_KEY) return error_common('Missing Secret Key', err);
if (!callback) return error('Missing Callback');
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
if (!PUBLISH_KEY) return error('Missing Publish Key');
if (!SECRET_KEY) return error('Missing Secret Key');

if (jsonp != '0') { data['callback'] = jsonp; }

Expand All @@ -886,8 +884,8 @@ function PN_API(setup) {

var data = { 'signature' : signature, 'timestamp' : timestamp };

if (channel) data['channel'] = channel;
if (auth_key) data['auth'] = auth_key;
if (channel) data['channel'] = encode(channel);
if (auth_key) data['auth'] = encode(auth_key);

xdr({
callback : jsonp,
Expand Down Expand Up @@ -1269,15 +1267,24 @@ function create(element) { return document.createElement(element) }
/* =-====================================================================-= */
/* =-====================================================================-= */

function PN(setup) {
function CREATE_PUBNUB(setup) {


setup['db'] = db;
setup['xdr'] = xdr;
setup['error'] = error;
var SELF = PN_API(setup);

SELF['init'] = PN;
SELF = function(setup) {
return CREATE_PUBNUB(setup);
}
var PN = PN_API(setup);
for (var prop in PN) {
if (PN.hasOwnProperty(prop)) {
SELF[prop] = PN[prop];
}
}

SELF['init'] = SELF;
SELF['$'] = $;
SELF['attr'] = attr;
SELF['search'] = search;
Expand All @@ -1301,9 +1308,10 @@ function PN(setup) {
SELF['ready']();
return SELF;
}
CREATE_PUBNUB['init'] = CREATE_PUBNUB

typeof module !== 'undefined' && (module.exports = PN) ||
typeof exports !== 'undefined' && (exports.PN = PN) || (PUBNUB = PN);
typeof module !== 'undefined' && (module.exports = CREATE_PUBNUB) ||
typeof exports !== 'undefined' && (exports.PUBNUB = CREATE_PUBNUB) || (PUBNUB = CREATE_PUBNUB);

})();
(function(){
Expand Down

0 comments on commit 0a4a87c

Please sign in to comment.