reconnecting-eventsource
reconnecting-eventsource copied to clipboard
Trigger reconnection?
Is there some way of triggering a reconnection of this library at any time?
When opening a hibernated tab in Chrome on Android, the connection has always failed at some point due to the tab hibernating. This library will try to reconnect but it will depend on the timeout how long it takes. Since I can get a focus listener using window.addEventListener('focus', handleFocusEvents);
I would really like to trigger a reconnection as soon as this event fires to minimize the downtime for users.
I can do something like this, however it feels a bit hacky. Is there a better way?
const events = new ReconnectingEventSource(...);
// Some time later
const handleFocusEvents = (e) => {
if(events && events?._eventSource?.readyState === 2) {
events?._start();
}
}