@@ -26,7 +26,6 @@ var net = require('net'),
26
26
stomp_utils = require ( './stomp-utils' ) ,
27
27
exceptions = require ( './stomp-exceptions' ) ,
28
28
utils = new stomp_utils . StompUtils ( ) ,
29
- socket = net . Stream ( ) ,
30
29
log = null ;
31
30
32
31
function parse_command ( data ) {
@@ -92,6 +91,7 @@ function parse_frame(chunk) {
92
91
} ;
93
92
94
93
function _connect ( stomp ) {
94
+ var socket = stomp . socket = net . Stream ( ) ;
95
95
log = stomp . log ;
96
96
log . debug ( 'Connecting to ' + stomp . host + ':' + stomp . port ) ;
97
97
socket . connect ( stomp . port , stomp . host ) ;
@@ -100,10 +100,10 @@ function _connect(stomp) {
100
100
log . debug ( 'Connected to socket' ) ;
101
101
if ( utils . really_defined ( stomp . login )
102
102
&& utils . really_defined ( stomp . passcode ) ) {
103
- stomp_connect ( { login : stomp . login , passcode : stomp . passcode } ) ;
103
+ stomp_connect ( stomp , { login : stomp . login , passcode : stomp . passcode } ) ;
104
104
}
105
105
else {
106
- stomp_connect ( ) ;
106
+ stomp_connect ( stomp ) ;
107
107
}
108
108
} ) ;
109
109
@@ -141,7 +141,7 @@ function _connect(stomp) {
141
141
} ) ;
142
142
} ;
143
143
144
- function stomp_connect ( headers ) {
144
+ function stomp_connect ( stomp , headers ) {
145
145
var _frame = new frame . Frame ( ) ,
146
146
args = { } ,
147
147
headers = headers || { } ;
@@ -150,18 +150,19 @@ function stomp_connect(headers) {
150
150
args [ 'headers' ] = headers ;
151
151
152
152
var frame_to_send = _frame . build_frame ( args ) ;
153
- send_frame ( frame_to_send ) ;
153
+ send_frame ( stomp , frame_to_send ) ;
154
154
log . debug ( 'Connected to STOMP' ) ;
155
155
} ;
156
156
157
- function _disconnect ( ) {
157
+ function _disconnect ( stomp ) {
158
+ var socket = stomp . socket ;
158
159
socket . end ( ) ;
159
160
if ( socket . readyState == 'readOnly' )
160
161
socket . destroy ( ) ;
161
162
log . debug ( 'disconnect called' ) ;
162
163
} ;
163
164
164
- function send_command ( command , headers , body , want_receipt ) {
165
+ function send_command ( stomp , command , headers , body , want_receipt ) {
165
166
var want_receipt = want_receipt || false ;
166
167
if ( ! utils . really_defined ( headers ) )
167
168
headers = { } ;
@@ -174,12 +175,13 @@ function send_command(command, headers, body, want_receipt) {
174
175
175
176
var _frame = new frame . Frame ( ) ;
176
177
var this_frame = _frame . build_frame ( args , want_receipt ) ;
177
- send_frame ( this_frame ) ;
178
+ send_frame ( stomp , this_frame ) ;
178
179
179
180
return this_frame ;
180
181
} ;
181
182
182
- function send_frame ( _frame ) {
183
+ function send_frame ( stomp , _frame ) {
184
+ var socket = stomp . socket ;
183
185
var frame_str = _frame . as_string ( ) ;
184
186
185
187
if ( socket . write ( frame_str ) === false ) {
@@ -246,7 +248,7 @@ Stomp.prototype.handle_new_frame = function(this_frame) {
246
248
* Disconnect from STOMP broker
247
249
*/
248
250
Stomp . prototype . disconnect = function ( ) {
249
- _disconnect ( ) ;
251
+ _disconnect ( this ) ;
250
252
}
251
253
252
254
/**
@@ -257,7 +259,7 @@ Stomp.prototype.subscribe = function(headers) {
257
259
var self = this ;
258
260
destination = headers [ 'destination' ] ;
259
261
headers [ 'session' ] = self . session ;
260
- send_command ( 'SUBSCRIBE' , headers ) ;
262
+ send_command ( this , 'SUBSCRIBE' , headers ) ;
261
263
self . _subscribed_to [ destination ] = true ;
262
264
self . log . debug ( 'subscribed to: ' + destination + ' with headers ' + sys . inspect ( headers ) ) ;
263
265
} ;
@@ -270,7 +272,7 @@ Stomp.prototype.unsubscribe = function(headers) {
270
272
var self = this ;
271
273
destination = headers [ 'destination' ] ;
272
274
headers [ 'session' ] = self . session ;
273
- send_command ( 'UNSUBSCRIBE' , headers ) ;
275
+ send_command ( this , 'UNSUBSCRIBE' , headers ) ;
274
276
self . _subscribed_to [ destination ] = false ;
275
277
self . log . debug ( 'no longer subscribed to: ' + destination ) ;
276
278
} ;
@@ -281,7 +283,7 @@ Stomp.prototype.unsubscribe = function(headers) {
281
283
*/
282
284
Stomp . prototype . ack = function ( message_id ) {
283
285
var self = this ;
284
- send_command ( 'ACK' , { 'message-id' : message_id } ) ;
286
+ send_command ( this , 'ACK' , { 'message-id' : message_id } ) ;
285
287
self . log . debug ( 'acknowledged message: ' + message_id ) ;
286
288
} ;
287
289
@@ -292,7 +294,7 @@ Stomp.prototype.ack = function(message_id) {
292
294
Stomp . prototype . begin = function ( ) {
293
295
var self = this ;
294
296
transaction_id = Math . floor ( Math . random ( ) * 99999999999 ) . toString ( ) ;
295
- send_command ( 'BEGIN' , { 'transaction' : transaction_id } ) ;
297
+ send_command ( this , 'BEGIN' , { 'transaction' : transaction_id } ) ;
296
298
self . log . debug ( 'begin transaction: ' + transaction_id ) ;
297
299
return transaction_id ;
298
300
} ;
@@ -303,7 +305,7 @@ Stomp.prototype.begin = function() {
303
305
*/
304
306
Stomp . prototype . commit = function ( transaction_id ) {
305
307
var self = this ;
306
- send_command ( 'COMMIT' , { 'transaction' : transaction_id } ) ;
308
+ send_command ( this , 'COMMIT' , { 'transaction' : transaction_id } ) ;
307
309
self . log . debug ( 'commit transaction: ' + transaction_id ) ;
308
310
} ;
309
311
@@ -313,7 +315,7 @@ Stomp.prototype.commit = function(transaction_id) {
313
315
*/
314
316
Stomp . prototype . abort = function ( transaction_id ) {
315
317
var self = this ;
316
- send_command ( 'ABORT' , { 'transaction' : transaction_id } ) ;
318
+ send_command ( this , 'ABORT' , { 'transaction' : transaction_id } ) ;
317
319
self . log . debug ( 'abort transaction: ' + transaction_id ) ;
318
320
} ;
319
321
@@ -328,7 +330,7 @@ Stomp.prototype.send = function(headers, want_receipt) {
328
330
destination = headers [ 'destination' ] ;
329
331
body = headers [ 'body' ] || null ;
330
332
headers [ 'session' ] = self . session ;
331
- return send_command ( 'SEND' , headers , body , want_receipt )
333
+ return send_command ( this , 'SEND' , headers , body , want_receipt )
332
334
} ;
333
335
334
336
module . exports . Stomp = Stomp ;
0 commit comments