SseClientOptions
Options of createSseClient.
Options of createSseClient.
Import#
ts
import type { SseClientOptions } from "@shadow-js/dusk/client";
Signature#
ts
interface SseClientOptions<T> {
/** The stream URL (relative URLs resolve against the page). */
readonly url: string;
/** Turns the data text into a value. Default: JSON, or the text when it is not JSON. */
readonly parse?: (raw: string) => T;
/** Receives each event. */
readonly onEvent: (event: SseEvent<T>) => void;
/** Receives each change of status. */
readonly onStatus?: (status: StreamStatus) => void;
/** Headers of every request (for example an authorization header). */
readonly headers?: HeadersInit;
/** Reconnection policy. */
readonly reconnect?: ReconnectOptions;
/** The `fetch` to use. Default: the global one. */
readonly fetch?: typeof fetch;
/**
* Receives a failure of the client's own code (a `parse` or `onEvent` that threw) or an unexpected
* one. A network drop is not an error: it is retried. Default: `console.error`.
*/
readonly onError?: (error: unknown) => void;
}
Members#
| Name | Type | Description |
|---|---|---|
T |
T |
|
url |
readonly url: string |
The stream URL (relative URLs resolve against the page). |
parse? |
readonly parse?: (raw: string) => T |
Turns the data text into a value. Default: JSON, or the text when it is not JSON. |
onEvent |
readonly onEvent: (event: SseEvent<T>) => void |
Receives each event. |
onStatus? |
readonly onStatus?: (status: StreamStatus) => void |
Receives each change of status. |
headers? |
readonly headers?: HeadersInit |
Headers of every request (for example an authorization header). |
reconnect? |
readonly reconnect?: ReconnectOptions |
Reconnection policy. |
fetch? |
readonly fetch?: typeof fetch |
The fetch to use. Default: the global one. |
onError? |
readonly onError?: (error: unknown) => void |
Receives a failure of the client's own code (a parse or onEvent that threw) or an unexpected one. A network drop is not an error: it is retried. Default: console.error. |