mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 15:45:48 +00:00
Remote: Only log set_state when the state will actually change. Only set state online when connection_count === 1
This commit is contained in:
@@ -267,13 +267,16 @@ Remote.prototype.addServer = function(opts) {
|
|||||||
server.on('message', serverMessage);
|
server.on('message', serverMessage);
|
||||||
|
|
||||||
function serverConnect() {
|
function serverConnect() {
|
||||||
self._connection_count++;
|
|
||||||
self._set_state('online');
|
|
||||||
if (opts.primary || !self._primary_server) {
|
if (opts.primary || !self._primary_server) {
|
||||||
self._setPrimaryServer(server);
|
self._setPrimaryServer(server);
|
||||||
}
|
}
|
||||||
if (self._connection_count === self._servers.length) {
|
switch (++self._connection_count) {
|
||||||
self.emit('ready');
|
case 1:
|
||||||
|
self._setState('online');
|
||||||
|
break;
|
||||||
|
case self._servers.length:
|
||||||
|
self.emit('ready');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -281,8 +284,8 @@ Remote.prototype.addServer = function(opts) {
|
|||||||
|
|
||||||
function serverDisconnect() {
|
function serverDisconnect() {
|
||||||
self._connection_count--;
|
self._connection_count--;
|
||||||
if (!self._connection_count) {
|
if (self._connection_count === 0) {
|
||||||
self._set_state('offline');
|
self._setState('offline');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -300,9 +303,9 @@ Remote.prototype.serverFatal = function() {
|
|||||||
|
|
||||||
// Set the emitted state: 'online' or 'offline'
|
// Set the emitted state: 'online' or 'offline'
|
||||||
Remote.prototype._setState = function(state) {
|
Remote.prototype._setState = function(state) {
|
||||||
this._trace('remote: set_state: %s', state);
|
|
||||||
|
|
||||||
if (this.state !== state) {
|
if (this.state !== state) {
|
||||||
|
this._trace('remote: set_state: %s', state);
|
||||||
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
|
||||||
this.emit('state', state);
|
this.emit('state', state);
|
||||||
@@ -343,6 +346,8 @@ Remote.prototype._trace = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the Ripple network.
|
* Connect to the Ripple network.
|
||||||
|
*
|
||||||
|
* param {Function} callback
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.connect = function(online) {
|
Remote.prototype.connect = function(online) {
|
||||||
@@ -353,9 +358,11 @@ Remote.prototype.connect = function(online) {
|
|||||||
switch (typeof online) {
|
switch (typeof online) {
|
||||||
case 'undefined':
|
case 'undefined':
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'function':
|
case 'function':
|
||||||
this.once('connect', online);
|
this.once('connect', online);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Downwards compatibility
|
// Downwards compatibility
|
||||||
if (!Boolean(online)) {
|
if (!Boolean(online)) {
|
||||||
@@ -762,6 +769,7 @@ Remote.prototype.requestTransactionEntry = function(hash, ledger_hash, callback)
|
|||||||
case 'string':
|
case 'string':
|
||||||
request.ledgerHash(ledger_hash);
|
request.ledgerHash(ledger_hash);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
request.ledgerIndex('validated');
|
request.ledgerIndex('validated');
|
||||||
callback = ledger_hash;
|
callback = ledger_hash;
|
||||||
@@ -918,7 +926,7 @@ Remote.prototype.requestBookOffers = function(gets, pays, taker, callback) {
|
|||||||
if (typeof lastArg === 'function') {
|
if (typeof lastArg === 'function') {
|
||||||
callback = lastArg;
|
callback = lastArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = new Request(this, 'book_offers');
|
var request = new Request(this, 'book_offers');
|
||||||
|
|
||||||
request.message.taker_gets = {
|
request.message.taker_gets = {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function Server(remote, opts) {
|
|||||||
this._ws = void(0);
|
this._ws = void(0);
|
||||||
this._connected = false;
|
this._connected = false;
|
||||||
this._shouldConnect = false;
|
this._shouldConnect = false;
|
||||||
this._state = void(0);
|
this._state = 'offline';
|
||||||
this._id = 0;
|
this._id = 0;
|
||||||
this._retry = 0;
|
this._retry = 0;
|
||||||
this._requests = { };
|
this._requests = { };
|
||||||
@@ -110,6 +110,8 @@ Server.onlineStates = [
|
|||||||
|
|
||||||
Server.prototype._setState = function(state) {
|
Server.prototype._setState = function(state) {
|
||||||
if (state !== this._state) {
|
if (state !== this._state) {
|
||||||
|
this._remote._trace('server: set_state: %s', state);
|
||||||
|
|
||||||
this._state = state;
|
this._state = state;
|
||||||
|
|
||||||
this.emit('state', state);
|
this.emit('state', state);
|
||||||
|
|||||||
Reference in New Issue
Block a user