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

Commit 57ec809

Browse files
committed
made subscriptions backwards compatible, to old style providers
1 parent a532b20 commit 57ec809

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

dist/web3.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27250,20 +27250,21 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
2725027250

2725127251
// listen to incoming notifications
2725227252
if (this.provider && this.provider.on) {
27253-
this.provider.on('data', function requestManagerNotification(result) {
27254-
// err,
27255-
// if(!err) {
27256-
if (_this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) {
27253+
this.provider.on('data', function requestManagerNotification(result, deprecatedResult) {
27254+
result = result || deprecatedResult; // this is for possible old providers, which may had the error first handler
27255+
27256+
// check for result.method, to prevent old providers errors to pass as result
27257+
if (result.method && _this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) {
2725727258
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
2725827259
}
27259-
// } else {
27260-
//
27261-
// Object.keys(_this.subscriptions).forEach(function(id){
27262-
// if(_this.subscriptions[id].callback)
27263-
// _this.subscriptions[id].callback(err);
27264-
// });
27265-
// }
2726627260
});
27261+
// TODO add error, end, timeout, connect??
27262+
// this.provider.on('error', function requestManagerNotification(result){
27263+
// Object.keys(_this.subscriptions).forEach(function(id){
27264+
// if(_this.subscriptions[id].callback)
27265+
// _this.subscriptions[id].callback(err);
27266+
// });
27267+
// }
2726727268
}
2726827269
};
2726927270

@@ -52543,7 +52544,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
5254352544
// notification
5254452545
if (!id && result.method.indexOf('_subscription') !== -1) {
5254552546
_this.notificationCallbacks.forEach(function (callback) {
52546-
if (_.isFunction(callback)) callback(null, result);
52547+
if (_.isFunction(callback)) callback(result);
5254752548
});
5254852549

5254952550
// fire the callback
@@ -52579,11 +52580,6 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
5257952580

5258052581
this.connection.on('end', function () {
5258152582
_this._timeout();
52582-
52583-
// inform notifications
52584-
_this.notificationCallbacks.forEach(function (callback) {
52585-
if (_.isFunction(callback)) callback(new Error('IPC socket connection closed'));
52586-
});
5258752583
});
5258852584

5258952585
this.connection.on('timeout', function () {
@@ -52704,6 +52700,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
5270452700
this.notificationCallbacks.push(callback);
5270552701
break;
5270652702

52703+
// adds error, end, timeout, connect
5270752704
default:
5270852705
this.connection.on(type, callback);
5270952706
break;
@@ -52850,7 +52847,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
5285052847
// notification
5285152848
if (!id && result.method.indexOf('_subscription') !== -1) {
5285252849
_this.notificationCallbacks.forEach(function (callback) {
52853-
if (_.isFunction(callback)) callback(null, result);
52850+
if (_.isFunction(callback)) callback(result);
5285452851
});
5285552852

5285652853
// fire the callback
@@ -52874,18 +52871,11 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
5287452871
_this._timeout();
5287552872
};
5287652873

52877-
this.connection.onclose = function (e) {
52874+
this.connection.onclose = function () {
5287852875
_this._timeout();
5287952876

52880-
var noteCb = _this.notificationCallbacks;
52881-
5288252877
// reset all requests and callbacks
5288352878
_this.reset();
52884-
52885-
// cancel subscriptions
52886-
noteCb.forEach(function (callback) {
52887-
if (_.isFunction(callback)) callback(e);
52888-
});
5288952879
};
5289052880

5289152881
// this.connection.on('timeout', function(){

dist/web3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/web3-core-requestmanager/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ RequestManager.prototype.setProvider = function (p, net) {
9595

9696
// listen to incoming notifications
9797
if(this.provider && this.provider.on) {
98-
this.provider.on('data', function requestManagerNotification(result){
99-
if(_this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) {
98+
this.provider.on('data', function requestManagerNotification(result, deprecatedResult){
99+
result = result || deprecatedResult; // this is for possible old providers, which may had the error first handler
100+
101+
// check for result.method, to prevent old providers errors to pass as result
102+
if(result.method && _this.subscriptions[result.params.subscription] && _this.subscriptions[result.params.subscription].callback) {
100103
_this.subscriptions[result.params.subscription].callback(null, result.params.result);
101104
}
102105
});

packages/web3-providers-ws/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ WebsocketProvider.prototype.addDefaultEvents = function(){
9292
_this._timeout();
9393
};
9494

95-
this.connection.onclose = function(e){
95+
this.connection.onclose = function(){
9696
_this._timeout();
9797

9898
// reset all requests and callbacks

0 commit comments

Comments
 (0)