app/assets/javascripts/faye-authentication.js in faye-authentication-0.4.0 vs app/assets/javascripts/faye-authentication.js in faye-authentication-1.6.0

- old
+ new

@@ -1,10 +1,11 @@ -function FayeAuthentication(client, endpoint) { +function FayeAuthentication(client, endpoint, options) { this._client = client; this._endpoint = endpoint || '/faye/auth'; this._signatures = {}; this._outbox = {}; + this._options = options || {}; } FayeAuthentication.prototype.endpoint = function() { return (this._endpoint); }; @@ -47,30 +48,36 @@ else callback(message); }; FayeAuthentication.prototype.authentication_required = function(message) { - var subscription_or_channel = message.subscription || message.channel - return (!this.public_channel(subscription_or_channel) && (message.channel == '/meta/subscribe' || message.channel.lastIndexOf('/meta/', 0) !== 0)) -}; - -FayeAuthentication.prototype.public_channel = function(channel) { - if (channel.lastIndexOf('/public/', 0) === 0) { - return (channel.indexOf('*') == -1); - } else { + var subscription_or_channel = message.subscription || message.channel; + if (message.channel == '/meta/subscribe' || message.channel.lastIndexOf('/meta/', 0) !== 0) + if(this._options.whitelist) { + try { + return (!this._options.whitelist(subscription_or_channel)); + } catch (e) { + this.error("Error caught when evaluating whitelist function : " + e.message); + } + } else + return (true); + else return (false); - } }; FayeAuthentication.prototype.incoming = function(message, callback) { var outbox_message = this._outbox[message.id]; if (outbox_message && message.error) { var channel = outbox_message.message.subscription || outbox_message.message.channel; this._signatures[outbox_message.clientId][channel] = null; outbox_message.message.retried = true; delete outbox_message.message.id; delete this._outbox[message.id]; - this._client._send(outbox_message.message, callback); + this._client._sendMessage(outbox_message.message, {}, callback); } else callback(message); }; + +$(function() { + Faye.extend(FayeAuthentication.prototype, Faye.Logging); +});