terra.js
terra.js copied to clipboard
WebSocket in browser
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?
Two potential solutions:
- change the dependency to https://github.com/heineiuo/isomorphic-ws
- in browser environments, just use native WebSocket
Another solution is to separate WebSocketClient from Terra.js. Some of the reasons:
- The protocol is pretty straight forward, subscribe and listen.
- 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.
@dakom I would appreciate if you could test the compatibility with isomorphic-ws module
Another solution is to separate WebSocketClient from Terra.js. Some of the reasons:
- The protocol is pretty straight forward, subscribe and listen.
- 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