websocket-ts
    Preparing search index...

    Class Websocket

    A websocket wrapper that can be configured to reconnect automatically and buffer messages when the websocket is not connected.

    Index

    Constructors

    Accessors

    • get backoff(): undefined | Backoff

      Getter for the backoff.

      Returns undefined | Backoff

      the backoff, or undefined if none was provided.

    • get buffer(): | undefined
      | WebsocketBuffer<
          string
          | ArrayBufferLike
          | Blob
          | ArrayBufferView<ArrayBufferLike>,
      >

      Getter for the buffer.

      Returns
          | undefined
          | WebsocketBuffer<
              string
              | ArrayBufferLike
              | Blob
              | ArrayBufferView<ArrayBufferLike>,
          >

      the buffer, or undefined if none was provided.

    • get closedByUser(): boolean

      Whether the websocket was closed by the user. A websocket is closed by the user by calling close().

      Returns boolean

      true if the websocket was closed by the user, false otherwise.

    • get instantReconnect(): undefined | boolean

      Getter for the instantReconnect.

      Returns undefined | boolean

      the instantReconnect, or undefined if none was provided.

    • get lastConnection(): undefined | Date

      Getter for the last 'open' event, e.g. the last time the websocket was connected.

      Returns undefined | Date

      the last 'open' event, or undefined if the websocket was never connected.

    • get maxRetries(): undefined | number

      Getter for the maxRetries.

      Returns undefined | number

      the maxRetries, or undefined if none was provided (no limit).

    • get protocols(): undefined | string | string[]

      Getter for the protocols.

      Returns undefined | string | string[]

      the protocols, or undefined if none were provided.

    • get url(): string

      Getter for the url.

      Returns string

      the url.

    Methods

    • Sends data over the websocket.

      If the websocket is not connected and a buffer was provided on creation, the data will be added to the buffer. If no buffer was provided or the websocket was closed by the user, the data will be dropped.

      Parameters

      • data: string | ArrayBufferLike | Blob | ArrayBufferView<ArrayBufferLike>

        to send.

      Returns void