Class WebSocket

Hierarchy

Index

Interfaces

Classes

Constructor methods

Properties

Methods

Functions

Interfaces

IServerOptions: IServerOptions

optional public clientTracking?: boolean

optional public disableHixie?: boolean

optional public handleProtocols?: any

optional public host?: string

optional public noServer?: boolean

optional public path?: string

optional public port?: number

optional public server?: Server

optional public verifyClient?: { (info: { origin: string; secure: boolean; req: "http".ClientRequest; }): boolean; (info: { origin: string; secure: boolean; req: "http".ClientRequest; }, callback: (res: boolean) => void): void; }

(): boolean

Returns

boolean

()

Classes

Server: Server

constructor(options?: IServerOptions, callback?: Function): Server

Parameters

Returns

Server

public clients: WebSocket[]

public options: IServerOptions

public path: string

public addListener(event: "'error'", cb: (err: Error) => void): Server

Parameters

  • event: "'error'"
  • cb: (err: Error) => void

Returns

Server

public addListener(event: "'headers'", cb: (headers: string[]) => void): Server

Parameters

  • event: "'headers'"
  • cb: (headers: string[]) => void

Returns

Server

public addListener(event: "'connection'", cb: (client: "ws".WebSocket) => void): Server

Parameters

  • event: "'connection'"
  • cb: (client: "ws".WebSocket) => void

Returns

Server

public addListener(event: string, listener: () => void): Server

Parameters

  • event: string
  • listener: () => void

Returns

Server

public close()

public emit(event: string, args?: Array<any>): boolean

Parameters

  • event: string
  • args?: Array<any> optional

Returns

boolean

public handleUpgrade(request: ServerRequest, socket: Socket, upgradeHead: Buffer, callback: (client: "ws".WebSocket) => void)

Parameters

public listeners(event: string): Array<Function>

Parameters

  • event: string

Returns

Array<Function>

public on(event: "'error'", cb: (err: Error) => void): Server

Parameters

  • event: "'error'"
  • cb: (err: Error) => void

Returns

Server

public on(event: "'headers'", cb: (headers: string[]) => void): Server

Parameters

  • event: "'headers'"
  • cb: (headers: string[]) => void

Returns

Server

public on(event: "'connection'", cb: (client: "ws".WebSocket) => void): Server

Parameters

  • event: "'connection'"
  • cb: (client: "ws".WebSocket) => void

Returns

Server

public on(event: string, listener: () => void): Server

Parameters

  • event: string
  • listener: () => void

Returns

Server

public once(event: string, listener: Function): EventEmitter

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public removeAllListeners(event?: string): EventEmitter

Parameters

  • event?: string optional

Returns

EventEmitter

public removeListener(event: string, listener: Function): EventEmitter

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public setMaxListeners(n: number)

Parameters

  • n: number

Constructor methods

constructor(address: string, options?: { protocol?: string; agent?: "http".Agent; headers?: { [key: string]: string; }; protocolVersion?: any; host?: string; origin?: string; pfx?: any; key?: any; passphrase?: string; cert?: any; ca?: any[]; ciphers?: string; rejectUnauthorized?: boolean; }): WebSocket

Parameters

  • address: string
  • options?: { protocol?: string; agent?: "http".Agent; headers?: { [key: string]: string; }; protocolVersion?: any; host?: string; origin?: string; pfx?: any; key?: any; passphrase?: string; cert?: any; ca?: any[]; ciphers?: string; rejectUnauthorized?: boolean; } optional

Returns

WebSocket

Properties

public static CLOSED: number

public CLOSED: number

public static CLOSING: number

public CLOSING: number

public static CONNECTING: number

public CONNECTING: number

public OPEN: number

public static OPEN: number

public bytesReceived: number

public onclose: (event: { wasClean: boolean; code: number; reason: string; target: "ws".WebSocket; }) => void

public onerror: (err: Error) => void

public onmessage: (event: { data: any; type: string; target: "ws".WebSocket; }) => void

public onopen: (event: { target: "ws".WebSocket; }) => void

public protocolVersion: string

public readyState: number

public supports: any

public url: string

Methods

public addEventListener(method: "'message'", cb?: (event: { data: any; type: string; target: "ws".WebSocket; }) => void)

Parameters

  • method: "'message'"
  • cb?: (event: { data: any; type: string; target: "ws".WebSocket; }) => void optional

public addEventListener(method: "'close'", cb?: (event: { wasClean: boolean; code: number; reason: string; target: "ws".WebSocket; }) => void)

Parameters

  • method: "'close'"
  • cb?: (event: { wasClean: boolean; code: number; reason: string; target: "ws".WebSocket; }) => void optional

public addEventListener(method: "'error'", cb?: (err: Error) => void)

Parameters

  • method: "'error'"
  • cb?: (err: Error) => void optional

public addEventListener(method: "'open'", cb?: (event: { target: "ws".WebSocket; }) => void)

Parameters

  • method: "'open'"
  • cb?: (event: { target: "ws".WebSocket; }) => void optional

public addEventListener(method: string, listener?: () => void)

Parameters

  • method: string
  • listener?: () => void optional

public addListener(event: "'error'", cb: (err: Error) => void): WebSocket

Parameters

  • event: "'error'"
  • cb: (err: Error) => void

Returns

WebSocket

public addListener(event: "'close'", cb: (code: number, message: string) => void): WebSocket

Parameters

  • event: "'close'"
  • cb: (code: number, message: string) => void

Returns

WebSocket

public addListener(event: "'message'", cb: (data: any, flags: { binary: boolean; }) => void): WebSocket

Parameters

  • event: "'message'"
  • cb: (data: any, flags: { binary: boolean; }) => void

Returns

WebSocket

public addListener(event: "'ping'", cb: (data: any, flags: { binary: boolean; }) => void): WebSocket

Parameters

  • event: "'ping'"
  • cb: (data: any, flags: { binary: boolean; }) => void

Returns

WebSocket

public addListener(event: "'pong'", cb: (data: any, flags: { binary: boolean; }) => void): WebSocket

Parameters

  • event: "'pong'"
  • cb: (data: any, flags: { binary: boolean; }) => void

Returns

WebSocket

public addListener(event: "'open'", cb: () => void): WebSocket

Parameters

  • event: "'open'"
  • cb: () => void

Returns

WebSocket

public addListener(event: string, listener: () => void): WebSocket

Parameters

  • event: string
  • listener: () => void

Returns

WebSocket

public close(code?: number, data?: any)

Parameters

  • code?: number optional
  • data?: any optional

public emit(event: string, args?: Array<any>): boolean

Parameters

  • event: string
  • args?: Array<any> optional

Returns

boolean

public listeners(event: string): Array<Function>

Parameters

  • event: string

Returns

Array<Function>

public on(event: "'error'", cb: (err: Error) => void): WebSocket

Parameters

  • event: "'error'"
  • cb: (err: Error) => void

Returns

WebSocket

public on(event: "'close'", cb: (code: number, message: string) => void): WebSocket

Parameters

  • event: "'close'"
  • cb: (code: number, message: string) => void

Returns

WebSocket

public on(event: "'message'", cb: (data: any, flags: { binary: boolean; }) => void): WebSocket

Parameters

  • event: "'message'"
  • cb: (data: any, flags: { binary: boolean; }) => void

Returns

WebSocket

public on(event: "'ping'", cb: (data: any, flags: { binary: boolean; }) => void): WebSocket

Parameters

  • event: "'ping'"
  • cb: (data: any, flags: { binary: boolean; }) => void

Returns

WebSocket

public on(event: "'pong'", cb: (data: any, flags: { binary: boolean; }) => void): WebSocket

Parameters

  • event: "'pong'"
  • cb: (data: any, flags: { binary: boolean; }) => void

Returns

WebSocket

public on(event: "'open'", cb: () => void): WebSocket

Parameters

  • event: "'open'"
  • cb: () => void

Returns

WebSocket

public on(event: string, listener: () => void): WebSocket

Parameters

  • event: string
  • listener: () => void

Returns

WebSocket

public once(event: string, listener: Function): EventEmitter

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public pause()

public ping(data?: any, options?: { mask?: boolean; binary?: boolean; }, dontFail?: boolean)

Parameters

  • data?: any optional
  • options?: { mask?: boolean; binary?: boolean; } optional
  • dontFail?: boolean optional

public pong(data?: any, options?: { mask?: boolean; binary?: boolean; }, dontFail?: boolean)

Parameters

  • data?: any optional
  • options?: { mask?: boolean; binary?: boolean; } optional
  • dontFail?: boolean optional

public removeAllListeners(event?: string): EventEmitter

Parameters

  • event?: string optional

Returns

EventEmitter

public removeListener(event: string, listener: Function): EventEmitter

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public resume()

public send(data: any, cb?: (err: Error) => void)

Parameters

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

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

Parameters

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

public setMaxListeners(n: number)

Parameters

  • n: number

public stream(options: { mask?: boolean; binary?: boolean; }, cb?: (err: Error, final: boolean) => void)

Parameters

  • options: { mask?: boolean; binary?: boolean; }
  • cb?: (err: Error, final: boolean) => void optional

public stream(cb?: (err: Error, final: boolean) => void)

Parameters

  • cb?: (err: Error, final: boolean) => void optional

public terminate()

Functions

connect(address: string, openListener?: Function)

Parameters

  • address: string
  • openListener?: Function optional

createConnection(address: string, openListener?: Function)

Parameters

  • address: string
  • openListener?: Function optional

createServer(options?: IServerOptions, connectionListener?: (client: "ws".WebSocket) => void): Server

Parameters

  • options?: IServerOptions optional
  • connectionListener?: (client: "ws".WebSocket) => void optional

Returns

Server