Add JSDoc style comments

This commit is contained in:
wltsmrz
2013-06-13 07:28:36 +09:00
parent c2ad23996d
commit 75d3a4f827

View File

@@ -6,6 +6,9 @@ var utils = require('./utils');
/**
* Server
*
* Options must contain `url` to
* WebSocket server
*
* @constructor
* @param {Object} remote
* @param {Object} opts
@@ -50,6 +53,7 @@ util.inherits(Server, EventEmitter);
* Our requirements are that the server can process transactions and notify
* us of changes.
*/
Server.online_states = [
'syncing'
, 'tracking'
@@ -58,10 +62,23 @@ Server.online_states = [
, 'full'
];
/**
* Determine if a server status qualifies
* as 'online'
*
* @param {String} status
* @return {Boolean}
* @api private
*/
Server.prototype.is_online = function(status) {
return Server.online_states.indexOf(status) !== -1;
};
/**
* Connect to WebSocket server
*/
Server.prototype.connect = function() {
var self = this;
@@ -166,6 +183,12 @@ Server.prototype.connect = function() {
};
};
/**
* Disconnect from WebSocket server
*
* @api public
*/
Server.prototype.disconnect = function() {
this._should_connect = false;
this._set_state('offline');
@@ -174,6 +197,13 @@ Server.prototype.disconnect = function() {
}
};
/**
* Send stringified message to WebSocket server
*
* @param {Object} message
* @api private
*/
Server.prototype.send = function(message) {
if (this._ws) {
this._ws.send(JSON.stringify(message));
@@ -182,7 +212,11 @@ Server.prototype.send = function(message) {
/**
* Submit a Request object to this server.
*
* @param {Object} request
* @api public
*/
Server.prototype.request = function(request) {
var self = this;
@@ -217,6 +251,18 @@ Server.prototype.request = function(request) {
}
};
/**
* Set server state
*
* Examples:
*
* set_state('online')
* set_state('offline')
*
* @param {String} state
* @api private
*/
Server.prototype._set_state = function(state) {
if (state !== this._state) {
this._state = state;
@@ -233,6 +279,13 @@ Server.prototype._set_state = function(state) {
}
};
/**
* Handle WebSocket message
*
* @param {String} json
* @api private
*/
Server.prototype._handle_message = function(json) {
var self = this;
var unexpected = false;
@@ -290,6 +343,13 @@ Server.prototype._handle_message = function(json) {
}
};
/**
* Handle subscribe response
*
* @param {Object} message
* @api private
*/
Server.prototype._handle_response_subscribe = function(message) {
var self = this;