From 75d3a4f827badf8dbb464a51b045f27d7970037d Mon Sep 17 00:00:00 2001 From: wltsmrz Date: Thu, 13 Jun 2013 07:28:36 +0900 Subject: [PATCH] Add JSDoc style comments --- src/js/ripple/server.js | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/js/ripple/server.js b/src/js/ripple/server.js index 03e10a61..26f146a2 100644 --- a/src/js/ripple/server.js +++ b/src/js/ripple/server.js @@ -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;