Skip to content

Commit

Permalink
Wildcard subscriptions support
Browse files Browse the repository at this point in the history
* add a id header when subscribing to a destination and
  find the corresponding onreceive handling by looking at the message's subscription header
* subscribers are unique for a given Stomp.client (incrementing its counter field)

closes jmesnil#1
  • Loading branch information
jmesnil committed Mar 26, 2010
1 parent 4a08f6f commit 394663d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/stomp.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
Stomp.client = function (url){

var that, ws, login, passcode;
// subscription callbacks indexed by destination
var counter = 0; // used to index subscribers
// subscription callbacks indexed by subscriber's ID
var subscriptions = {};

debug = function(str) {
Expand All @@ -81,7 +82,7 @@
if (frame.command === "CONNECTED" && that.connectCallback) {
that.connectCallback(frame);
} else if (frame.command === "MESSAGE") {
var onreceive = subscriptions[frame.headers.destination];
var onreceive = subscriptions[frame.headers.subscription];
if (onreceive) {
onreceive(frame);
}
Expand Down Expand Up @@ -137,8 +138,10 @@

that.subscribe = function(destination, callback, headers) {
var headers = headers || {};
var id = "sub-" + counter++;
headers.destination = destination;
subscriptions[destination] = callback;
headers.id = id;
subscriptions[id] = callback;
transmit("SUBSCRIBE", headers);
};

Expand Down

0 comments on commit 394663d

Please sign in to comment.