import { FetchEventSourceInit } from '@microsoft/fetch-event-source'; import React, { Context } from 'react'; declare type SseURL = string; declare type SseConnectionID = string; interface EventMessage { source: string; timestamp: number; event: T; } interface EventSourceMessage { id: string; event: string; data: T; retry?: number; } /** * If SSE connection is lost (e.g. due to unreliable mobile network) * then reconnect is retried every 15 seconds. In case of having * a successful REST-call during that period, an SSE potentially * caused by this REST-call would be lost. To avoid this situation * the wakeup-callback can be used by REST-clients to trigger * SSE reconnect immediately instead of waiting to the end of the * 15 seconds period. If network is available the SSE connection * will be established before doing the REST-call and therefore * any potentially triggered SSE can be received and processed. */ declare type WakeupSseCallback = (() => void) | undefined; declare type OnMessageFunction = (ev: EventSourceMessage) => void; declare type GuiSseHook = (onMessage: OnMessageFunction, messageName?: string | RegExp) => WakeupSseCallback; declare type GetConnectionFunction = (onMessage: OnMessageFunction, messageName?: string | RegExp) => SseConnectionID; declare type ReleaseConnectionFunction = (connectionId: SseConnectionID) => void; declare type SseContextInterface = { wakeupSseCallback: WakeupSseCallback; getConnection: GetConnectionFunction; releaseConnection: ReleaseConnectionFunction; }; interface SseProviderProps extends Omit { Context: Context; buildFetchApi: () => WindowOrWorkerGlobalScope['fetch']; url: SseURL; } declare const SseProvider: ({ url, Context, buildFetchApi, children, ...rest }: React.PropsWithChildren) => JSX.Element; declare const useSse: (Context: React.Context, onMessage: OnMessageFunction, messageName?: string | RegExp) => WakeupSseCallback; export { EventMessage, EventSourceMessage, GuiSseHook, OnMessageFunction, SseContextInterface, SseProvider, WakeupSseCallback, useSse };