Open mschipperheyn opened 8 years ago
One of the interesting ways to do this is to have a variable timer. Start with 2s, if it doesnt reconnect go to 4, then 8 etc. Have an option to have a max time (E.g 3-5 mins). Once reconnected, the next reconnect timer (if disconnected) would start again at 2s. This should reduce drain on battery (it would be 20 polls at max time of 3 mins, as opposed to 1800 polls at a max time of 2s).
Looks like the author added "reconnectDecay", which should let you do this.
I have implemented this based on an adapted version of a reconnection library. I can send this if ibterestibg. Only thing g I still need to do is deal with expired server sessions against a websocket that is still alive.
robust-websocket
allows you to fully configure when to reconnect via a function callback
@nathanboktae I like the premise of where you are going with robust-websocket. However, can I suggest that we improve reconnecting-websocket to include tests and other things that you deem are missing? This project already has 1k+ followers. So rather than fork the userbase, I suggest adding to and improving this project.
-Amar
I considered that @aparmar but there's too many issues with this library on fundamental levels that I started a new project fresh, especially with 0 tests. I have no idea how the library truly works without tests and contracts being validated constantly, and evidence to the users of that package that they are. Also, the maintainer seems not so active these days.
In a mobile scenario, often the internet connection is not available. In that case it doesn't seem to make sense, and I wouldn't be surprised if it was detrimental to battery life, to keep trying to reconnect.
It might be interesting to add a function reference that returns a boolean on whether to attempt a reconnect at all. This function could in a mobile scenario return true if connected and false if offline.