pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

Better instructions for using reconnecting-websocket in browser client #55

Closed jschulenklopper closed 6 years ago

jschulenklopper commented 6 years ago

Using this package in a browser client application (instead of from a Node.js application) does not seem to be sufficiently covered in the documentation.

That is, the simple case

const ReconnectingWebSocket = require('reconnecting-websocket');
const rws = new ReconnectingWebSocket('ws://my.site.com');

rws.addEventListener('open', () => {
    rws.send('hello!');
});

does not work out-of-the-box because it requires RequireJS client-side. And getting reconnecting-websocket to work in combination with RequireJS isn't trivial, as even the troubleshooting section at http://requirejs.org/docs/errors.html#notloaded does not clearly provide solutions for getting it working.

I guess that a basic instruction "How/where to install reconnecting-websocket in your client-side web application directory structure" would help out greatly.

pladaria commented 6 years ago

That example was meant to work with node.js. Anyway, I've just released a new version and examples now use ES modules.

Please, feel free to open a new ticket if something isn't clear.