Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

private_pub.js changes: only load faye.js if Faye object is not present and use module pattern to prevent pollution of global namespace #51

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bc81f1e
Added basic support for using Redis engine.
zlu Feb 22, 2012
045975d
Added configuration instruction for Redis engine
zlu Feb 22, 2012
fe71d80
fixed mount point
zlu Feb 22, 2012
1f753ba
Refactor - Redis options are now passed into PrivatePub.faye_app.
zlu Feb 23, 2012
38726f8
Added some debugging
zlu Feb 23, 2012
33969eb
Changing how redis config is loaded
zlu Feb 23, 2012
00ecd3f
Setting default rails_env to be development
zlu Feb 23, 2012
298c3ed
Increased timeout to 60
zlu Feb 28, 2012
1f3728f
Fixed faye version to be 0.7.1 because thin was removed in a later ve…
zlu Feb 28, 2012
b17035c
Only sign when PrivatePub is avaiable. When thin server is down, Pri…
zlu Mar 5, 2012
ff647fa
Added logic to check in Faye server is up. Only subscribe when it is…
Mar 6, 2012
2a753a6
Revert "Added logic to check in Faye server is up. Only subscribe wh…
Mar 6, 2012
265c3bf
Added support to Faye 0.8.0.
Mar 6, 2012
b0d96ce
Actually merge redis options
Mar 6, 2012
a4dbd30
Use module pattern. Do not export buildPrivatePub function unnecessar…
vollnhals Apr 6, 2012
2790cc8
only load faye.js if Faye object is not present
vollnhals Apr 6, 2012
21f352d
only subscribe once to a channel
vollnhals Apr 20, 2012
105016d
Merge branch 'master' of https://github.com/ryanb/private_pub
vollnhals Aug 22, 2012
8e6da99
merge zlu master
vollnhals Aug 22, 2012
08b1345
do not load private_pub_redis.yml in rails
vollnhals Aug 22, 2012
28931ca
Allow configuration of server side faye server url
vollnhals Oct 31, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions app/assets/javascripts/private_pub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function buildPrivatePub(doc) {
var PrivatePub = (function (doc) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, the buildPrivatePub function should not be exposed.

var self = {
connecting: false,
fayeClient: null,
Expand All @@ -13,11 +13,15 @@ function buildPrivatePub(doc) {
self.fayeCallbacks.push(callback);
if (self.subscriptions.server && !self.connecting) {
self.connecting = true;
var script = doc.createElement("script");
script.type = "text/javascript";
script.src = self.subscriptions.server + ".js";
script.onload = self.connectToFaye;
doc.documentElement.appendChild(script);
if (typeof Faye === 'undefined') {
var script = doc.createElement("script");
script.type = "text/javascript";
script.src = self.subscriptions.server + ".js";
script.onload = self.connectToFaye;
doc.documentElement.appendChild(script);
} else {
self.connectToFaye();
}
}
}
},
Expand Down Expand Up @@ -47,10 +51,12 @@ function buildPrivatePub(doc) {
if (!self.subscriptions.server) {
self.subscriptions.server = options.server;
}
self.subscriptions[options.channel] = options;
self.faye(function(faye) {
faye.subscribe(options.channel, self.handleResponse);
});
if (!self.subscriptions[options.channel]) {
self.subscriptions[options.channel] = options;
self.faye(function(faye) {
faye.subscribe(options.channel, self.handleResponse);
});
}
},

handleResponse: function(message) {
Expand All @@ -67,6 +73,4 @@ function buildPrivatePub(doc) {
}
};
return self;
}

var PrivatePub = buildPrivatePub(document);
}(document));