Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger reconnection? #69

Open
khromov opened this issue Feb 27, 2023 · 0 comments
Open

Trigger reconnection? #69

khromov opened this issue Feb 27, 2023 · 0 comments

Comments

@khromov
Copy link

khromov commented Feb 27, 2023

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();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant