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

Commit 0e79060

Browse files
committed
Make things docco friendly
1 parent 4247593 commit 0e79060

File tree

2 files changed

+145
-60
lines changed

2 files changed

+145
-60
lines changed

lib/frame.js

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,50 @@
2020
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2121
*/
2222

23-
/**
24-
* Frame - Object representation of a STOMP frame
25-
*/
23+
// ## frame
24+
//
25+
// The `Frame` module provides an object representation of a `Stomp` frame.
26+
//
27+
// ### frame.Frame
28+
//
29+
// An instance of the `Frame` object.
30+
//
31+
// var frame = new frame.Frame();
32+
//
33+
// ### frame.Frame.build_frame()
34+
//
35+
// Build a frame object from an object of arguments.
36+
//
37+
// var args = {
38+
// command: '',
39+
// headers: {},
40+
// body: ''
41+
// };
42+
//
43+
// this_frame = frame.build_frame(args);
44+
//
45+
46+
47+
//
48+
// ## Frame - Object representation of a STOMP frame
49+
//
2650
function Frame() {
2751
this.command = null;
2852
this.headers = null;
2953
this.body = null;
3054
};
3155

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-
*/
56+
//
57+
// ## Frame.build_frame(args, want_receipt)
58+
//
59+
// **Build frame based on arguments provided**
60+
//
61+
// Takes arguments object needed to build frame (command, headers, body?)
62+
//
63+
// Takes boolean to indicate that you wish to get a receipt (set receipt header)
64+
//
65+
// Returns an object representing a frame
66+
//
3867
Frame.prototype.build_frame = function(args, want_receipt) {
3968
var receipt_stamp = null;
4069

@@ -56,10 +85,13 @@ Frame.prototype.build_frame = function(args, want_receipt) {
5685
return this;
5786
};
5887

59-
/**
60-
* String representation of Frame object
61-
* @return {String} - Frame as string
62-
*/
88+
//
89+
// ## Frame.as_string()
90+
//
91+
// **String representation of Frame object**
92+
//
93+
// Returns `Frame` as string
94+
//
6395
Frame.prototype.as_string = function() {
6496
var header_strs = [],
6597
frame = "",
@@ -68,15 +100,16 @@ Frame.prototype.as_string = function() {
68100
body = this.body;
69101

70102
for (var header in headers) {
71-
header_strs.push(header + ':' + headers[header]);
103+
header_strs.push(header + ':' + headers[header]);
72104
}
73105

74106
frame += command + "\n";
75107
frame += header_strs.join("\n");
76108
frame += "\n\n";
77109

78-
if(body)
110+
if(body) {
79111
frame += body;
112+
}
80113

81114
frame += '\x00';
82115

lib/stomp.js

Lines changed: 97 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2121
*/
2222

23+
// ## stomp
24+
//
25+
// The `Stomp` module provides you with a client interface for interacting with STOMP messaging brokers
26+
//
27+
// ### stomp.Stomp
28+
//
29+
// An instance of the `Stomp` object. Initialized like so:
30+
//
31+
// var stomp_args = {
32+
// port: 61613,
33+
// host: 'localhost',
34+
// debug: false,
35+
// login: 'guest',
36+
// passcode: 'guest',
37+
// };
38+
//
39+
// var client = new stomp.Stomp(stomp_args);
40+
//
41+
// If debug is set to true, extra output will be printed to the console.
42+
2343
var net = require('net'),
2444
tls = require('tls'),
2545
sys = require('util'),
@@ -29,6 +49,8 @@ var net = require('net'),
2949
utils = new stomp_utils.StompUtils(),
3050
log = null;
3151

52+
// ## Helpers to handle frames, and do parsing
53+
3254
function parse_command(data) {
3355
var command,
3456
this_string = data.toString('utf8', 0, data.length);
@@ -231,10 +253,11 @@ function send_frame(stomp, _frame) {
231253
return true;
232254
};
233255

234-
/**
235-
* Stomp - Client API
236-
* @param {Object} args
237-
*/
256+
//
257+
// ## Stomp - Client API
258+
//
259+
// Takes an argument object
260+
//
238261
function Stomp(args) {
239262
this.port = args['port'] || 61613;
240263
this.host = args['host'] || "127.0.0.1";
@@ -252,22 +275,24 @@ function Stomp(args) {
252275

253276
Stomp.prototype = new process.EventEmitter();
254277

255-
/**
256-
* Begin connection
257-
*/
278+
// ## Stomp.connect()
279+
//
280+
// **Begin connection**
281+
//
258282
Stomp.prototype.connect = function() {
259283
_connect(this);
260284
};
261285

262-
/**
263-
* Handle frame based on type
264-
* @param {Object} Frame Object
265-
*/
286+
// ## Stomp.handle\_new_frame()
287+
//
288+
// **Handle frame based on type**
289+
//
290+
// Takes a `Frame` object
291+
//
266292
Stomp.prototype.handle_new_frame = function(this_frame) {
267293
switch (this_frame.command) {
268294
case "MESSAGE":
269295
if (utils.really_defined(this_frame.headers['message-id'])) {
270-
// if a subscription to the destination queue exists, fire callback
271296
if (this_frame.headers !== null && this_frame.headers.destination !== null && this._subscribed_to[this_frame.headers.destination] !== null) {
272297
var subscription = this._subscribed_to[this_frame.headers.destination];
273298
if (subscription.enabled && subscription.callback !== null && typeof(subscription.callback) == 'function') {
@@ -294,17 +319,24 @@ Stomp.prototype.handle_new_frame = function(this_frame) {
294319
}
295320
};
296321

297-
/**
298-
* Disconnect from STOMP broker
299-
*/
322+
//
323+
// ## `Stomp.disconnect()`
324+
//
325+
// **Disconnect from STOMP broker**
326+
//
300327
Stomp.prototype.disconnect = function() {
301328
_disconnect(this);
302329
}
303330

304-
/**
305-
* Subscribe to destination (queue or topic)
306-
* @param {Object} headers
307-
*/
331+
//
332+
// ## Stomp.subscribe()
333+
//
334+
// **Subscribe to destination (queue or topic)**
335+
//
336+
// Takes a header object
337+
//
338+
// Takes a callback function
339+
//
308340
Stomp.prototype.subscribe = function(headers, callback) {
309341
var destination = headers['destination'];
310342
headers['session'] = this.session;
@@ -313,10 +345,13 @@ Stomp.prototype.subscribe = function(headers, callback) {
313345
this.log.debug('subscribed to: ' + destination + ' with headers ' + sys.inspect(headers));
314346
};
315347

316-
/**
317-
* Unsubscribe from destination (queue or topic)
318-
* @param {Object} headers
319-
*/
348+
//
349+
// ## Stomp.unsubscribe()
350+
//
351+
// **Unsubscribe from destination (queue or topic)**
352+
//
353+
// Takes a header object
354+
//
320355
Stomp.prototype.unsubscribe = function(headers) {
321356
var destination = headers['destination'];
322357
headers['session'] = this.session;
@@ -325,50 +360,67 @@ Stomp.prototype.unsubscribe = function(headers) {
325360
this.log.debug('no longer subscribed to: ' + destination);
326361
};
327362

328-
/**
329-
* Acknowledge received message
330-
* @param {String} message id to acknowledge
331-
*/
363+
//
364+
// ## Stomp.ack()
365+
//
366+
// **Acknowledge received message**
367+
//
368+
// Takes a string representing the message id to ack
369+
//
332370
Stomp.prototype.ack = function(message_id) {
333371
send_command(this, 'ACK', {'message-id': message_id});
334372
this.log.debug('acknowledged message: ' + message_id);
335373
};
336374

337-
/**
338-
* Begin transaction
339-
* @return {String} generated transaction id
340-
*/
375+
//
376+
// ## Stomp.begin()
377+
//
378+
// **Begin transaction**
379+
//
380+
// Return a string representing the generated transaction id
381+
//
341382
Stomp.prototype.begin = function() {
342383
var transaction_id = Math.floor(Math.random()*99999999999).toString();
343384
send_command(this, 'BEGIN', {'transaction': transaction_id});
344385
this.log.debug('begin transaction: ' + transaction_id);
345386
return transaction_id;
346387
};
347388

348-
/**
349-
* Commit transaction
350-
* @param {String} transaction id generated by stomp.Stomp.begin()
351-
*/
389+
//
390+
// ## Stomp.commit()
391+
//
392+
// **Commit transaction**
393+
//
394+
// Takes a string representing the transaction id generated by stomp.Stomp.begin()
395+
//
352396
Stomp.prototype.commit = function(transaction_id) {
353397
send_command(this, 'COMMIT', {'transaction': transaction_id});
354398
this.log.debug('commit transaction: ' + transaction_id);
355399
};
356400

357-
/**
358-
* Abort transaction
359-
* @param {String} transaction id generated by stomp.Stomp.begin()
360-
*/
401+
//
402+
// ## Stomp.abort()
403+
//
404+
// **Abort transaction**
405+
//
406+
// Takes a string representing the transaction id generated by stomp.Stomp.begin()
407+
//
361408
Stomp.prototype.abort = function(transaction_id) {
362409
send_command(this, 'ABORT', {'transaction': transaction_id});
363410
this.log.debug('abort transaction: ' + transaction_id);
364411
};
365412

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-
*/
413+
//
414+
// ## Stomp.send()
415+
//
416+
// **Send MESSAGE to STOMP broker**
417+
//
418+
// Takes a header object (destination is required)
419+
//
420+
// Takes a boolean requesting recipt of the sent message
421+
//
422+
// Returns a `Frame` object representing the message sent
423+
//
372424
Stomp.prototype.send = function(headers, want_receipt) {
373425
var destination = headers['destination'],
374426
body = headers['body'] || null;

0 commit comments

Comments
 (0)