Class request

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(socket: Socket, httpRequest: ClientRequest, config: IServerConfig): request

Parameters

Returns

request

Properties

public cookies: ICookie[]

public host: string

This will include the port number if a non-standard port is used

public httpRequest: ClientRequest

A reference to the original Node HTTP request object

public key: string

Sec-WebSocket-Key

public origin: string

If the client is a web browser, origin will be a string containing the URL of the page containing the script that opened the connection. If the client is not a web browser, origin may be null or "*".

public protocolFullCaseMap: { [key: string]: string; }

(): string

Returns

string

public remoteAddress: string

Client's IP. If an X-Forwarded-For header is present, the value will be taken from that header to facilitate WebSocket servers that live behind a reverse-proxy

public requestedExtensions: Array<any>

An array containing a list of extensions requested by the client

public requestedProtocols: Array<string>

List of strings that indicate the subprotocols the client would like to speak. The server should select the best one that it can support from the list and pass it to the accept function when accepting the connection. Note that all the strings in the requestedProtocols array will have been converted to lower case.

public resource: string

A string containing the path that was requested by the client

public resourceURL: Url

Parsed resource, including the query string parameters

public socket: Socket

public webSocketVersion: number

The version of the WebSocket protocol requested by the client

Methods

public accept(acceptedProtocol?: string, allowedOrigin?: string, cookies?: ICookie[]): connection

After inspecting the request properties, call this function on the request object to accept the connection. If you don't have a particular subprotocol you wish to speak, you may pass null for the acceptedProtocol parameter.

Parameters

  • acceptedProtocol?: string optional
  • allowedOrigin?: string optional
  • cookies?: ICookie[] optional

Returns

connection

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

Parameters

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

Returns

request

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

Parameters

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

Returns

request

public addListener(event: "'requestRejected'", cb: () => void): request

Parameters

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

Returns

request

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: string, listener: () => void): request

Parameters

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

Returns

request

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

Parameters

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

Returns

request

public on(event: "'requestRejected'", cb: () => void): request

Parameters

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

Returns

request

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

Parameters

  • event: string
  • listener: Function

Returns

EventEmitter

public reject(httpStatus?: number, reason?: string)

Reject connection. You may optionally pass in an HTTP Status code (such as 404) and a textual description that will be sent to the client in the form of an X-WebSocket-Reject-Reason header.

Parameters

  • httpStatus?: number optional
  • reason?: string 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 setMaxListeners(n: number)

Parameters

  • n: number