@@ -141,7 +141,7 @@ function _setupListeners(stomp) {
141
141
buffer += chunk ;
142
142
var frames = buffer . split ( '\0\n' ) ;
143
143
144
- // Temporary fix : NULL,LF is not a guranteed standard, the LF is optional, so lets deal with it. (Rauls)
144
+ // Temporary fix : NULL,LF is not a guranteed standard, the LF is optional, so lets deal with it. (Rauls)
145
145
if ( frames . length == 1 ) {
146
146
frames = buffer . split ( '\0' ) ;
147
147
}
@@ -269,8 +269,17 @@ Stomp.prototype.handle_new_frame = function(this_frame) {
269
269
270
270
switch ( this_frame . command ) {
271
271
case "MESSAGE" :
272
- if ( utils . really_defined ( this_frame . headers [ 'message-id' ] ) )
272
+ if ( utils . really_defined ( this_frame . headers [ 'message-id' ] ) ) {
273
+ // if a subscription to the destination queue exists, fire callback
274
+ if ( this_frame . headers !== null && this_frame . headers . destination !== null && self . _subscribed_to [ this_frame . headers . destination ] !== null ) {
275
+ var subscription = self . _subscribed_to [ this_frame . headers . destination ] ;
276
+ if ( subscription . enabled && subscription . callback !== null && typeof ( subscription . callback ) == 'function' ) {
277
+ subscription . callback ( this_frame . body , this_frame . headers ) ;
278
+ }
279
+ }
273
280
self . emit ( 'message' , this_frame ) ;
281
+ }
282
+
274
283
break ;
275
284
case "CONNECTED" :
276
285
log . debug ( 'Connected to STOMP' ) ;
@@ -299,12 +308,12 @@ Stomp.prototype.disconnect = function() {
299
308
* Subscribe to destination (queue or topic)
300
309
* @param {Object } headers
301
310
*/
302
- Stomp . prototype . subscribe = function ( headers ) {
311
+ Stomp . prototype . subscribe = function ( headers , callback ) {
303
312
var self = this ;
304
313
destination = headers [ 'destination' ] ;
305
314
headers [ 'session' ] = self . session ;
306
315
send_command ( this , 'SUBSCRIBE' , headers ) ;
307
- self . _subscribed_to [ destination ] = true ;
316
+ self . _subscribed_to [ destination ] = { enabled : true , callback : callback } ;
308
317
self . log . debug ( 'subscribed to: ' + destination + ' with headers ' + sys . inspect ( headers ) ) ;
309
318
} ;
310
319
@@ -317,7 +326,7 @@ Stomp.prototype.unsubscribe = function(headers) {
317
326
destination = headers [ 'destination' ] ;
318
327
headers [ 'session' ] = self . session ;
319
328
send_command ( this , 'UNSUBSCRIBE' , headers ) ;
320
- self . _subscribed_to [ destination ] = false ;
329
+ self . _subscribed_to [ destination ] . enabled = false ;
321
330
self . log . debug ( 'no longer subscribed to: ' + destination ) ;
322
331
} ;
323
332
0 commit comments