Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Last active August 29, 2015 14:03
Show Gist options
  • Save PatrickJS/194fe2fa276b505c8e88 to your computer and use it in GitHub Desktop.
Save PatrickJS/194fe2fa276b505c8e88 to your computer and use it in GitHub Desktop.
Monkey patch multiple channel publishing
PUBNUB._publish = PUBNUB.publish;
PUBNUB.publish = function(body) {
var channels = body.channel;
if (typeof channels === 'string' && (/,/i).test(channels)) {
this.publish(channels.split(','));
}
if (Array.isArray(channels)) {
this.each(Array.prototype.slice.call(channels, 0), function(channel) {
body.channel = channel;
this.publish(body);
});
} else {
this._publish(body);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment