@types/websocket
- Version 1.0.10
- Published
- 32.6 kB
- 1 dependency
- MIT license
Install
npm i @types/websocket
yarn add @types/websocket
pnpm add @types/websocket
Overview
TypeScript definitions for websocket
Index
Variables
Classes
connection
- addListener()
- assembleFragments
- bufferList
- bytesWaitingToFlush
- clearCloseTimer()
- clearGracePeriodTimer()
- clearKeepaliveTimer()
- close()
- CLOSE_DESCRIPTIONS
- CLOSE_REASON_ABNORMAL
- CLOSE_REASON_EXTENSION_REQUIRED
- CLOSE_REASON_GOING_AWAY
- CLOSE_REASON_INVALID_DATA
- CLOSE_REASON_MESSAGE_TOO_BIG
- CLOSE_REASON_NORMAL
- CLOSE_REASON_NOT_PROVIDED
- CLOSE_REASON_POLICY_VIOLATION
- CLOSE_REASON_PROTOCOL_ERROR
- CLOSE_REASON_RESERVED
- CLOSE_REASON_UNPROCESSABLE_INPUT
- closeDescription
- closeReasonCode
- closeTimeout
- config
- connected
- currentFrame
- drop()
- extensions
- fragmentAndSend()
- fragmentationSize
- frameHeader
- frameQueue
- handleCloseTimer()
- handleGracePeriodTimer()
- handleKeepaliveTimer()
- handleSocketClose()
- handleSocketData()
- handleSocketDrain()
- handleSocketEnd()
- handleSocketError()
- handleSocketPause()
- handleSocketResume()
- inputPaused
- maskBytes
- maskOutgoingPackets
- maxReceivedMessageSize
- on()
- outputBufferFull
- pause()
- ping()
- pong()
- processFrame()
- processReceivedData()
- protocol
- receivedEnd
- remoteAddress
- resume()
- send()
- sendBytes()
- sendCloseFrame()
- sendFrame()
- sendUTF()
- setCloseTimer()
- setGracePeriodTimer()
- setKeepaliveTimer()
- socket
- socketHadError
- state
- waitingForCloseResponse
- webSocketVersion
Interfaces
Type Aliases
Variables
variable deprecation
const deprecation: { disableWarnings: boolean; deprecationWarningMap: { [name: string]: string }; warn(deprecationName: string): void;};
variable version
const version: string;
Classes
class client
class client extends events.EventEmitter {}
constructor
constructor(ClientConfig?: IClientConfig);
method abort
abort: () => void;
Will cancel an in-progress connection request before either the
connect
event or theconnectFailed
event has been emitted. If theconnect
orconnectFailed
event has already been emitted, callingabort()
will do nothing.
method addListener
addListener: { (event: 'connect', cb: (connection: connection) => void): this; (event: 'connectFailed', cb: (err: Error) => void): this; ( event: 'httpResponse', cb: (response: http.IncomingMessage, client: client) => void ): this;};
method connect
connect: ( requestUrl: url.Url | string, requestedProtocols?: string | string[], origin?: string, headers?: http.OutgoingHttpHeaders, extraRequestOptions?: http.RequestOptions) => void;
Establish a connection. The remote server will select the best subprotocol that it supports and send that back when establishing the connection.
Parameter requestUrl
should be a standard websocket url
Parameter requestedProtocols
list of subprotocols supported by the client. The remote server will select the best subprotocol that it supports and send that back when establishing the connection.
Parameter origin
Used in user-agent scenarios to identify the page containing any scripting content that caused the connection to be requested.
Parameter headers
additional arbitrary HTTP request headers to send along with the request. This may be used to pass things like access tokens, etc. so that the server can verify authentication/authorization before deciding to accept and open the full WebSocket connection.
Parameter extraRequestOptions
additional configuration options to be passed to
http.request
orhttps.request
. This can be used to pass a customagent
to enableclient
usage from behind an HTTP or HTTPS proxy server using koichik/node-tunnel or similar.Example 1
client.connect('ws://www.mygreatapp.com:1234/websocketapp/')
method on
on: { (event: 'connect', cb: (connection: connection) => void): this; (event: 'connectFailed', cb: (err: Error) => void): this; ( event: 'httpResponse', cb: (response: http.IncomingMessage, client: client) => void ): this;};
class connection
class connection extends events.EventEmitter {}
constructor
constructor( socket: net.Socket, extensions: IExtension[], protocol: string, maskOutgoingPackets: boolean, config: IConfig);
property assembleFragments
assembleFragments: number;
property bufferList
bufferList: IBufferList;
property bytesWaitingToFlush
bytesWaitingToFlush: number;
property CLOSE_DESCRIPTIONS
static CLOSE_DESCRIPTIONS: { [code: number]: string };
property CLOSE_REASON_ABNORMAL
static CLOSE_REASON_ABNORMAL: number;
property CLOSE_REASON_EXTENSION_REQUIRED
static CLOSE_REASON_EXTENSION_REQUIRED: number;
property CLOSE_REASON_GOING_AWAY
static CLOSE_REASON_GOING_AWAY: number;
property CLOSE_REASON_INVALID_DATA
static CLOSE_REASON_INVALID_DATA: number;
property CLOSE_REASON_MESSAGE_TOO_BIG
static CLOSE_REASON_MESSAGE_TOO_BIG: number;
property CLOSE_REASON_NORMAL
static CLOSE_REASON_NORMAL: number;
property CLOSE_REASON_NOT_PROVIDED
static CLOSE_REASON_NOT_PROVIDED: number;
property CLOSE_REASON_POLICY_VIOLATION
static CLOSE_REASON_POLICY_VIOLATION: number;
property CLOSE_REASON_PROTOCOL_ERROR
static CLOSE_REASON_PROTOCOL_ERROR: number;
property CLOSE_REASON_RESERVED
static CLOSE_REASON_RESERVED: number;
property CLOSE_REASON_UNPROCESSABLE_INPUT
static CLOSE_REASON_UNPROCESSABLE_INPUT: number;
property closeDescription
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.
property closeReasonCode
closeReasonCode: number;
After the connection is closed, contains the numeric close reason status code, or
-1
if the connection is still open.
property closeTimeout
closeTimeout: number;
property config
config: IConfig;
property connected
connected: boolean;
Whether or not the connection is still connected. Read-only
property currentFrame
currentFrame: frame;
property extensions
extensions: IExtension[];
An array of extensions that were negotiated for this connection
property fragmentationSize
fragmentationSize: number;
property frameHeader
frameHeader: Buffer;
property frameQueue
frameQueue: frame[];
property inputPaused
inputPaused: boolean;
property maskBytes
maskBytes: Buffer;
property maskOutgoingPackets
maskOutgoingPackets: boolean;
property maxReceivedMessageSize
maxReceivedMessageSize: number;
property outputBufferFull
outputBufferFull: boolean;
property protocol
protocol: string;
The subprotocol that was chosen to be spoken on this connection. This field will have been converted to lower case.
property receivedEnd
receivedEnd: boolean;
property remoteAddress
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.
property socket
socket: net.Socket;
property socketHadError
socketHadError: boolean;
property state
state: string;
property waitingForCloseResponse
waitingForCloseResponse: boolean;
property webSocketVersion
webSocketVersion: number;
The version of the WebSocket protocol requested by the client
method addListener
addListener: { (event: 'message', cb: (data: Message) => void): this; (event: 'frame', cb: (frame: frame) => void): this; (event: 'close', cb: (code: number, desc: string) => void): this; (event: 'error', cb: (err: Error) => void): this; (event: 'drain' | 'pause' | 'resume', cb: () => void): this; ( event: 'ping', cb: (cancel: () => void, binaryPayload: Buffer) => void ): this; (event: 'pong', cb: (binaryPayload: Buffer) => void): this;};
method clearCloseTimer
clearCloseTimer: () => void;
method clearGracePeriodTimer
clearGracePeriodTimer: () => void;
method clearKeepaliveTimer
clearKeepaliveTimer: () => void;
method close
close: (reasonCode?: number, description?: string) => void;
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.
method drop
drop: ( reasonCode?: number, description?: string, skipCloseFrame?: boolean) => void;
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.
method fragmentAndSend
fragmentAndSend: (frame: frame, cb?: (err: Error) => void) => void;
method handleCloseTimer
handleCloseTimer: () => void;
method handleGracePeriodTimer
handleGracePeriodTimer: () => void;
method handleKeepaliveTimer
handleKeepaliveTimer: () => void;
method handleSocketClose
handleSocketClose: (hadError: boolean) => void;
method handleSocketData
handleSocketData: (data: Buffer) => void;
method handleSocketDrain
handleSocketDrain: () => void;
method handleSocketEnd
handleSocketEnd: () => void;
method handleSocketError
handleSocketError: (error: Error) => void;
method handleSocketPause
handleSocketPause: () => void;
method handleSocketResume
handleSocketResume: () => void;
method on
on: { (event: 'message', cb: (data: Message) => void): this; (event: 'frame', cb: (frame: frame) => void): this; (event: 'close', cb: (code: number, desc: string) => void): this; (event: 'error', cb: (err: Error) => void): this; (event: 'drain' | 'pause' | 'resume', cb: () => void): this; ( event: 'ping', cb: (cancel: () => void, binaryPayload: Buffer) => void ): this; (event: 'pong', cb: (binaryPayload: Buffer) => void): this;};
method pause
pause: () => void;
method ping
ping: (data: Buffer | IStringified) => void;
Sends a ping frame. Ping frames must not exceed 125 bytes in length.
method pong
pong: (buffer: Buffer) => void;
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.
method processFrame
processFrame: (frame: frame) => void;
method processReceivedData
processReceivedData: () => void;
method resume
resume: () => void;
method send
send: (data: Buffer | IStringified, cb?: (err?: Error) => void) => void;
Auto-detect the data type and send UTF-8 or Binary message
method sendBytes
sendBytes: (buffer: Buffer, cb?: (err?: Error) => void) => void;
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.
method sendCloseFrame
sendCloseFrame: ( reasonCode?: number, reasonText?: string, cb?: (err?: Error) => void) => void;
method sendFrame
sendFrame: (frame: frame, cb?: (err?: Error) => void) => void;
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 ownframe
. You should probably use sendUTF or sendBytes instead.
method sendUTF
sendUTF: (data: IStringified, cb?: (err?: Error) => void) => void;
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 exceedsconfig.fragmentationThreshold
bytes.
method setCloseTimer
setCloseTimer: () => void;
method setGracePeriodTimer
setGracePeriodTimer: () => void;
method setKeepaliveTimer
setKeepaliveTimer: () => void;
Set or reset the
keepalive
timer when data is received
class frame
class frame {}
property binaryPayload
binaryPayload: Buffer;
The binary payload data. Even text frames are sent with a Buffer providing the binary payload data.
property closeStatus
closeStatus: number;
property config
config: IConfig;
property dropReason
dropReason: string;
property fin
fin: boolean;
Whether or not this is last frame in a fragmentation sequence
property frameHeader
frameHeader: Buffer;
property frameTooLarge
frameTooLarge: boolean;
property invalidCloseFrameLength
invalidCloseFrameLength: boolean;
property length
length: number;
Identifies the length of the payload data on a received frame. When sending a frame, will be automatically calculated from
binaryPayload
object.
property mask
mask: number;
Whether or not this frame is (or should be) masked. For outgoing frames, when connected as a client, this flag is automatically forced to true by
connection
. Outgoing frames sent from the server-side of a connection are not masked.
property maskBytes
maskBytes: Buffer;
property maxReceivedFrameSize
maxReceivedFrameSize: number;
property opcode
opcode: number;
Identifies which kind of frame this is.
Hex - Dec - Description 0x00 - 0 - Continuation 0x01 - 1 - Text Frame 0x02 - 2 - Binary Frame 0x08 - 8 - Close Frame 0x09 - 9 - Ping Frame 0x0A - 10 - Pong Frame
property parseState
parseState: number;
property protocolError
protocolError: boolean;
property rsv1
rsv1: boolean;
Represents the RSV1 field in the framing. Setting this to true will result in a Protocol Error on the receiving peer.
property rsv2
rsv2: boolean;
Represents the RSV1 field in the framing. Setting this to true will result in a Protocol Error on the receiving peer.
property rsv3
rsv3: boolean;
Represents the RSV1 field in the framing. Setting this to true will result in a Protocol Error on the receiving peer.
method addData
addData: (bufferList: IBufferList) => boolean;
method throwAwayPayload
throwAwayPayload: (bufferList: IBufferList) => boolean;
method toBuffer
toBuffer: (nullMask: boolean) => Buffer;
method toString
toString: () => string;
class request
class request extends events.EventEmitter {}
constructor
constructor( socket: net.Socket, httpRequest: http.IncomingMessage, config: IServerConfig);
property cookies
cookies: ICookie[];
property host
host: string;
This will include the port number if a non-standard port is used
property httpRequest
httpRequest: http.IncomingMessage;
A reference to the original Node HTTP request object
property key
key: string;
Sec-WebSocket-Key
property origin
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 "*".
property protocolFullCaseMap
protocolFullCaseMap: { [key: string]: string };
property remoteAddress
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
property remoteAddresses
remoteAddresses: string[];
property requestedExtensions
requestedExtensions: any[];
An array containing a list of extensions requested by the client
property requestedProtocols
requestedProtocols: 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 therequestedProtocols
array will have been converted to lower case.
property resource
resource: string;
A string containing the path that was requested by the client
property resourceURL
resourceURL: url.UrlWithParsedQuery;
Parsed resource, including the query string parameters
property serverConfig
serverConfig: IServerConfig;
property socket
socket: net.Socket;
property webSocketVersion
webSocketVersion: number;
The version of the WebSocket protocol requested by the client
method accept
accept: ( acceptedProtocol?: string | null, 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 passnull
for theacceptedProtocol
parameter.Parameter acceptedProtocol
case-insensitive value that was requested by the client
method addListener
addListener: { ( event: 'requestResolved' | 'requestRejected', cb: (request: this) => void ): this; (event: 'requestAccepted', cb: (connection: connection) => void): this;};
method on
on: { ( event: 'requestResolved' | 'requestRejected', cb: (request: this) => void ): this; (event: 'requestAccepted', cb: (connection: connection) => void): this;};
method parseCookies
parseCookies: (str: string) => ICookie[] | void;
method parseExtensions
parseExtensions: (extensionString: string) => string[];
method readHandshake
readHandshake: () => void;
method reject
reject: (httpStatus?: number, reason?: string, extraHeaders?: object) => void;
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. Optional extra http headers can be added via Object key/values on extraHeaders.
class router
class router extends events.EventEmitter {}
constructor
constructor(config?: IRouterConfig);
property handlers
handlers: IRouterHandler[];
method attachServer
attachServer: (server: server) => void;
Attach to WebSocket server
method detachServer
detachServer: () => void;
Detach from WebSocket server
method findHandlerIndex
findHandlerIndex: (pathString: string, protocol: string) => number;
method handleRequest
handleRequest: (request: request) => void;
method mount
mount: ( path: string | RegExp, protocol: string | null, callback: (request: IRouterRequest) => void) => void;
method pathToRegEx
pathToRegEx: (path: RegExp) => RegExp;
method pathToRegExp
pathToRegExp: (path: string) => RegExp;
method unmount
unmount: (path: string | RegExp, protocol?: string) => void;
class server
class server extends events.EventEmitter {}
constructor
constructor(serverConfig?: IServerConfig);
property config
config?: IServerConfig;
property connections
connections: connection[];
property pendingRequests
pendingRequests: request[];
method addListener
addListener: { (event: 'request', cb: (request: request) => void): this; (event: 'connect', cb: (connection: connection) => void): this; ( event: 'close', cb: (connection: connection, reason: number, desc: string) => void ): this;};
method broadcast
broadcast: (data: Buffer | IStringified) => void;
Send binary or UTF-8 message for each connection
method broadcastBytes
broadcastBytes: (data: Buffer) => void;
Send binary message for each connection
method broadcastUTF
broadcastUTF: (data: IStringified) => void;
Send UTF-8 message for each connection
method closeAllConnections
closeAllConnections: () => void;
Close all open WebSocket connections
method handleConnectionClose
handleConnectionClose: ( connection: connection, closeReason: number, description: string) => void;
method handleRequestAccepted
handleRequestAccepted: (connection: connection) => void;
method handleRequestResolved
handleRequestResolved: (request: request) => void;
method handleUpgrade
handleUpgrade: (request: http.IncomingMessage, socket: net.Socket) => void;
method mount
mount: (serverConfig: IServerConfig) => void;
Attach the
server
instance to a Node http.Server instance
method on
on: { (event: 'request', cb: (request: request) => void): this; (event: 'connect', cb: (connection: connection) => void): this; ( event: 'close', cb: (connection: connection, reason: number, desc: string) => void ): this;};
method shutDown
shutDown: () => void;
Close all open WebSocket connections and unmount the server
method unmount
unmount: () => void;
Detach the
server
instance from the Node http.Server instance. All existing connections are left alone and will not be affected, but no new WebSocket connections will be accepted.
class w3cwebsocket
class w3cwebsocket {}
constructor
constructor( url: string, protocols?: string | string[], origin?: string, headers?: http.OutgoingHttpHeaders, requestOptions?: {}, IClientConfig?: IClientConfig);
property binaryType
binaryType: string;
property bufferedAmount
bufferedAmount: number;
property CLOSED
static CLOSED: number;
property CLOSED
CLOSED: number;
property CLOSING
static CLOSING: number;
property CLOSING
CLOSING: number;
property CONNECTING
static CONNECTING: number;
property CONNECTING
CONNECTING: number;
property extensions
extensions: IExtension[];
property onclose
onclose: (event: ICloseEvent) => void;
property onerror
onerror: (error: Error) => void;
property onmessage
onmessage: (message: IMessageEvent) => void;
property onopen
onopen: () => void;
property OPEN
static OPEN: number;
property OPEN
OPEN: number;
property protocol
protocol?: string;
property readyState
readyState: number;
property url
url: string;
method close
close: (code?: number, reason?: string) => void;
method send
send: (data: ArrayBufferView | ArrayBuffer | Buffer | IStringified) => void;
Interfaces
interface IBinaryMessage
interface IBinaryMessage {}
property binaryData
binaryData: Buffer;
property type
type: 'binary';
interface IBufferList
interface IBufferList extends events.EventEmitter {}
property encoding
encoding: string;
property length
length: number;
method addListener
addListener: { (event: 'advance', cb: (n: number) => void): this; (event: 'write', cb: (buf: Buffer) => void): this;};
method advance
advance: (n: number) => IBufferList;
Advance the buffer stream by
n
bytes. Ifn
the aggregate advance offset passes the end of the buffer list, operations such astake
will return empty strings until enough data is pushed.
method end
end: (buf: Buffer) => void;
method forEach
forEach: (fn: (buf: Buffer) => boolean) => void;
For each buffer, perform some action. If fn's result is a true value, cut out early.
method join
join: (start: number, end: number) => Buffer;
Create a single buffer out of all the chunks
method joinInto
joinInto: (buf: Buffer, offset: number, start: number, end: number) => Buffer;
Join all the chunks to existing buffer
method on
on: { (event: 'advance', cb: (n: number) => void): this; (event: 'write', cb: (buf: Buffer) => void): this;};
method push
push: () => void;
method take
take: { (n: number, encoding?: string): any; (encoding?: string): any };
Take
n
bytes from the start of the buffers. If there are less thann
bytes in all the buffers orn
is undefined, returns the entire concatenated buffer string.
method toString
toString: () => string;
method write
write: (buf: Buffer) => boolean;
interface IClientConfig
interface IClientConfig extends IConfig {}
property tlsOptions
tlsOptions?: https.RequestOptions | undefined;
Options to pass to
https.request
if connecting via TLS.See Also
https://nodejs.org/api/https.html#https_https_request_options_callback
property webSocketVersion
webSocketVersion?: number | undefined;
Which version of the WebSocket protocol to use when making the connection. Currently supported values are 8 and 13. This option will be removed once the protocol is finalized by the IETF It is only available to ease the transition through the intermediate draft protocol versions. The only thing this affects the name of the Origin header. 13
interface ICloseEvent
interface ICloseEvent {}
interface IConfig
interface IConfig {}
property assembleFragments
assembleFragments?: boolean | undefined;
If true, fragmented messages will be automatically assembled and the full message will be emitted via a
message
event. If false, each frame will be emitted on theconnection
object via aframe
event and the application will be responsible for aggregating multiple fragmented frames. Single-frame messages will emit amessage
event in addition to theframe
event. true
property closeTimeout
closeTimeout?: number | undefined;
The number of milliseconds to wait after sending a close frame for an
acknowledgement
to come back before giving up and just closing the socket. 5000
property disableNagleAlgorithm
disableNagleAlgorithm?: boolean | undefined;
The Nagle Algorithm makes more efficient use of network resources by introducing a small delay before sending small packets so that multiple messages can be batched together before going onto the wire. This however comes at the cost of latency. true
property fragmentationThreshold
fragmentationThreshold?: number | undefined;
The maximum size of a frame in bytes before it is automatically fragmented. 16KiB
property fragmentOutgoingMessages
fragmentOutgoingMessages?: boolean | undefined;
Whether or not to fragment outgoing messages. If true, messages will be automatically fragmented into chunks of up to
fragmentationThreshold
bytes. true
property maxReceivedFrameSize
maxReceivedFrameSize?: number | undefined;
The maximum allowed received frame size in bytes. Single frame messages will also be limited to this maximum. 1MiB
property maxReceivedMessageSize
maxReceivedMessageSize?: number | undefined;
The maximum allowed aggregate message size (for fragmented messages) in bytes 8MiB
interface ICookie
interface ICookie {}
property domain
domain?: string | undefined;
property expires
expires?: Date | undefined;
property httponly
httponly?: boolean | undefined;
property maxage
maxage?: number | undefined;
property name
name: string;
property path
path?: string | undefined;
property secure
secure?: boolean | undefined;
property value
value: string;
interface IExtension
interface IExtension {}
interface IMessageEvent
interface IMessageEvent {}
property data
data: string | Buffer | ArrayBuffer;
interface IRouterConfig
interface IRouterConfig {}
property server
server: server;
interface IRouterHandler
interface IRouterHandler {}
property callback
callback: (request: IRouterRequest) => void;
property path
path: string;
property pathString
pathString: string;
property protocol
protocol: string;
interface IRouterRequest
interface IRouterRequest extends events.EventEmitter {}
property cookies
cookies: ICookie[];
property httpRequest
httpRequest: http.IncomingMessage;
A reference to the original Node HTTP request object
property origin
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 "*".
property protocol
protocol: string | null;
property remoteAddress
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
property requestedExtensions
requestedExtensions: any[];
An array containing a list of extensions requested by the client
property resource
resource: string;
A string containing the path that was requested by the client
property resourceURL
resourceURL: url.UrlWithParsedQuery;
Parsed resource, including the query string parameters
property webSocketRequest
webSocketRequest: request;
property webSocketVersion
webSocketVersion: number;
The version of the WebSocket protocol requested by the client
method accept
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 passnull
for theacceptedProtocol
parameter.Parameter acceptedProtocol
case-insensitive value that was requested by the client
method addListener
addListener: { (event: 'requestAccepted', cb: (connection: connection) => void): this; (event: 'requestRejected', cb: (request: this) => void): this;};
method on
on: { (event: 'requestAccepted', cb: (connection: connection) => void): this; (event: 'requestRejected', cb: (request: this) => void): this;};
method reject
reject: (httpStatus?: number, reason?: string) => void;
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.
interface IServerConfig
interface IServerConfig extends IConfig {}
property autoAcceptConnections
autoAcceptConnections?: boolean | undefined;
If this is true, websocket connections will be accepted regardless of the path and protocol specified by the client. The protocol accepted will be the first that was requested by the client. false
property dropConnectionOnKeepaliveTimeout
dropConnectionOnKeepaliveTimeout?: boolean | undefined;
If true, the server will consider any connection that has not received any data within the amount of time specified by
keepaliveGracePeriod
after akeepalive
ping has been sent. Ignored ifkeepalive
is false. true
property httpServer
httpServer: http.Server | https.Server | Array<http.Server | https.Server>;
The http or https server instance(s) to attach to
property ignoreXForwardedFor
ignoreXForwardedFor?: boolean | undefined;
Whether or not the X-Forwarded-For header should be respected. It's important to set this to 'true' when accepting connections from untrusted clients, as a malicious client could spoof its IP address by simply setting this header. It's meant to be added by a trusted proxy or other intermediary within your own infrastructure. See: http://en.wikipedia.org/wiki/X-Forwarded-For false
property keepalive
keepalive?: boolean | undefined;
If true, the server will automatically send a ping to all clients every
keepaliveInterval
milliseconds. Each client has an independentkeepalive
timer, which is reset when any data is received from that client. true
property keepaliveGracePeriod
keepaliveGracePeriod?: number | undefined;
The amount of time to wait after sending a
keepalive
ping before closing the connection if the connected peer does not respond. Ignored ifkeepalive
ordropConnectionOnKeepaliveTimeout
are false. The grace period timer is reset when any data is received from the client. 10000
property keepaliveInterval
keepaliveInterval?: number | undefined;
The interval in milliseconds to send
keepalive
pings to connected clients. 20000
property maxReceivedFrameSize
maxReceivedFrameSize?: number | undefined;
The maximum allowed received frame size in bytes. Single frame messages will also be limited to this maximum. 64KiB
property maxReceivedMessageSize
maxReceivedMessageSize?: number | undefined;
The maximum allowed aggregate message size (for fragmented messages) in bytes. 1MiB
property useNativeKeepalive
useNativeKeepalive?: boolean | undefined;
Whether to use native TCP keep-alive instead of WebSockets ping and pong packets. Native TCP keep-alive sends smaller packets on the wire and so uses bandwidth more efficiently. This may be more important when talking to mobile devices. If this value is set to true, then these values will be ignored: keepaliveGracePeriod dropConnectionOnKeepaliveTimeout false
interface IStringified
interface IStringified {}
property toString
toString: (...args: any[]) => string;
interface IUtf8Message
interface IUtf8Message {}
Type Aliases
type Message
type Message = IUtf8Message | IBinaryMessage;
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/websocket
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/websocket)
- HTML<a href="https://www.jsdocs.io/package/@types/websocket"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 6426 ms. - Missing or incorrect documentation? Open an issue for this package.