Function connectEventSource

  • Internal

    Sanity API specific EventSource handler shared between the listen and live APIs

    Since the EventSource API is not provided by all environments, this function enables custom initialization of the EventSource instance for runtimes that requires polyfilling or custom setup logic (e.g. custom HTTP headers) via the passed initEventSource function which must return an EventSource instance.

    Possible errors to be thrown on the returned observable are:

    Type Parameters

    • EventName extends string

    Parameters

    • initEventSource: () => EventSource | Observable<EventSource>

      A function that returns an EventSource instance or an Observable that resolves to an EventSource instance

    • events: EventName[]

      an array of named events from the API to listen for.

    Returns Observable<ServerSentEvent<EventName>>