Skip to content

Commit

Permalink
Merge git://github.com/Quantivo/tunguska
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jul 6, 2011
2 parents 3a295da + 2f4e084 commit 914a63a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -57,6 +57,16 @@ or we can use double asterisk for recursive wildcard, to subscribe to everything

hub.subscribe("**", listenerFunction);

In addition, we can use tagged subscriptions to subscribe to a subset of tagged messages on a channel:

hub.subscribe("name/of/*:tagname", listenerFunction);

Using tags requires that objects are published with a tag:

hub.publish("name/of/channel:tagname", {foo:"bar"});

Messages that are published with a tag will be sent to all subscribers that are subscribed to a matching tag, or that are subscribed to the base channel without a tag.

Tunguska also supports named event sub-types within each channel. The subscribe
function takes an optional second parameter for specifying a specific event type
to listen for. For example,
Expand Down
10 changes: 9 additions & 1 deletion lib/hub.js
Expand Up @@ -28,7 +28,15 @@ exports.publish= function(channel, message){
var publishedToClients = {};
notifyAll(channel);
var index = channel.lastIndexOf("/");
channel = channel.substring(0, index + 1);
var tagSeparatorIndex = channel.lastIndexOf(":");
var pathPart = channel.substring(0, index + 1);
if(tagSeparatorIndex>index){
var idPart = channel.substring(index+1, tagSeparatorIndex);
var tagPart = channel.substring(tagSeparatorIndex);
notifyAll(pathPart+idPart);
notifyAll(pathPart+"*"+tagPart);
}
channel = pathPart;
notifyAll(channel + "*");
notifyAll(channel + "**");
while(channel){
Expand Down

0 comments on commit 914a63a

Please sign in to comment.