Browse files

Properly modify channel for child hub subscriptions

  • Loading branch information...
1 parent 3b5879e commit a6f5799ffe9db2579e555bc9944ae82342b0e266 @kriszyp kriszyp committed Aug 31, 2010
Showing with 25 additions and 1 deletion.
  1. +25 −1 lib/hub.js
View
26 lib/hub.js
@@ -14,6 +14,9 @@ try{
}
var clientId;
var excludeMatchingClient = true;
+exports.getSubscribers = function(){
+ return hub;
+}
exports.publish= function(channel, message){
if(!message && typeof channel === "object"){
message = channel;
@@ -205,7 +208,28 @@ exports.getMonitored = function(path){
exports.getChildHub = function(channel){
return {
publish: addPath(exports.publish),
- subscribe: addPath(exports.subscribe),
+ subscribe: addPath(function(){
+ var subscription = exports.subscribe.apply(this, arguments);
+ var originalObserve = subscription.observe;
+ var originalOn = subscription.on;
+ subscription.observe = function(callback){
+ originalObserve(function(message){
+ if(message.channel.substring(0, channel.length) == channel){
+ message.channel = message.channel.substring(channel.length + 1);
+ }
+ callback(message);
+ });
+ }
+ subscription.on = function(event, callback){
+ originalOn(event, function(message){
+ if(message.channel.substring(0, channel.length) == channel){
+ message.channel = message.channel.substring(channel.length + 1);
+ }
+ callback(message);
+ });
+ }
+ return subscription;
+ }),
unsubscribe: addPath(exports.unsubscribe),
fromClient: exports.fromClient,
getChildHub: addPath(exports.getChildHub),

0 comments on commit a6f5799

Please sign in to comment.