@@ -256,41 +256,38 @@ Stomp.prototype = new process.EventEmitter();
256
256
* Begin connection
257
257
*/
258
258
Stomp . prototype . connect = function ( ) {
259
- var self = this ;
260
- _connect ( self ) ;
259
+ _connect ( this ) ;
261
260
} ;
262
261
263
262
/**
264
263
* Handle frame based on type
265
264
* @param {Object } Frame Object
266
265
*/
267
266
Stomp . prototype . handle_new_frame = function ( this_frame ) {
268
- var self = this ;
269
-
270
267
switch ( this_frame . command ) {
271
268
case "MESSAGE" :
272
269
if ( utils . really_defined ( this_frame . headers [ 'message-id' ] ) ) {
273
270
// 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 ] ;
271
+ if ( this_frame . headers !== null && this_frame . headers . destination !== null && this . _subscribed_to [ this_frame . headers . destination ] !== null ) {
272
+ var subscription = this . _subscribed_to [ this_frame . headers . destination ] ;
276
273
if ( subscription . enabled && subscription . callback !== null && typeof ( subscription . callback ) == 'function' ) {
277
274
subscription . callback ( this_frame . body , this_frame . headers ) ;
278
275
}
279
276
}
280
- self . emit ( 'message' , this_frame ) ;
277
+ this . emit ( 'message' , this_frame ) ;
281
278
}
282
279
283
280
break ;
284
281
case "CONNECTED" :
285
282
log . debug ( 'Connected to STOMP' ) ;
286
- self . session = this_frame . headers [ 'session' ] ;
287
- self . emit ( 'connected' ) ;
283
+ this . session = this_frame . headers [ 'session' ] ;
284
+ this . emit ( 'connected' ) ;
288
285
break ;
289
286
case "RECEIPT" :
290
- self . emit ( 'receipt' , this_frame . headers [ 'receipt-id' ] ) ;
287
+ this . emit ( 'receipt' , this_frame . headers [ 'receipt-id' ] ) ;
291
288
break ;
292
289
case "ERROR" :
293
- self . emit ( 'error' , this_frame ) ;
290
+ this . emit ( 'error' , this_frame ) ;
294
291
break ;
295
292
default :
296
293
console . log ( "Could not parse command: " + this_frame . command ) ;
@@ -309,46 +306,42 @@ Stomp.prototype.disconnect = function() {
309
306
* @param {Object } headers
310
307
*/
311
308
Stomp . prototype . subscribe = function ( headers , callback ) {
312
- var self = this ,
313
- destination = headers [ 'destination' ] ;
314
- headers [ 'session' ] = self . session ;
309
+ var destination = headers [ 'destination' ] ;
310
+ headers [ 'session' ] = this . session ;
315
311
send_command ( this , 'SUBSCRIBE' , headers ) ;
316
- self . _subscribed_to [ destination ] = { enabled : true , callback : callback } ;
317
- self . log . debug ( 'subscribed to: ' + destination + ' with headers ' + sys . inspect ( headers ) ) ;
312
+ this . _subscribed_to [ destination ] = { enabled : true , callback : callback } ;
313
+ this . log . debug ( 'subscribed to: ' + destination + ' with headers ' + sys . inspect ( headers ) ) ;
318
314
} ;
319
315
320
316
/**
321
317
* Unsubscribe from destination (queue or topic)
322
318
* @param {Object } headers
323
319
*/
324
320
Stomp . prototype . unsubscribe = function ( headers ) {
325
- var self = this ,
326
- destination = headers [ 'destination' ] ;
327
- headers [ 'session' ] = self . session ;
321
+ var destination = headers [ 'destination' ] ;
322
+ headers [ 'session' ] = this . session ;
328
323
send_command ( this , 'UNSUBSCRIBE' , headers ) ;
329
- self . _subscribed_to [ destination ] . enabled = false ;
330
- self . log . debug ( 'no longer subscribed to: ' + destination ) ;
324
+ this . _subscribed_to [ destination ] . enabled = false ;
325
+ this . log . debug ( 'no longer subscribed to: ' + destination ) ;
331
326
} ;
332
327
333
328
/**
334
329
* Acknowledge received message
335
330
* @param {String } message id to acknowledge
336
331
*/
337
332
Stomp . prototype . ack = function ( message_id ) {
338
- var self = this ;
339
333
send_command ( this , 'ACK' , { 'message-id' : message_id } ) ;
340
- self . log . debug ( 'acknowledged message: ' + message_id ) ;
334
+ this . log . debug ( 'acknowledged message: ' + message_id ) ;
341
335
} ;
342
336
343
337
/**
344
338
* Begin transaction
345
339
* @return {String } generated transaction id
346
340
*/
347
341
Stomp . prototype . begin = function ( ) {
348
- var self = this ;
349
- transaction_id = Math . floor ( Math . random ( ) * 99999999999 ) . toString ( ) ;
342
+ var transaction_id = Math . floor ( Math . random ( ) * 99999999999 ) . toString ( ) ;
350
343
send_command ( this , 'BEGIN' , { 'transaction' : transaction_id } ) ;
351
- self . log . debug ( 'begin transaction: ' + transaction_id ) ;
344
+ this . log . debug ( 'begin transaction: ' + transaction_id ) ;
352
345
return transaction_id ;
353
346
} ;
354
347
@@ -357,19 +350,17 @@ Stomp.prototype.begin = function() {
357
350
* @param {String } transaction id generated by stomp.Stomp.begin()
358
351
*/
359
352
Stomp . prototype . commit = function ( transaction_id ) {
360
- var self = this ;
361
353
send_command ( this , 'COMMIT' , { 'transaction' : transaction_id } ) ;
362
- self . log . debug ( 'commit transaction: ' + transaction_id ) ;
354
+ this . log . debug ( 'commit transaction: ' + transaction_id ) ;
363
355
} ;
364
356
365
357
/**
366
358
* Abort transaction
367
359
* @param {String } transaction id generated by stomp.Stomp.begin()
368
360
*/
369
361
Stomp . prototype . abort = function ( transaction_id ) {
370
- var self = this ;
371
362
send_command ( this , 'ABORT' , { 'transaction' : transaction_id } ) ;
372
- self . log . debug ( 'abort transaction: ' + transaction_id ) ;
363
+ this . log . debug ( 'abort transaction: ' + transaction_id ) ;
373
364
} ;
374
365
375
366
/**
@@ -379,11 +370,10 @@ Stomp.prototype.abort = function(transaction_id) {
379
370
* @return {Object } Frame object of message sent
380
371
*/
381
372
Stomp . prototype . send = function ( headers , want_receipt ) {
382
- var self = this ,
383
- destination = headers [ 'destination' ] ,
373
+ var destination = headers [ 'destination' ] ,
384
374
body = headers [ 'body' ] || null ;
385
375
delete headers [ 'body' ] ;
386
- headers [ 'session' ] = self . session ;
376
+ headers [ 'session' ] = this . session ;
387
377
return send_command ( this , 'SEND' , headers , body , want_receipt )
388
378
} ;
389
379
0 commit comments