Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Full support for websocket reconnection/resubscription #3167

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 70 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"lerna": "^2.11.0",
"mocha": "^6.2.1",
"npm-auth-to-token": "^1.0.0",
"pify": "^4.0.1",
"puppeteer": "^1.20.0",
"sandboxed-module": "^2.0.3",
"typescript": "next",
Expand Down
32 changes: 19 additions & 13 deletions packages/web3-core-requestmanager/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ RequestManager.prototype.setProvider = function (p, net) {
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
}
});
// TODO add error, end, timeout, connect??
// this.provider.on('error', function requestManagerNotification(result){
// Object.keys(_this.subscriptions).forEach(function(id){
// if(_this.subscriptions[id].callback)
// _this.subscriptions[id].callback(err);
// });
// }

// notify all subscriptions about the error condition
this.provider.on('error', function (event) {
Object.keys(_this.subscriptions).forEach(function(id){
if(_this.subscriptions[id] && _this.subscriptions[id].callback)
_this.subscriptions[id].callback(event.code || new Error('Provider error'));
});
});

// TODO add end, timeout, connect??
}
};

Expand Down Expand Up @@ -205,17 +208,20 @@ RequestManager.prototype.addSubscription = function (id, name, type, callback) {
* @param {Function} callback fired once the subscription is removed
*/
RequestManager.prototype.removeSubscription = function (id, callback) {
var _this = this;

if(this.subscriptions[id]) {
var type = this.subscriptions[id].type;

// remove subscription first to avoid reentry
delete this.subscriptions[id];

// then, try to actually unsubscribe
this.send({
method: this.subscriptions[id].type + '_unsubscribe',
method: type + '_unsubscribe',
params: [id]
}, callback);

// remove subscription
delete _this.subscriptions[id];
} else if (typeof callback === 'function') {
// call the callback if the subscription was already removed
callback(null);
}
};

Expand Down
Loading