Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitter
    • WebSocket

Index

Constructors

  • Parameters

    Returns WebSocket

  • Parameters

    • address: string | URL
    • Optional protocols: string | string[]
    • Optional options: ClientRequestArgs | WebSocket.ClientOptions

    Returns WebSocket

Properties

CLOSED: 3

The connection is closed.

CLOSING: 2

The connection is in the process of closing.

CONNECTING: 0

The connection is not yet open.

OPEN: 1

The connection is open and ready to communicate.

binaryType: "nodebuffer" | "arraybuffer" | "fragments"
bufferedAmount: number
extensions: string
onclose: (event: WebSocket.CloseEvent) => void

Type declaration

onerror: (event: WebSocket.ErrorEvent) => void

Type declaration

onmessage: (event: WebSocket.MessageEvent) => void

Type declaration

onopen: (event: WebSocket.Event) => void

Type declaration

protocol: string
readyState: 0 | 1 | 2 | 3

The current state of the connection

url: string
CLOSED: 3

The connection is closed.

CLOSING: 2

The connection is in the process of closing.

CONNECTING: 0

The connection is not yet open.

OPEN: 1

The connection is open and ready to communicate.

Methods

  • addListener(event: "close", listener: (code: number, reason: Buffer) => void): WebSocket
  • addListener(event: "error", listener: (err: Error) => void): WebSocket
  • addListener(event: "upgrade", listener: (request: IncomingMessage) => void): WebSocket
  • addListener(event: "message", listener: (data: WebSocket.RawData, isBinary: boolean) => void): WebSocket
  • addListener(event: "open", listener: () => void): WebSocket
  • addListener(event: "ping" | "pong", listener: (data: Buffer) => void): WebSocket
  • addListener(event: "unexpected-response", listener: (request: ClientRequest, response: IncomingMessage) => void): WebSocket
  • addListener(event: string | symbol, listener: (...args: any[]) => void): WebSocket
  • Parameters

    • event: "close"
    • listener: (code: number, reason: Buffer) => void
        • (code: number, reason: Buffer): void
        • Parameters

          • code: number
          • reason: Buffer

          Returns void

    Returns WebSocket

  • Parameters

    • event: "error"
    • listener: (err: Error) => void
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns WebSocket

  • Parameters

    • event: "upgrade"
    • listener: (request: IncomingMessage) => void
        • (request: IncomingMessage): void
        • Parameters

          • request: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    • event: "open"
    • listener: () => void
        • (): void
        • Returns void

    Returns WebSocket

  • Parameters

    • event: "ping" | "pong"
    • listener: (data: Buffer) => void
        • (data: Buffer): void
        • Parameters

          • data: Buffer

          Returns void

    Returns WebSocket

  • Parameters

    • event: "unexpected-response"
    • listener: (request: ClientRequest, response: IncomingMessage) => void
        • (request: ClientRequest, response: IncomingMessage): void
        • Parameters

          • request: ClientRequest
          • response: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns WebSocket

  • close(code?: number, data?: string | Buffer): void
  • Parameters

    • Optional code: number
    • Optional data: string | Buffer

    Returns void

  • Parameters

    • event: "close"
    • listener: (this: WebSocket, code: number, reason: Buffer) => void
        • (this: WebSocket, code: number, reason: Buffer): void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    • event: "error"
    • listener: (this: WebSocket, err: Error) => void

    Returns WebSocket

  • Parameters

    • event: "upgrade"
    • listener: (this: WebSocket, request: IncomingMessage) => void
        • (this: WebSocket, request: IncomingMessage): void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    • event: "ping" | "pong"
    • listener: (this: WebSocket, data: Buffer) => void

    Returns WebSocket

  • Parameters

    • event: "unexpected-response"
    • listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void
        • (this: WebSocket, request: ClientRequest, response: IncomingMessage): void
        • Parameters

          • this: WebSocket
          • request: ClientRequest
          • response: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    • event: string | symbol
    • listener: (this: WebSocket, ...args: any[]) => void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    • event: "close"
    • listener: (this: WebSocket, code: number, reason: Buffer) => void
        • (this: WebSocket, code: number, reason: Buffer): void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    • event: "error"
    • listener: (this: WebSocket, err: Error) => void

    Returns WebSocket

  • Parameters

    • event: "upgrade"
    • listener: (this: WebSocket, request: IncomingMessage) => void
        • (this: WebSocket, request: IncomingMessage): void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    • event: "ping" | "pong"
    • listener: (this: WebSocket, data: Buffer) => void

    Returns WebSocket

  • Parameters

    • event: "unexpected-response"
    • listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void
        • (this: WebSocket, request: ClientRequest, response: IncomingMessage): void
        • Parameters

          • this: WebSocket
          • request: ClientRequest
          • response: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    • event: string | symbol
    • listener: (this: WebSocket, ...args: any[]) => void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    • event: "close"
    • listener: (this: WebSocket, code: number, reason: Buffer) => void
        • (this: WebSocket, code: number, reason: Buffer): void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    • event: "error"
    • listener: (this: WebSocket, err: Error) => void

    Returns WebSocket

  • Parameters

    • event: "upgrade"
    • listener: (this: WebSocket, request: IncomingMessage) => void
        • (this: WebSocket, request: IncomingMessage): void
        • Parameters

          Returns void

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    • event: "ping" | "pong"
    • listener: (this: WebSocket, data: Buffer) => void

    Returns WebSocket

  • Parameters

    • event: "unexpected-response"
    • listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void
        • (this: WebSocket, request: ClientRequest, response: IncomingMessage): void
        • Parameters

          • this: WebSocket
          • request: ClientRequest
          • response: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    • event: string | symbol
    • listener: (this: WebSocket, ...args: any[]) => void
        • Parameters

          Returns void

    Returns WebSocket

  • ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void
  • Parameters

    • Optional data: any
    • Optional mask: boolean
    • Optional cb: (err: Error) => void
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void
  • Parameters

    • Optional data: any
    • Optional mask: boolean
    • Optional cb: (err: Error) => void
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • removeListener(event: "close", listener: (code: number, reason: Buffer) => void): WebSocket
  • removeListener(event: "error", listener: (err: Error) => void): WebSocket
  • removeListener(event: "upgrade", listener: (request: IncomingMessage) => void): WebSocket
  • removeListener(event: "message", listener: (data: WebSocket.RawData, isBinary: boolean) => void): WebSocket
  • removeListener(event: "open", listener: () => void): WebSocket
  • removeListener(event: "ping" | "pong", listener: (data: Buffer) => void): WebSocket
  • removeListener(event: "unexpected-response", listener: (request: ClientRequest, response: IncomingMessage) => void): WebSocket
  • removeListener(event: string | symbol, listener: (...args: any[]) => void): WebSocket
  • Parameters

    • event: "close"
    • listener: (code: number, reason: Buffer) => void
        • (code: number, reason: Buffer): void
        • Parameters

          • code: number
          • reason: Buffer

          Returns void

    Returns WebSocket

  • Parameters

    • event: "error"
    • listener: (err: Error) => void
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns WebSocket

  • Parameters

    • event: "upgrade"
    • listener: (request: IncomingMessage) => void
        • (request: IncomingMessage): void
        • Parameters

          • request: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    Returns WebSocket

  • Parameters

    • event: "open"
    • listener: () => void
        • (): void
        • Returns void

    Returns WebSocket

  • Parameters

    • event: "ping" | "pong"
    • listener: (data: Buffer) => void
        • (data: Buffer): void
        • Parameters

          • data: Buffer

          Returns void

    Returns WebSocket

  • Parameters

    • event: "unexpected-response"
    • listener: (request: ClientRequest, response: IncomingMessage) => void
        • (request: ClientRequest, response: IncomingMessage): void
        • Parameters

          • request: ClientRequest
          • response: IncomingMessage

          Returns void

    Returns WebSocket

  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns WebSocket

  • send(data: any, cb?: (err?: Error) => void): void
  • send(data: any, options: { binary?: boolean; compress?: boolean; fin?: boolean; mask?: boolean }, cb?: (err?: Error) => void): void
  • Parameters

    • data: any
    • Optional cb: (err?: Error) => void
        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns void

  • Parameters

    • data: any
    • options: { binary?: boolean; compress?: boolean; fin?: boolean; mask?: boolean }
      • Optional binary?: boolean
      • Optional compress?: boolean
      • Optional fin?: boolean
      • Optional mask?: boolean
    • Optional cb: (err?: Error) => void
        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns void

  • terminate(): void
  • Returns void