Optional bodyOptional createCreates the listener registry for this instance. The registry stores the listeners
registered through addEventListener. When this option is absent, the instance uses the
internal Map-backed registry (createDefaultEventRegistry).
A substitute must satisfy EventListenerRegistry. An SDK can supply one that uses a
native eventing primitive, such as Node's EventEmitter. A raw EventEmitter throws from
emit('error') when error has no listener. An EventEmitter-backed substitute must
guard against that case.
The registry is trusted code. It sees every event this instance dispatches, and it controls what its listeners receive.
createEventSource throws a TypeError that names createEventRegistry when this option
is not a function, or when the returned value is missing a required EventListenerRegistry
method.
This function must return a new registry on each call. createEventSource calls it once
per instance. When a factory returns one shared registry for more than one instance, the
separate event sources deliver each other's events.
Decides if the client retries a given error. Return false to stop the retries and close the stream. When this field is not set, the client retries I/O errors and HTTP 500, 502, 503, and 504.
Optional fetchThe transport used to open the stream. When absent, the client uses the global fetch.
The client only needs the structural subset declared by FetchLike, so a real fetch
implementation satisfies this option without casts. A platform without a suitable global
fetch, or one that needs agents, proxies, or TLS configuration, supplies a function with
the same shape over its own transport.
Optional jitterIf set, the client decreases each computed retry delay by a random amount. The maximum decrease is this fraction of the delay.
Optional maxIf set, retry delays grow exponentially up to this limit.
Optional methodOptional retryReplaces the built-in retry delay behavior with a caller-supplied strategy.
The client calls nextRetryDelay(currentTimeMillis) when it schedules a reconnect, and it
waits for the returned number of milliseconds. The client calls
setGoodSince(goodSinceTimeMillis) when the first event of a connection arrives. The client
calls setBaseDelay(delayMillis) when the server sends a retry: field. The value reaches
the strategy already validated as all ASCII digits and capped at one hour.
When this option is set, it fully replaces the built-in strategy. The tuning options
initialRetryDelayMillis, maxBackoffMillis, jitterRatio, and
retryResetIntervalMillis have no effect. When this option is absent, the built-in
strategy applies and those options work as documented.
An exception a strategy method throws does not stop the stream or the reconnect. The client falls back to the last reconnect interval for the delay, and the exception rethrows later, on a separate microtask.
Optional skipWhen true, the request omits the default Cache-Control: no-cache and
Accept: text/event-stream headers.
Optional urlReturns the URL for the next connection attempt. When set, the client calls this function immediately before each request, including the first. This keeps a query parameter current when the parameter changes between attempts.
Optional withWhen true, the client sends credentials (cookies, HTTP authentication) with the request, including
a cross-origin request. This flag maps to credentials: 'include' in fetch(). A transport without a
credentials concept ignores it.
Generated using TypeDoc
The options that
createEventSourceunderstands.The first group of fields mirrors the platform's
EventSourceInitDict. Each field that the SDK supplies stays required here, to match the platform contract. A caller that callscreateEventSourcedirectly can omit each field, because that function's parameter isPartial<...>. A missing field falls back to a default (errorFilter,initialRetryDelayMillis), or the feature stays off (headers,readTimeoutMillis,retryResetIntervalMillis).