Skip to content

Trigger reconnection? #69

Open
Open
@khromov

Description

@khromov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions