mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 03:35:49 +00:00
Add Request.broadcast. Subscribe to account transaction stream on all connected servers
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user