Interface EventSource

A W3C-compliant EventSource (server-sent events) client built on a fetch()-shaped transport, ReadableStream, and AbortController. Unlike the native browser EventSource, an event source built by this package supports request headers, a custom method with a request body, and a read timeout.

Remark

The SSE behavior stays as close as possible to the behavior of the original launchdarkly-eventsource package: the same event names and shapes, the same retry and backoff timing, and the same text/event-stream parser algorithm.

Remark

The Node-only options (https, proxy, agent, rejectUnauthorized) do not exist here, because fetch() has no equivalent for them; a caller that needs transport control injects a fetch-shaped function instead.

Remark

There is no onmessage slot. The LaunchDarkly SDKs register their message listeners with addEventListener('message', ...), so this implementation leaves the slot out on purpose.

See

https://html.spec.whatwg.org/multipage/server-sent-events.html

Hierarchy

  • EventSource

Properties

onclose: undefined | (() => void)

Called once when close() closes the stream, before the listeners registered for the closed event. Only the public close() method invokes it. An internal non-retryable termination dispatches the error and closed events without it, because the errorFilter caller already received that error. A server-sent SSE frame named closed reaches only the addEventListener('closed') listeners. Thus neither can look like a user-initiated close.

Type declaration

    • (): void
    • Returns void

onerror: undefined | ((event?) => void)

Called for a connection-level failure or an HTTP error response. A server-sent SSE frame named error also reaches this slot, with a MessageEvent payload; only that frame carries a string data property.

An exception this slot throws does not stop the reconnect that follows. The exception rethrows later, on a separate microtask.

Type declaration

    • (event?): void
    • Parameters

      Returns void

onopen: undefined | ((event) => void)

Called when a connection is established, with the HTTP response headers in the event.

An exception this slot throws does not stop the read loop from starting. The exception rethrows later, on a separate microtask.

Type declaration

    • (event): void
    • Parameters

      Returns void

onretrying: undefined | ((event) => void)

Called when a reconnect is scheduled, with the delay in the event.

An exception this slot throws does not stop the reconnect timer from arming. The exception rethrows later, on a separate microtask.

Type declaration

    • (event): void
    • Parameters

      Returns void

readyState: number
reconnectInterval: number

Mirrors the most recent server retry: field, in milliseconds; starts at 1000 before any retry: field has arrived. A server-directed value is capped at one hour. The retry strategy owns the actual reconnect timing; this slot only supplies the fallback delay for a reconnect whose strategy call throws, validated and capped at one hour at that point.

url: string

Methods

Generated using TypeDoc