Class connection

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(socket: Socket, extensions: IExtension[], protocol: string, maskOutgoingPackets: boolean, config: IConfig): connection

Parameters

Returns

connection

Properties

public static CLOSE_REASON_ABNORMAL: number

public static CLOSE_REASON_EXTENSION_REQUIRED: number

public static CLOSE_REASON_GOING_AWAY: number

public static CLOSE_REASON_INVALID_DATA: number

public static CLOSE_REASON_MESSAGE_TOO_BIG: number

public static CLOSE_REASON_NORMAL: number

public static CLOSE_REASON_NOT_PROVIDED: number

public static CLOSE_REASON_POLICY_VIOLATION: number

public static CLOSE_REASON_PROTOCOL_ERROR: number

public static CLOSE_REASON_RESERVED: number

public static CLOSE_REASON_UNPROCESSABLE_INPUT: number

public assembleFragments: number

public bufferList: IBufferList

public bytesWaitingToFlush: number

public closeDescription: string

After the connection is closed, contains a textual description of the reason for the connection closure, or null if the connection is still open.

public closeReasonCode: number

After the connection is closed, contains the numeric close reason status code, or -1 if the connection is still open.

public closeTimeout: number

public config: IConfig

public connected: boolean

Whether or not the connection is still connected. Read-only

public currentFrame: frame

public extensions: IExtension[]

An array of extensions that were negotiated for this connection

public fragmentationSize: number

public frameHeader: Buffer

public frameQueue: frame[]

public maskBytes: Buffer

public maskOutgoingPackets: boolean

public maxReceivedMessageSize: number

public outputPaused: boolean

public protocol: string

The subprotocol that was chosen to be spoken on this connection. This field will have been converted to lower case.

public remoteAddress: string

The IP address of the remote peer as a string. In the case of a server, the X-Forwarded-For header will be respected and preferred for the purposes of populating this field. If you need to get to the actual remote IP address, socket.remoteAddress will provide it.

public socket: Socket

public socketHadError: boolean

public state: string

public waitingForCloseResponse: boolean

public webSocketVersion: number

The version of the WebSocket protocol requested by the client

Methods

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

Parameters

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

Returns

connection

public addListener(event: "'message'", cb: (data: "websocket".IMessage) => void): connection

Parameters

  • event: "'message'"
  • cb: (data: "websocket".IMessage) => void

Returns

connection

public addListener(event: "'frame'", cb: (frame: "websocket".frame) => void): connection

Parameters

  • event: "'frame'"
  • cb: (frame: "websocket".frame) => void

Returns

connection

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

Parameters

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

Returns

connection

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

Parameters

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

Returns

connection

public clearCloseTimer()

public close()

Close the connection. A close frame will be sent to the remote peer indicating that we wish to close the connection, and we will then wait for up to config.closeTimeout milliseconds for an acknowledgment from the remote peer before terminating the underlying socket connection.

public drop(reasonCode?: number, description?: string)

Send a close frame to the remote peer and immediately close the socket without waiting for a response. This should generally be used only in error conditions.

Parameters

  • reasonCode?: number optional
  • description?: string optional

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

Parameters

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

Returns

boolean

public fragmentAndSend(frame: frame, cb?: (err: Error) => void)

Parameters

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

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

Parameters

  • event: string

Returns

Array<Function>

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

Parameters

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

Returns

connection

public on(event: "'message'", cb: (data: "websocket".IMessage) => void): connection

Parameters

  • event: "'message'"
  • cb: (data: "websocket".IMessage) => void

Returns

connection

public on(event: "'frame'", cb: (frame: "websocket".frame) => void): connection

Parameters

  • event: "'frame'"
  • cb: (frame: "websocket".frame) => void

Returns

connection

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

Parameters

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

Returns

connection

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

Parameters

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

Returns

connection

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

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public ping(data: Buffer)

Sends a ping frame. Ping frames must not exceed 125 bytes in length.

Parameters

public ping(data: IStringified)

Parameters

public pong(buffer: Buffer)

Sends a pong frame. Pong frames may be sent unsolicited and such pong frames will trigger no action on the receiving peer. Pong frames sent in response to a ping frame must mirror the payload data of the ping frame exactly. The connection object handles this internally for you, so there should be no need to use this method to respond to pings. Pong frames must not exceed 125 bytes in length.

Parameters

public processFrame(frame: frame)

Parameters

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 send(data: Buffer)

Auto-detect the data type and send UTF-8 or Binary message

Parameters

public send(data: IStringified)

Parameters

public sendBytes(buffer: Buffer)

Immediately sends the specified Node Buffer object as a Binary WebSocket message to the remote peer. If config.fragmentOutgoingMessages is true the message may be sent as multiple fragments if it exceeds config.fragmentationThreshold bytes.

Parameters

public sendCloseFrame(reasonCode: number, reasonText: string, force: boolean)

Parameters

  • reasonCode: number
  • reasonText: string
  • force: boolean

public sendCloseFrame()

public sendFrame(frame: frame)

Serializes a frame object into binary data and immediately sends it to the remote peer. This is an advanced function, requiring you to manually compose your own frame. You should probably use sendUTF or sendBytes instead.

Parameters

public sendFrame(frame: frame, force: boolean, cb?: (msg: string) => void)

Parameters

  • frame: frame
  • force: boolean
  • cb?: (msg: string) => void optional

public sendFrame(frame: frame, cb?: (msg: string) => void)

Parameters

  • frame: frame
  • cb?: (msg: string) => void optional

public sendUTF(data: IStringified)

Immediately sends the specified string as a UTF-8 WebSocket message to the remote peer. If config.fragmentOutgoingMessages is true the message may be sent as multiple fragments if it exceeds config.fragmentationThreshold bytes.

Parameters

public setCloseTimer()

public setGracePeriodTimer()

public setKeepaliveTimer()

Set or reset the keepalive timer when data is received

public setMaxListeners(n: number)

Parameters

  • n: number