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

WebSocket in browser #202

Open
dakom opened this issue Jan 2, 2022 · 4 comments
Open

WebSocket in browser #202

dakom opened this issue Jan 2, 2022 · 4 comments

Comments

@dakom
Copy link
Contributor

dakom commented Jan 2, 2022

Terra.JS is using ws which states explicitly:

This module does not work in the browser.

Additionally, attempting to follow the instructions in the documentation from a browser throws an error:

ws does not work in the browser. Browser clients must use the native WebSocket object

So... how are browser clients supposed to subscribe over RPC/WebSockets?

@dakom
Copy link
Contributor Author

dakom commented Jan 2, 2022

Two potential solutions:

  1. change the dependency to https://github.com/heineiuo/isomorphic-ws
  2. in browser environments, just use native WebSocket

@hanjukim
Copy link
Contributor

hanjukim commented Jan 10, 2022

Another solution is to separate WebSocketClient from Terra.js. Some of the reasons:

  1. The protocol is pretty straight forward, subscribe and listen.
  2. WebsocketClient module doesn't have type or module dependency from in Terra.js library

It has its own reconnecting logic inside, but we (in our infrastructure) decided not to use WebSocketClient module in Terra.js because of the bug we found that sometimes it doesn't work.

@hanjukim
Copy link
Contributor

hanjukim commented Jan 10, 2022

@dakom I would appreciate if you could test the compatibility with isomorphic-ws module

@sascha1337
Copy link

Another solution is to separate WebSocketClient from Terra.js. Some of the reasons:

  1. The protocol is pretty straight forward, subscribe and listen.
  2. WebsocketClient module doesn't have type or module dependency from in Terra.js library

It has its own reconnecting logic inside, but we (in our infrastructure) decided not to use WebSocketClient module in Terra.js because of the bug we found that sometimes it doesn't work.

might be fixed by today, some time passed, but that ws thing with that node-buffer thing, solved, could reduce the polyfill rabbit hole

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

No branches or pull requests

3 participants