@@ -66,8 +66,9 @@ function parse_frame(chunk) {
66
66
body = null ,
67
67
headers_str = null ;
68
68
69
- if ( ! utils . really_defined ( chunk ) )
69
+ if ( ! utils . really_defined ( chunk ) ) {
70
70
return null ;
71
+ }
71
72
72
73
command = parse_command ( chunk ) ;
73
74
data = chunk . slice ( command . length + 1 , chunk . length ) ;
@@ -77,8 +78,9 @@ function parse_frame(chunk) {
77
78
headers = parse_headers ( the_rest [ 0 ] ) ;
78
79
body = the_rest . slice ( 1 , the_rest . length ) ;
79
80
80
- if ( 'content-length' in headers )
81
+ if ( 'content-length' in headers ) {
81
82
headers [ 'bytes_message' ] = true ;
83
+ }
82
84
83
85
args = {
84
86
command : command ,
@@ -108,7 +110,8 @@ function _connect(stomp) {
108
110
}
109
111
_setupListeners ( stomp ) ;
110
112
} ) ;
111
- } else {
113
+ }
114
+ else {
112
115
log . debug ( 'Connecting to ' + stomp . host + ':' + stomp . port ) ;
113
116
stomp . socket = new net . Socket ( ) ;
114
117
stomp . socket . connect ( stomp . port , stomp . host ) ;
@@ -198,15 +201,20 @@ function stomp_connect(stomp, headers) {
198
201
function _disconnect ( stomp ) {
199
202
var socket = stomp . socket ;
200
203
socket . end ( ) ;
201
- if ( socket . readyState == 'readOnly' )
204
+
205
+ if ( socket . readyState == 'readOnly' ) {
202
206
socket . destroy ( ) ;
207
+ }
208
+
203
209
log . debug ( 'disconnect called' ) ;
204
210
} ;
205
211
206
212
function send_command ( stomp , command , headers , body , want_receipt ) {
207
213
var want_receipt = want_receipt || false ;
208
- if ( ! utils . really_defined ( headers ) )
214
+
215
+ if ( ! utils . really_defined ( headers ) ) {
209
216
headers = { } ;
217
+ }
210
218
211
219
var args = {
212
220
'command' : command ,
@@ -239,7 +247,7 @@ function send_frame(stomp, _frame) {
239
247
//
240
248
function Stomp ( args ) {
241
249
this . port = args [ 'port' ] || 61613 ;
242
- this . host = args [ 'host' ] || " 127.0.0.1" ;
250
+ this . host = args [ 'host' ] || ' 127.0.0.1' ;
243
251
this . debug = args [ 'debug' ] ;
244
252
this . login = args [ 'login' ] || null ;
245
253
this . passcode = args [ 'passcode' ] || null ;
@@ -263,6 +271,31 @@ Stomp.prototype.connect = function() {
263
271
_connect ( this ) ;
264
272
} ;
265
273
274
+ // ## Stomp.is_a_message(frame)
275
+ //
276
+ // **Test that `Frame` is a message**
277
+ //
278
+ // Takes a `Frame` object
279
+ //
280
+ Stomp . prototype . is_a_message = function ( this_frame ) {
281
+ return ( this_frame . headers !== null && utils . really_defined ( this_frame . headers [ 'message-id' ] ) )
282
+ }
283
+
284
+ // ## Stomp.should_run_message_callback
285
+ //
286
+ // **Handle any registered message callbacks**
287
+ //
288
+ // Takes a `Frame` object
289
+ //
290
+ Stomp . prototype . should_run_message_callback = function ( this_frame ) {
291
+ var subscription = this . _subscribed_to [ this_frame . headers . destination ] ;
292
+ if ( this_frame . headers . destination !== null && subscription !== null ) {
293
+ if ( subscription . enabled && subscription . callback !== null && typeof ( subscription . callback ) == 'function' ) {
294
+ subscription . callback ( this_frame . body , this_frame . headers ) ;
295
+ }
296
+ }
297
+ }
298
+
266
299
// ## Stomp.handle\_new_frame(frame)
267
300
//
268
301
// **Handle frame based on type. Emit events when needed.**
@@ -272,16 +305,10 @@ Stomp.prototype.connect = function() {
272
305
Stomp . prototype . handle_new_frame = function ( this_frame ) {
273
306
switch ( this_frame . command ) {
274
307
case "MESSAGE" :
275
- if ( utils . really_defined ( this_frame . headers [ 'message-id' ] ) ) {
276
- if ( this_frame . headers !== null && this_frame . headers . destination !== null && this . _subscribed_to [ this_frame . headers . destination ] !== null ) {
277
- var subscription = this . _subscribed_to [ this_frame . headers . destination ] ;
278
- if ( subscription . enabled && subscription . callback !== null && typeof ( subscription . callback ) == 'function' ) {
279
- subscription . callback ( this_frame . body , this_frame . headers ) ;
280
- }
281
- }
308
+ if ( this . is_a_message ( this_frame ) ) {
309
+ this . should_run_message_callback ( this_frame ) ;
282
310
this . emit ( 'message' , this_frame ) ;
283
311
}
284
-
285
312
break ;
286
313
case "CONNECTED" :
287
314
log . debug ( 'Connected to STOMP' ) ;
0 commit comments