Socket
Socket
Sign inDemoInstall

web3-providers-ws

Package Overview
Dependencies
Maintainers
1
Versions
416
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-providers-ws - npm Package Compare versions

Comparing version 1.0.0-beta.33 to 1.0.0-beta.34

4

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc