mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 16:15:49 +00:00
Add remote.disconnect callback
This commit is contained in:
@@ -235,7 +235,7 @@ Remote.from_config = function(obj, trace) {
|
|||||||
var remote = new Remote(serverConfig, trace);
|
var remote = new Remote(serverConfig, trace);
|
||||||
|
|
||||||
function initializeAccount(account) {
|
function initializeAccount(account) {
|
||||||
var accountInfo = config.accounts[account];
|
var accountInfo = this.accounts[account];
|
||||||
if (typeof accountInfo === 'object') {
|
if (typeof accountInfo === 'object') {
|
||||||
if (accountInfo.secret) {
|
if (accountInfo.secret) {
|
||||||
// Index by nickname
|
// Index by nickname
|
||||||
@@ -246,11 +246,7 @@ Remote.from_config = function(obj, trace) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof config.accounts === 'object') {
|
Object.keys(config.accounts || {}).forEach(initializeAccount, config);
|
||||||
for (var account in config.accounts) {
|
|
||||||
initializeAccount(account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return remote;
|
return remote;
|
||||||
};
|
};
|
||||||
@@ -387,11 +383,15 @@ Remote.prototype.connect = function(online) {
|
|||||||
/**
|
/**
|
||||||
* Disconnect from the Ripple network.
|
* Disconnect from the Ripple network.
|
||||||
*/
|
*/
|
||||||
Remote.prototype.disconnect = function(online) {
|
Remote.prototype.disconnect = function(callback) {
|
||||||
if (!this._servers.length) {
|
if (!this._servers.length) {
|
||||||
throw new Error('No servers available, not disconnecting');
|
throw new Error('No servers available, not disconnecting');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
this.once('disconnect', callback);
|
||||||
|
}
|
||||||
|
|
||||||
this._servers.forEach(function(server) {
|
this._servers.forEach(function(server) {
|
||||||
server.disconnect();
|
server.disconnect();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user