pladaria / reconnecting-websocket

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

Support immediate reconnect #27

Closed PaulSD closed 6 years ago

PaulSD commented 7 years ago

I have some code which periodically monitors the connection by sending an application-specific ping message and waiting for a response. If no response is received, I would like to disconnect and immediately attempt to reconnect (with no delay, since I've already delayed a long time waiting for the ping response). However, if the first reconnection attempt fails, I would like to delay additional reconnect attempts using the current reconnectDelay logic.

ReconnectingWebsocket.close() accepts a delay parameter that can be used to override reconnectDelay. However, if I set this to a low value (like 1) and the first reconnection attempt fails, then subsequent reconnect attempts will happen too rapidly.

Any suggestions for how to deal with this situation? Could another flag be added to close() to trigger an immediate reconnect without interfering with the existing reconnectDelay logic on subsequent reconnects if the immediate reconnect fails?

pladaria commented 6 years ago

Hi,

I've just released a new major version of the library, its a complete rewrite. It now has a reconnect method that should fit your needs.

Thanks. Any feedback is appreciated!