web3-providers-ws
Advanced tools
Comparing version 1.0.0-beta.33 to 1.0.0-beta.34
{ | ||
"name": "web3-providers-ws", | ||
"namespace": "ethereum", | ||
"version": "1.0.0-beta.33", | ||
"version": "1.0.0-beta.34", | ||
"description": "Module to handle web3 RPC connections over WebSockets.", | ||
@@ -11,5 +11,5 @@ "repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-providers-ws", | ||
"underscore": "1.8.3", | ||
"web3-core-helpers": "1.0.0-beta.33", | ||
"web3-core-helpers": "1.0.0-beta.34", | ||
"websocket": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible" | ||
} | ||
} |
@@ -34,3 +34,4 @@ # web3-providers-ws | ||
var ws = new Web3WsProvider('ws://localhost:8546'); | ||
var options = { timeout: 30000, headers: {authorization: 'Basic username:password'} } // set a custom timeout at 30 seconds, and credentials (you can also add the credentials to the URL: ws://username:password@localhost:8546) | ||
var ws = new Web3WsProvider('ws://localhost:8546', options); | ||
``` | ||
@@ -41,3 +42,1 @@ | ||
[repo]: https://github.com/ethereum/web3.js | ||
@@ -29,6 +29,17 @@ /* | ||
var Ws = null; | ||
var _btoa = null; | ||
var parseURL = null; | ||
if (typeof window !== 'undefined') { | ||
Ws = window.WebSocket; | ||
_btoa = btoa; | ||
parseURL = function(url) { | ||
return new URL(url); | ||
}; | ||
} else { | ||
Ws = require('websocket').w3cwebsocket; | ||
_btoa = function(str) { | ||
return Buffer(str).toString('base64'); | ||
}; | ||
// Web3 supports Node.js 5, so we need to use the legacy URL API | ||
parseURL = require('url').parse; | ||
} | ||
@@ -39,9 +50,22 @@ // Default connection ws://localhost:8546 | ||
var WebsocketProvider = function WebsocketProvider(url) { | ||
var WebsocketProvider = function WebsocketProvider(url, options) { | ||
var _this = this; | ||
this.responseCallbacks = {}; | ||
this.notificationCallbacks = []; | ||
this.connection = new Ws(url); | ||
options = options || {}; | ||
this._customTimeout = options.timeout; | ||
// The w3cwebsocket implementation does not support Basic Auth | ||
// username/password in the URL. So generate the basic auth header, and | ||
// pass through with any additional headers supplied in constructor | ||
var parsedURL = parseURL(url); | ||
var headers = options.headers || {}; | ||
if (parsedURL.username && parsedURL.password) { | ||
headers.authorization = 'Basic ' + _btoa(parsedURL.username + ':' + parsedURL.password); | ||
} | ||
this.connection = new Ws(url, undefined, undefined, headers); | ||
this.addDefaultEvents(); | ||
@@ -165,3 +189,3 @@ | ||
/** | ||
Get the adds a callback to the responseCallbacks object, | ||
Adds a callback to the responseCallbacks object, | ||
which will be called if a response matching the response Id will arrive. | ||
@@ -177,2 +201,14 @@ | ||
this.responseCallbacks[id].method = method; | ||
var _this = this; | ||
// schedule triggering the error response if a custom timeout is set | ||
if (this._customTimeout) { | ||
setTimeout(function () { | ||
if (_this.responseCallbacks[id]) { | ||
_this.responseCallbacks[id](errors.ConnectionTimeout(_this._customTimeout)); | ||
delete _this.responseCallbacks[id]; | ||
} | ||
}, this._customTimeout); | ||
} | ||
}; | ||
@@ -179,0 +215,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
13038
342
3
41
+ Addedweb3-core-helpers@1.0.0-beta.34(transitive)
+ Addedweb3-eth-iban@1.0.0-beta.34(transitive)
+ Addedweb3-utils@1.0.0-beta.34(transitive)
- Removedweb3-core-helpers@1.0.0-beta.33(transitive)
- Removedweb3-eth-iban@1.0.0-beta.33(transitive)
- Removedweb3-utils@1.0.0-beta.33(transitive)