Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document WS clientConfig options in README and RTD #3402

Merged
Merged
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
69 changes: 69 additions & 0 deletions docs/include_package-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,75 @@ Example
// on windows the path is: "\\\\.\\pipe\\geth.ipc"
// on linux the path is: "/users/myuser/.ethereum/geth.ipc"

-------------
Configuration
-------------

.. code-block:: javascript

// ====
// Http
// ====

var Web3HttpProvider = require('web3-providers-http');

var options = {
keepAlive: true,
withCredentials: false,
timeout: 20000, // ms
headers: [
{
name: 'Access-Control-Allow-Origin',
value: '*'
},
{
...
}
],
agent: {
http: http.Agent(...),
baseUrl: ''
}
};

var provider = new Web3HttpProvider('http://localhost:8545', options);

// ==========
// Websockets
// ==========

var Web3WsProvider = require('web3-providers-ws');

var options = {
timeout: 30000, // ms

// Useful for credentialed urls, e.g: ws://username:password@localhost:8546
headers: {
authorization: 'Basic username:password'
},

// Useful if requests result are large
clientConfig: {
maxReceivedFrameSize: 100000000, // bytes - default: 1MiB
maxReceivedMessageSize: 100000000, // bytes - default: 8MiB
},

// Enable auto reconnection
reconnect: {
auto: true,
delay: 5000, // ms
maxAttempts: 5,
onTimeout: false
}
};

var ws = new Web3WsProvider('ws://localhost:8546', options);


More information for the Http and Websocket provider modules can be found here:

- `HttpProvider <https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-http#usage>`_
- `WebsocketProvider <https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ws#usage>`_

------------------------------------------------------------------------------

Expand Down
31 changes: 24 additions & 7 deletions packages/web3-providers-ws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a sub package of [web3.js][repo]

This is a websocket provider for [web3.js][repo].
This is a websocket provider for [web3.js][repo].
Please read the [documentation][docs] for more.

## Installation
Expand Down Expand Up @@ -31,16 +31,33 @@ This will expose the `Web3WsProvider` object on the window object.
var Web3WsProvider = require('web3-providers-ws');

var options = {
timeout: 30000,
headers: { authorization: 'Basic username:password' },
timeout: 30000, // ms

// Useful for credentialed urls, e.g: ws://username:password@localhost:8546
headers: {
authorization: 'Basic username:password'
},

// Useful if requests are large
clientConfig: {
maxReceivedFrameSize: 100000000, // bytes - default: 1MiB
maxReceivedMessageSize: 100000000, // bytes - default: 8MiB
},

// Enable auto reconnection
reconnect: {
auto: false,
delay: 5000,
maxAttempts: false,
auto: true,
delay: 5000, // ms
maxAttempts: 5,
onTimeout: false
}
}; // set a custom timeout at 30 seconds, credentials (you can also add the credentials to the URL: ws://username:password@localhost:8546), and enable WebSocket auto-reconnection
};

var ws = new Web3WsProvider('ws://localhost:8546', options);

(Additional client config options can be found [here][1])

[1]: https://github.com/web3-js/WebSocket-Node/blob/polyfill/globalThis/docs/WebSocketClient.md
```

## Types
Expand Down