terra.js icon indicating copy to clipboard operation
terra.js copied to clipboard

WebSocket in browser

Open dakom opened this issue 3 years ago • 5 comments
trafficstars

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 avatar Jan 02 '22 19:01 dakom

Two potential solutions:

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

dakom avatar Jan 02 '22 20:01 dakom

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 avatar Jan 10 '22 06:01 hanjukim

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

hanjukim avatar Jan 10 '22 06:01 hanjukim

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

sascha1337 avatar Mar 26 '22 19:03 sascha1337