Class WebSocketConnection

Think of this as equivalent to net.Socket. This is one-to-one with the ws.WebSocket. Errors here are emitted to the connection only. Not to the server.

Events:

Note that on TLS verification failure, EventWebSocketConnectionError is emitted with the following event.detail:

The reason for this is that when the peer fails to verify us, Node only tells us that the TCP socket has been reset, but not why.

Hierarchy

  • StartStop
    • WebSocketConnection

Constructors

Properties

[initLock]: RWLockWriter
_localHost?: Host
_localPort?: Port
_remoteHost: Host
_remotePort: Port
caDERs: Uint8Array[] = []
certDERs: Uint8Array[] = []
closeSocket: ((errorCode?: number, reason?: string) => void)

Type declaration

    • (errorCode?: number, reason?: string): void
    • Parameters

      • Optional errorCode: number
      • Optional reason: string

      Returns void

closedP: Promise<void>

Connection closed promise. This can resolve or reject.

codeToReason: StreamCodeToReason

Converts code to reason. Used during WebSocketStream creation.

connectionId: number

This is the source connection ID.

This stores the last dispatched error. If no error has occurred, it will be null.

keepAliveIntervalTimer?: Timer<void>
keepAliveResponsibilityEstablishedP: Promise<boolean>

Promise that resolves once the keepAliveResponsibility has been established. This is true if we are responsible for sending pings, and false when the peer is responsible.

keepAliveTimeOutTimer?: Timer<void>
logger: Logger
pingsReceived: number = 0
pongsReceived: number = 0
reasonToCode: StreamReasonToCode

Converts reason to code. Used during WebSocketStream creation.

rejectSecureEstablishedP: ((reason?: any) => void)

Type declaration

    • (reason?: any): void
    • Parameters

      • Optional reason: any

      Returns void

remoteCertDERs: Uint8Array[] = []
resolveClosedP: (() => void)

Type declaration

    • (): void
    • Returns void

resolveKeepAliveResponsibilityEstablishedP: ((isResponsible: boolean) => void)

Type declaration

    • (isResponsible: boolean): void
    • Parameters

      • isResponsible: boolean

      Returns void

resolveSecureEstablishedP: (() => void)

Type declaration

    • (): void
    • Returns void

secureEstablished: boolean = false

Secure connection establishment. This can resolve or reject. Will resolve after connection has established and peer certs have been validated. Rejections cascade down to secureEstablishedP and closedP.

secureEstablishedP: Promise<void>
sendReadyP: undefined | Promise<void>

This should never reject.

socketLocallyClosed: boolean = false
streamIdClientBidi: VarInt = ...

Client initiated bidirectional stream starts at 0. Increment by 4 to get the next ID.

streamIdLock: Lock = ...

Stream ID increment lock.

streamIdServerBidi: VarInt = ...

Server initiated bidirectional stream starts at 1. Increment by 4 to get the next ID.

type: "client" | "server"

This determines when it is a client or server connection.

Accessors

  • get [eventHandled](): ReadonlyWeakSet<Event>
  • Returns ReadonlyWeakSet<Event>

  • get [eventHandlers](): ReadonlyMap<string, Set<EventHandlerInfo>>
  • Returns ReadonlyMap<string, Set<EventHandlerInfo>>

  • get [eventTarget](): EventTarget
  • Returns EventTarget

  • get [handleEventError](): ((evt: EventError) => void)
  • Returns ((evt: EventError) => void)

      • (evt: EventError): void
      • Parameters

        • evt: EventError

        Returns void

  • get [running](): boolean
  • Returns boolean

  • get [statusP](): Promise<Status>
  • Returns Promise<Status>

  • get [status](): Status
  • Returns Status

Methods

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Parameters

    • event: Event

    Returns boolean

  • Gets an array of CA certificates in DER format starting on the leaf.

    This will be empty if:

    • the connection was instantiated by a WebSocketServer with an injected https.Server or
    • the connection was instantiated by a WebSocketClient running in a browser

    Returns Uint8Array[]

  • Gets an array of local certificates in DER format starting on the leaf.

    This will be empty if:

    • the connection was instantiated by a WebSocketServer with an injected https.Server or
    • the connection was instantiated by a WebSocketClient running in a browser

    Returns Uint8Array[]

  • Gets an array of peer certificates in DER format starting on the leaf.

    This will be empty if the connection was instantiated by a WebSocketClient running in a browser.

    Returns Uint8Array[]

  • Parameters

    • errorCode: number
    • reason: Buffer

    Returns void

  • Parameters

    • data: RawData
    • isBinary: boolean

    Returns Promise<void>

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Send data on the WebSocket

    Parameters

    • data: Uint8Array | Uint8Array[]

    Returns Promise<void>

  • Stops WebSocketConnection

    Parameters

    • opts: {
          errorCode?: number;
          force?: boolean;
          reason?: string;
      } = {}
      • Optional errorCode?: number

        The error code to send to the peer on closing

      • Optional force?: boolean

        When force is false, the returned promise will wait for all streams to close naturally before resolving.

      • Optional reason?: string

    Returns Promise<void>

Generated using TypeDoc