reconnecting-eventsource icon indicating copy to clipboard operation
reconnecting-eventsource copied to clipboard

Trigger reconnection?

Open khromov opened this issue 1 year ago • 0 comments

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();
    }
}

khromov avatar Feb 27 '23 23:02 khromov