Code style.

This commit is contained in:
Julien Fontanet 2015-02-05 11:57:05 +01:00
parent c6db974962
commit debcf086b5

View File

@ -10,12 +10,12 @@ var WebSocket = require('ws');
//==================================================================== //====================================================================
var notConnected = function () { function notConnected() {
throw new Error('not connected'); throw new Error('not connected');
}; }
// Fix URL if necessary. // Fix URL if necessary.
var fixUrl = function (url) { function fixUrl(url) {
// Add HTTP protocol if missing. // Add HTTP protocol if missing.
if (!/^https?:/.test(url)) { if (!/^https?:/.test(url)) {
url = 'http:'+ url; url = 'http:'+ url;
@ -40,11 +40,11 @@ var fixUrl = function (url) {
url.search, url.search,
url.hash, url.hash,
].join(''); ].join('');
}; }
//==================================================================== //====================================================================
var Xo = function (url) { function Xo(url) {
this._url = fixUrl(url); this._url = fixUrl(url);
// Identifier of the next request. // Identifier of the next request.
@ -61,19 +61,17 @@ var Xo = function (url) {
// - connecting // - connecting
// - connected // - connected
this.status = 'disconnected'; this.status = 'disconnected';
}; }
assign(Xo.prototype, { assign(Xo.prototype, {
close: function () { close: function () {
if (this._socket) if (this._socket) {
{
this._socket.close(); this._socket.close();
} }
}, },
connect: function () { connect: function () {
if (this.status === 'connected') if (this.status === 'connected') {
{
return Bluebird.cast(); return Bluebird.cast();
} }
@ -101,8 +99,7 @@ assign(Xo.prototype, {
socket.on('message', function (data) { socket.on('message', function (data) {
// `ws` API is lightly different from standard API. // `ws` API is lightly different from standard API.
if (data.data) if (data.data) {
{
data = data.data; data = data.data;
} }
@ -112,20 +109,17 @@ assign(Xo.prototype, {
var id = response.id; var id = response.id;
var deferred = this._deferreds[id]; var deferred = this._deferreds[id];
if (!deferred) if (!deferred) {
{
// Response already handled. // Response already handled.
return; return;
} }
delete this._deferreds[id]; delete this._deferreds[id];
if ('error' in response) if ('error' in response) {
{
return deferred.reject(response.error); return deferred.reject(response.error);
} }
if ('result' in response) if ('result' in response) {
{
return deferred.resolve(response.result); return deferred.resolve(response.result);
} }