This class is a wrapper for web sockets, that allows to receive messages with async / await instead of using callbacks (onmessage onopen ...)

It also has a on('message') event, because sometimes you just need it. When you solely use the event based interface, and don't use the waitForMessage functions, then you need to set disableWaitForMessage to true, because otherwise you will get an error that you didn't collect incoming messages with waitFor... functions.

Implements

Constructors

  • Construct a new connection - at the moment based on WebSockets

    Parameters

    • webSocket: WebSocket
    • defaultOpenTimeout: number = Number.POSITIVE_INFINITY

    Returns default

Properties

id: number = ++Connection.idCounter
onMessage: OEvent<((message: string | Uint8Array) => void)> = ...

Event is emitted when a new message is received.

state: StateMachine<"closed" | "connecting" | "open", "open" | "close">

Accessors

  • get bufferedAmount(): number
  • Chum streams use the websocket bufferedAmount number to control how fast the streams provide data to the websocket stream.

    Returns number

Methods

  • Add a plugin to the connection.

    Parameters

    • plugin: default
    • Optionaloptions: {
          after?: string;
          before?: string;
      }
      • Optionalafter?: string
      • Optionalbefore?: string

    Returns void

  • Wait for the socket to be open.

    Parameters

    • Optionaltimeout: number

    Returns Promise<void>