Skip to content

Commit

Permalink
Properly modify channel for child hub subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Aug 31, 2010
1 parent 3b5879e commit a6f5799
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit a6f5799

Please sign in to comment.