Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

Commit 9eb416f

Browse files
committed
Merge branch 'doc_imporovements'
2 parents 4247593 + ae4c925 commit 9eb416f

File tree

2 files changed

+144
-101
lines changed

2 files changed

+144
-101
lines changed

lib/frame.js

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
/*
2-
frame.js - Frame object
1+
// ## frame
2+
//
3+
// The `Frame` module provides an object representation of a `Stomp` frame.
4+
//
5+
// ### frame.Frame
6+
//
7+
// An instance of the `Frame` object.
8+
//
9+
// var frame = new frame.Frame();
10+
//
11+
// ### frame.Frame.build_frame()
12+
//
13+
// Build a frame object from an object of arguments.
14+
//
15+
// var args = {
16+
// command: '',
17+
// headers: {},
18+
// body: ''
19+
// };
20+
//
21+
// this_frame = frame.build_frame(args);
22+
//
323

4-
Copyright (c) 2010, Benjamin W. Smith
5-
All rights reserved.
624

7-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8-
9-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
11-
other materials provided with the distribution.
12-
* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software
13-
without specific prior written permission.
14-
15-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17-
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21-
*/
22-
23-
/**
24-
* Frame - Object representation of a STOMP frame
25-
*/
25+
//
26+
// ## Frame - Object representation of a STOMP frame
27+
//
2628
function Frame() {
2729
this.command = null;
2830
this.headers = null;
2931
this.body = null;
3032
};
3133

32-
/**
33-
* Build frame based on arguments provided
34-
* @param {Object} arguments needed to build frame (command, headers, body?)
35-
* @param {Bool} Indicate that you wish to get a receipt (set receipt header)
36-
* @return {Object} Frame object
37-
*/
34+
//
35+
// ## Frame.build_frame(args, want_receipt)
36+
//
37+
// **Build frame based on arguments provided**
38+
//
39+
// Takes arguments object needed to build frame (command, headers, body?)
40+
//
41+
// Takes boolean to indicate that you wish to get a receipt (set receipt header)
42+
//
43+
// Returns an object representing a frame
44+
//
3845
Frame.prototype.build_frame = function(args, want_receipt) {
3946
var receipt_stamp = null;
4047

@@ -56,10 +63,13 @@ Frame.prototype.build_frame = function(args, want_receipt) {
5663
return this;
5764
};
5865

59-
/**
60-
* String representation of Frame object
61-
* @return {String} - Frame as string
62-
*/
66+
//
67+
// ## Frame.as_string()
68+
//
69+
// **String representation of Frame object**
70+
//
71+
// Returns `Frame` as string
72+
//
6373
Frame.prototype.as_string = function() {
6474
var header_strs = [],
6575
frame = "",
@@ -68,15 +78,16 @@ Frame.prototype.as_string = function() {
6878
body = this.body;
6979

7080
for (var header in headers) {
71-
header_strs.push(header + ':' + headers[header]);
81+
header_strs.push(header + ':' + headers[header]);
7282
}
7383

7484
frame += command + "\n";
7585
frame += header_strs.join("\n");
7686
frame += "\n\n";
7787

78-
if(body)
88+
if(body) {
7989
frame += body;
90+
}
8091

8192
frame += '\x00';
8293

lib/stomp.js

Lines changed: 98 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
/*
2-
stomp.js - STOMP Protocol in node.js
3-
4-
Copyright (c) 2010, Benjamin W. Smith
5-
All rights reserved.
6-
7-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8-
9-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
11-
other materials provided with the distribution.
12-
* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software
13-
without specific prior written permission.
14-
15-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17-
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21-
*/
1+
// ## stomp
2+
//
3+
// The `Stomp` module provides you with a client interface for interacting with STOMP messaging brokers
4+
//
5+
// ### stomp.Stomp
6+
//
7+
// An instance of the `Stomp` object. Initialized like so:
8+
//
9+
// var stomp_args = {
10+
// port: 61613,
11+
// host: 'localhost',
12+
// debug: false,
13+
// login: 'guest',
14+
// passcode: 'guest',
15+
// };
16+
//
17+
// var client = new stomp.Stomp(stomp_args);
18+
//
19+
// If debug is set to true, extra output will be printed to the console.
20+
21+
// ## Helpers to handle frames, and do parsing
2222

2323
var net = require('net'),
2424
tls = require('tls'),
@@ -29,6 +29,7 @@ var net = require('net'),
2929
utils = new stomp_utils.StompUtils(),
3030
log = null;
3131

32+
3233
function parse_command(data) {
3334
var command,
3435
this_string = data.toString('utf8', 0, data.length);
@@ -231,10 +232,11 @@ function send_frame(stomp, _frame) {
231232
return true;
232233
};
233234

234-
/**
235-
* Stomp - Client API
236-
* @param {Object} args
237-
*/
235+
//
236+
// ## Stomp - Client API
237+
//
238+
// Takes an argument object
239+
//
238240
function Stomp(args) {
239241
this.port = args['port'] || 61613;
240242
this.host = args['host'] || "127.0.0.1";
@@ -250,24 +252,27 @@ function Stomp(args) {
250252
this['client-id'] = args['client-id'] || null;
251253
};
252254

255+
// ## Stomp is an EventEmitter
253256
Stomp.prototype = new process.EventEmitter();
254257

255-
/**
256-
* Begin connection
257-
*/
258+
// ## Stomp.connect()
259+
//
260+
// **Begin connection**
261+
//
258262
Stomp.prototype.connect = function() {
259263
_connect(this);
260264
};
261265

262-
/**
263-
* Handle frame based on type
264-
* @param {Object} Frame Object
265-
*/
266+
// ## Stomp.handle\_new_frame()
267+
//
268+
// **Handle frame based on type. Emit events when needed.**
269+
//
270+
// Takes a `Frame` object
271+
//
266272
Stomp.prototype.handle_new_frame = function(this_frame) {
267273
switch (this_frame.command) {
268274
case "MESSAGE":
269275
if (utils.really_defined(this_frame.headers['message-id'])) {
270-
// if a subscription to the destination queue exists, fire callback
271276
if (this_frame.headers !== null && this_frame.headers.destination !== null && this._subscribed_to[this_frame.headers.destination] !== null) {
272277
var subscription = this._subscribed_to[this_frame.headers.destination];
273278
if (subscription.enabled && subscription.callback !== null && typeof(subscription.callback) == 'function') {
@@ -294,17 +299,24 @@ Stomp.prototype.handle_new_frame = function(this_frame) {
294299
}
295300
};
296301

297-
/**
298-
* Disconnect from STOMP broker
299-
*/
302+
//
303+
// ## Stomp.disconnect()
304+
//
305+
// **Disconnect from STOMP broker**
306+
//
300307
Stomp.prototype.disconnect = function() {
301308
_disconnect(this);
302309
}
303310

304-
/**
305-
* Subscribe to destination (queue or topic)
306-
* @param {Object} headers
307-
*/
311+
//
312+
// ## Stomp.subscribe()
313+
//
314+
// **Subscribe to destination (queue or topic)**
315+
//
316+
// Takes a header object
317+
//
318+
// Takes a callback function
319+
//
308320
Stomp.prototype.subscribe = function(headers, callback) {
309321
var destination = headers['destination'];
310322
headers['session'] = this.session;
@@ -313,10 +325,13 @@ Stomp.prototype.subscribe = function(headers, callback) {
313325
this.log.debug('subscribed to: ' + destination + ' with headers ' + sys.inspect(headers));
314326
};
315327

316-
/**
317-
* Unsubscribe from destination (queue or topic)
318-
* @param {Object} headers
319-
*/
328+
//
329+
// ## Stomp.unsubscribe()
330+
//
331+
// **Unsubscribe from destination (queue or topic)**
332+
//
333+
// Takes a header object
334+
//
320335
Stomp.prototype.unsubscribe = function(headers) {
321336
var destination = headers['destination'];
322337
headers['session'] = this.session;
@@ -325,50 +340,67 @@ Stomp.prototype.unsubscribe = function(headers) {
325340
this.log.debug('no longer subscribed to: ' + destination);
326341
};
327342

328-
/**
329-
* Acknowledge received message
330-
* @param {String} message id to acknowledge
331-
*/
343+
//
344+
// ## Stomp.ack()
345+
//
346+
// **Acknowledge received message**
347+
//
348+
// Takes a string representing the message id to ack
349+
//
332350
Stomp.prototype.ack = function(message_id) {
333351
send_command(this, 'ACK', {'message-id': message_id});
334352
this.log.debug('acknowledged message: ' + message_id);
335353
};
336354

337-
/**
338-
* Begin transaction
339-
* @return {String} generated transaction id
340-
*/
355+
//
356+
// ## Stomp.begin()
357+
//
358+
// **Begin transaction**
359+
//
360+
// Return a string representing the generated transaction id
361+
//
341362
Stomp.prototype.begin = function() {
342363
var transaction_id = Math.floor(Math.random()*99999999999).toString();
343364
send_command(this, 'BEGIN', {'transaction': transaction_id});
344365
this.log.debug('begin transaction: ' + transaction_id);
345366
return transaction_id;
346367
};
347368

348-
/**
349-
* Commit transaction
350-
* @param {String} transaction id generated by stomp.Stomp.begin()
351-
*/
369+
//
370+
// ## Stomp.commit()
371+
//
372+
// **Commit transaction**
373+
//
374+
// Takes a string representing the transaction id generated by stomp.Stomp.begin()
375+
//
352376
Stomp.prototype.commit = function(transaction_id) {
353377
send_command(this, 'COMMIT', {'transaction': transaction_id});
354378
this.log.debug('commit transaction: ' + transaction_id);
355379
};
356380

357-
/**
358-
* Abort transaction
359-
* @param {String} transaction id generated by stomp.Stomp.begin()
360-
*/
381+
//
382+
// ## Stomp.abort()
383+
//
384+
// **Abort transaction**
385+
//
386+
// Takes a string representing the transaction id generated by stomp.Stomp.begin()
387+
//
361388
Stomp.prototype.abort = function(transaction_id) {
362389
send_command(this, 'ABORT', {'transaction': transaction_id});
363390
this.log.debug('abort transaction: ' + transaction_id);
364391
};
365392

366-
/**
367-
* Send MESSAGE to STOMP broker
368-
* @param {Object} headers required (destination is required)
369-
* @param {Bool} do you want a receipt of the message sent?
370-
* @return {Object} Frame object of message sent
371-
*/
393+
//
394+
// ## Stomp.send()
395+
//
396+
// **Send MESSAGE to STOMP broker**
397+
//
398+
// Takes a header object (destination is required)
399+
//
400+
// Takes a boolean requesting recipt of the sent message
401+
//
402+
// Returns a `Frame` object representing the message sent
403+
//
372404
Stomp.prototype.send = function(headers, want_receipt) {
373405
var destination = headers['destination'],
374406
body = headers['body'] || null;

0 commit comments

Comments
 (0)