pladaria / reconnecting-websocket

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

Support passing a function as url to the constructor #4

Closed pladaria closed 7 years ago

pladaria commented 8 years ago

This way the URL can easily change between reconnects

oxygen commented 7 years ago

Keeping track of websockets can be tedious. So, the same thing about changing the URL can be said about the keepClosed flag. It would be nice to have a keepClosedCallback. Right?

Thinking further, it would be nice that the entire options should be like a callback. And it is:

Considering objects in JavaScript are passed by reference, wouldn't it be simpler to just modify the reference of the options parameter, and thus be able to modify any option?

Making the URL in the constructor a function is incompatible with the standard and would make this entire library not swappable in certain scenarios.

It would be much better be able to specify the URL as an options attribute, AND for the reconnecting websocket to keep a reference to the options object.

pladaria commented 7 years ago

Ok, if someone has the need for it I will consider implementing that feature.

bennycode commented 7 years ago

@pladaria: A dynamic function to change the connection URL could help with our use case. 🙂

pladaria commented 7 years ago

Sorry for the delay, I've been really busy those days.

I hope this fits your needs :)