Class BaseEventSourceAbstract

Base class for EventSource implementation

Implement BaseSource 101:

  • extends this class
  • constructor(url, eventSourceInitDict) :
    • take url as first argument
    • an eventSourceInitDict as second argument, for request options
    • merge EVENT_STREAM_HEADERS EVENT_STREAM_HEADERS in eventSourceInitDict.headers
    • run the request
    • on response :
  • cleaning() clean resources stored and unassign them

See

https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface for the spec

Note for reader on typedoc, activate Protected member visibility, by default only Inherited is selected

Hierarchy

Constructors

Properties

_readyState: undefined | number
onerror: undefined | ((event: Event) => void)
onmessage: undefined | ((event: Event) => void)
onopen: undefined | ((event: Event) => void)
url: string
CLOSED: CLOSED = ReadyState.CLOSED
CONNECTING: CONNECTING = ReadyState.CONNECTING
OPEN: OPEN = ReadyState.OPEN

Accessors

Methods

  • Adds a new handler for the type event. Any given listener is added only once per type and per capture option value.

    If the once option is true, the listener is removed after the next time a type event is dispatched.

    The capture option is not used by Node.js in any functional way other than tracking registered event listeners per the EventTarget specification. Specifically, the capture option is used as part of the key when registering a listener. Any individual listener may be added once with capture = false, and once with capture = true.

    Parameters

    • type: string
    • listener: EventListener | EventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • MUST be implemented by child class

    Example

    protected cleaning() {
    // clean resources
    // ex
    this.#request?.destroy();
    this.#request = undefined;
    }

    Returns void

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    Parameters

    • event: Event

    Returns boolean

  • Protected

    build an error attach to an event error and dispatch the event

    Returns void

  • MUST be implemented by child class

    Parameters

    • url: string

    Returns void

  • Protected
    • listen error on stream to signal in EventTarget way
    • listen on data on stream to signal it EventTarget way (message, named event)

    Parameters

    • stream: TransformParser
    • onErrorCleanUp: (() => void)
        • (): void
        • Returns void

    Returns void

  • Protected

    Check if response 200 or Content-Type is text/event-stream

    Parameters

    • response: {
          headers?: IncomingHttpHeaders;
          statusCode?: number;
      }
      • Optional headers?: IncomingHttpHeaders
      • Optional statusCode?: number

    Returns boolean

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    Parameters

    • type: string
    • listener: EventListener | EventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Dispatch an event error

    Parameters

    • error: Error

    Returns void

  • Dispatch a message with an IEvent and try to dispatch named event from message event

    Parameters

    Returns void

Generated using TypeDoc