Class WebSocketServer

You must provide an error handler addEventListener('error'). Otherwise, errors will just be ignored.

Events:

Hierarchy

  • StartStop
    • WebSocketServer

Constructors

  • WebSocketServer.constructor

    • if opts.server is not provided, .start will create a new https server.
    • if opts.server is provided and not already listening, .start make the server start listening and use the provided server.
    • if opts.server is provided and already listening, .start use the provided server.
    • if opts.server is provided, verifyCallback and verifyPeer must be undefined, and the TLS verification policy will follow that of the underlying server.

    Parameters

    Returns WebSocketServer

Properties

[initLock]: RWLockWriter
_closed: boolean = false
_closedP: Promise<void>

Resolved when the underlying server is closed.

_host: string
_port: number
codeToReason?: StreamCodeToReason

Custom code to reason converted for new connections.

Configuration for new connections.

connectTimeoutTime?: number

Connection timeout for new connections.

connectionMap: WebSocketConnectionMap = ...

Map of connections with connectionId keys that correspond to WebSocketConnection values.

isServerShared: boolean

Determines whether the socket is injected or not

logger: Logger
reasonToCode?: StreamReasonToCode

Custom reason to code converter for new connections.

resolveClosedP: (() => void)

Type declaration

    • (): void
    • Returns void

resolveHostname: ResolveHostname
server: Server<typeof IncomingMessage, typeof ServerResponse>
webSocketServer: WebSocketServer
webSocketServerClosed: boolean = false

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

  • get closed(): boolean
  • Boolean that indicates whether the internal server is closed or not. This will be initially be false when WebSocketServer is constructed.

    Returns boolean

Methods

  • Parameters

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

    Returns void

  • Parameters

    • event: Event

    Returns boolean

  • Parameters

    • evt: EventAll<Event>

    Returns void

  • Used to trigger stopping if the underlying server fails

    Returns Promise<void>

  • Handles the creation of the ReadableWritablePair and provides it to the StreamPair handler.

    Parameters

    • webSocket: WebSocket
    • request: IncomingMessage

    Returns Promise<void>

  • Used to propagate error conditions

    Parameters

    • e: Error

    Returns void

  • Will tell any normal HTTP request to upgrade

    Parameters

    • _req: any
    • res: ServerResponse<IncomingMessage>

    Returns void

  • Parameters

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

    Returns void

  • Starts the WebSocketServer.

    If the server is shared and it is not listening, it will be started. If the server is not shared, a server will be created and started.

    Parameters

    • opts: {
          host?: string;
          ipv6Only?: boolean;
          path?: string;
          port?: number;
      } = {}
      • Optional host?: string

        host to listen on, defaults to '::'

      • Optional ipv6Only?: boolean

        ipv6 only, defaults to false

      • Optional path?: string

        the path the WebSocketServer should respond to upgrade requests on

      • Optional port?: number

        port to listen on, defaults to 0

    Returns Promise<void>

  • Stops WebSocketServer

    Parameters

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

        The error code to send to connections on closing

      • Optional errorMessage?: string

        The error message to send to connections on closing

      • Optional force?: boolean

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

    Returns Promise<void>

Generated using TypeDoc