diff --git a/src/js/ripple/account.js b/src/js/ripple/account.js index 106845b3..31881cac 100644 --- a/src/js/ripple/account.js +++ b/src/js/ripple/account.js @@ -39,7 +39,7 @@ function Account(remote, account) { if (!self._subs && self._remote._connected) { self._remote.request_subscribe() .accounts(self._account_id) - .request(); + .broadcast(); } self._subs += 1; } @@ -51,7 +51,7 @@ function Account(remote, account) { if (!self._subs && self._remote._connected) { self._remote.request_unsubscribe() .accounts(self._account_id) - .request(); + .broadcast(); } } } diff --git a/src/js/ripple/request.js b/src/js/ripple/request.js index 3678b111..3f97b2a2 100644 --- a/src/js/ripple/request.js +++ b/src/js/ripple/request.js @@ -27,14 +27,29 @@ function Request(remote, command) { util.inherits(Request, EventEmitter); +Request.prototype.broadcast = function() { + this._broadcast = true; + return this.request(); +}; + // Send the request to a remote. Request.prototype.request = function (remote) { - if (!this.requested) { - this.requested = true; - this.on('error', new Function); + if (this.requested) return; + + this.requested = true; + this.on('error', new Function); + this.emit('request', remote); + + if (this._broadcast) { + this.remote._servers.forEach(function(server) { + this.set_server(server); + this.remote.request(this); + }, this ); + } else { this.remote.request(this); - this.emit('request', remote); } + + return this; }; Request.prototype.callback = function(callback, successEvent, errorEvent) {