Class SseClient

Client for managing Server-Sent Events (SSE) connections.

Hierarchy

  • SseClient

Constructors

  • Creates an instance of SseClient.

    Parameters

    • eventStreamUrl: string

      The URL of the event stream.

    Returns SseClient

Properties

eventSource?: EventSource
eventStreamUrl: string

The URL of the event stream.

parser: EventParser
subscribedTo: EventSubscription[] = []

Methods

  • Processes incoming messages from the event source and dispatches them to the appropriate handlers.

    Parameters

    • event: MessageEvent<string>

      The message event containing the event data.

    Returns void

  • Starts the SSE connection.

    Parameters

    • Optional eventId: number

      (Optional) The event ID to start streaming from.

    Returns void

  • Subscribes to a specified event.

    Returns

    A Result indicating success (Ok(true)) or failure (Err with an error message).

    Parameters

    • eventName: EventName

      The name of the event to subscribe to.

    • eventHandlerFn: EventHandlerFn

      The function to handle the event when it occurs.

    Returns Result<boolean, string>

  • Unsubscribes from a specified event.

    Returns

    A Result indicating success (Ok(true)) or failure (Err with an error message).

    Parameters

    • eventName: EventName

      The name of the event to unsubscribe from.

    Returns Result<boolean, string>

Generated using TypeDoc