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

Remove webocket native dependency. #3578

Closed
wants to merge 1 commit into from
Closed

Conversation

nebojsa94
Copy link

@nebojsa94 nebojsa94 commented Jun 10, 2020

Description

This PR removes websocket dependency and instead uses ws since it doesn't require native dependency compiling.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build-all and tested the resulting files from dist folder in a browser.
  • I have updated the CHANGELOG.md file in the root folder.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.

@nebojsa94 nebojsa94 marked this pull request as ready for review June 16, 2020 17:44
@@ -16,7 +16,7 @@
"eventemitter3": "^4.0.0",
"underscore": "1.9.1",
"web3-core-helpers": "1.2.8",
"websocket": "^1.0.31"
"ws": "^7.3.0"
Copy link

@alcuadrado alcuadrado Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation, this module doesn't work in the browser.

I think we need two implementations of this provider, one for node using ws, and another one for the browser using the native WebSocket implementation. They can share most of their code.

The browser version should be declared in the package.json's browser field: https://docs.npmjs.com/files/package.json#browser

@@ -101,7 +101,10 @@ WebsocketProvider.prototype.constructor = WebsocketProvider;
* @returns {void}
*/
WebsocketProvider.prototype.connect = function () {
this.connection = new Ws(this.url, this.protocol, undefined, this.headers, this.requestOptions, this.clientConfig);
// TODO: include this.requestOptions and this.clientConfig
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO is important. Relevant Web3 API docs are here plus recent additions in #3566

assert(err.message.includes('1012'));
assert(err.message.includes('restart'));
web3.currentProvider.once('close', function(event){
assert.strictEqual(event.code, 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe this test should continue work as expected. The disconnect uses an error code. Test was added in #3486.

@cgewecke cgewecke self-requested a review June 19, 2020 16:59
@cgewecke
Copy link
Collaborator

There's an (abandoned) PR converting to N-API in the current Websocket repo fwiw.

theturtle/Websocket PR 302

@ryanio ryanio added the Enhancement Includes improvements or optimizations label Jun 22, 2020
@cgewecke
Copy link
Collaborator

For background - this PR is part of a NomicLabs led initiative to purge the JS Eth stack of dependencies that require node-gyp to install. It's the source of many problems as new Node versions come out and has bad installation UX.

In some cases this is straightforward and the substitution is painless.

In others there are tradeoffs to consider and this looks like one of them...

So far the proposed replacement's issues include:

  • Configurability not obviously equivalent.
  • Disconnection behavior not identical
  • Browser compatibility needs work.

cc: @GregTheGreek

@alcuadrado
Copy link

Thanks for raising these points, @cgewecke! We are now exploring fixing this in websocket instead. We'll report back when we have any updates.

@github-actions
Copy link

This PR has been automatically marked as stale beacause it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Jul 30, 2020
@GregTheGreek GregTheGreek removed the Stale Has not received enough activity label Jul 30, 2020
@GregTheGreek
Copy link
Contributor

This as been superseded by #3686

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Includes improvements or optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants