mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Always call Remote.disconnect callback
This commit is contained in:
@@ -574,12 +574,17 @@ Remote.prototype.disconnect = function(callback) {
|
||||
throw new Error('No servers available, not disconnecting');
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
this.once('disconnect', callback);
|
||||
var callback = (typeof callback === 'function') ? callback : function(){};
|
||||
|
||||
if (!this._connected) {
|
||||
callback();
|
||||
return this;
|
||||
}
|
||||
|
||||
this._should_connect = false;
|
||||
|
||||
this.once('disconnect', callback);
|
||||
|
||||
this._servers.forEach(function(server) {
|
||||
server.disconnect();
|
||||
});
|
||||
@@ -773,6 +778,16 @@ Remote.prototype.setPrimaryServer = function(server) {
|
||||
this._primary_server._primary = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get connected state
|
||||
*
|
||||
* @return {Boolean} connected
|
||||
*/
|
||||
|
||||
Remote.prototype.isConnected = function() {
|
||||
return this._connected;
|
||||
};
|
||||
|
||||
/**
|
||||
* Select a server to handle a request. Servers are
|
||||
* automatically prioritized
|
||||
@@ -782,7 +797,7 @@ Remote.prototype._getServer =
|
||||
Remote.prototype.getServer = function() {
|
||||
var result = void(0);
|
||||
|
||||
if (this._primary_server && this._primary_server._connected) {
|
||||
if (this._primary_server && this._primary_server.isConnected()) {
|
||||
return this._primary_server;
|
||||
}
|
||||
|
||||
|
||||
@@ -316,7 +316,6 @@ Server.prototype.disconnect = function() {
|
||||
this._lastLedgerIndex = NaN;
|
||||
this._lastLedgerClose = NaN;
|
||||
this._score = 0;
|
||||
|
||||
this._shouldConnect = false;
|
||||
this._setState('offline');
|
||||
|
||||
@@ -341,11 +340,11 @@ Server.prototype.reconnect = function() {
|
||||
};
|
||||
|
||||
if (this._ws && this._shouldConnect) {
|
||||
if (this._connected) {
|
||||
if (this.isConnected()) {
|
||||
this.once('disconnect', reconnect);
|
||||
this.disconnect();
|
||||
} else {
|
||||
reconnect();
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user