onclose behaviour has changed -- was it intentional?
See original GitHub issueI noticed my application was failing to reconnect after the reconnecting-websocket rewrite. Upon investigation, I realised this seems to be because this library no longer reconnects when a websocket is intentionally closed by the server – a close
event is triggered but nothing else happens.
Previously, a graceful server-side close event would trigger a reconnect: https://github.com/pladaria/reconnecting-websocket/blob/e79fba552f236463adac04e1872f5e20e37d66a1/index.ts#L141
…but now the reconnect is not triggered: https://github.com/pladaria/reconnecting-websocket/blob/2e5d6f0406784da357e3213506c9b508c2b32991/reconnecting-websocket.ts#L392
The reconnect mechanism is triggered on error
so I suspect this is an intentional change.
What do you think about adding a reconnectOnClose
option, on by default?
Alternatively the docs could be updated to clarify this behaviour, and perhaps suggest manually binding a reconnect such as:
rws.addEventListener('close', () => rws.reconnect());
Although that seems to cause thrashing if the connection cannot be established, as reconnect calls _disconnect
which calls the handlers again.
Thanks for the well written library.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:24 (4 by maintainers)
Is there any progress on this? Not reconnecting after server dropout totally devalues this library.
The same here, v3.2.2 behaves how most of us wants. @usefulthink has a good idea. Or maybe even better - old behavior should be preserved. At the end - that is a reason why most of us use this library.