@types/ws
- Version 8.5.13
- Published
- 21.6 kB
- 1 dependency
- MIT license
Install
npm i @types/ws
yarn add @types/ws
pnpm add @types/ws
Overview
TypeScript definitions for ws
Index
Variables
Functions
Classes
Interfaces
Type Aliases
Variables
variable WebSocket
const WebSocket: typeof WebSocket;
variable WebSocketAlias
const WebSocketAlias: typeof WebSocket;
variable WebSocketServer
const WebSocketServer: typeof Server;
Functions
function createWebSocketStream
createWebSocketStream: (websocket: WebSocket, options?: DuplexOptions) => Duplex;
Classes
class Server
class Server< T extends typeof WebSocket.WebSocket = typeof WebSocket.WebSocket, U extends typeof IncomingMessage = typeof IncomingMessage> extends EventEmitter {}
constructor
constructor(options?: ServerOptions<T, U>, callback?: () => void);
property clients
clients: Set<InstanceType<T>>;
property options
options: ServerOptions<T, U>;
property path
path: string;
method addListener
addListener: { ( event: 'connection', cb: (client: InstanceType<T>, request: InstanceType<U>) => void ): this; (event: 'error', cb: (err: Error) => void): this; ( event: 'headers', cb: (headers: string[], request: InstanceType<U>) => void ): this; (event: 'close' | 'listening', cb: () => void): this; (event: string | symbol, listener: (...args: any[]) => void): this;};
method address
address: () => AddressInfo | string | null;
method close
close: (cb?: (err?: Error) => void) => void;
method handleUpgrade
handleUpgrade: ( request: InstanceType<U>, socket: Duplex, upgradeHead: Buffer, callback: (client: InstanceType<T>, request: InstanceType<U>) => void) => void;
method off
off: { ( event: 'connection', cb: ( this: Server<T, any>, socket: InstanceType<T>, request: InstanceType<U> ) => void ): this; (event: 'error', cb: (this: Server<T, any>, error: Error) => void): this; ( event: 'headers', cb: ( this: Server<T, any>, headers: string[], request: InstanceType<U> ) => void ): this; (event: 'close' | 'listening', cb: (this: Server<T, any>) => void): this; ( event: string | symbol, listener: (this: Server<T, any>, ...args: any[]) => void ): this;};
method on
on: { ( event: 'connection', cb: ( this: Server<T, any>, socket: InstanceType<T>, request: InstanceType<U> ) => void ): this; (event: 'error', cb: (this: Server<T, any>, error: Error) => void): this; ( event: 'headers', cb: ( this: Server<T, any>, headers: string[], request: InstanceType<U> ) => void ): this; (event: 'close' | 'listening', cb: (this: Server<T, any>) => void): this; ( event: string | symbol, listener: (this: Server<T, any>, ...args: any[]) => void ): this;};
method once
once: { ( event: 'connection', cb: ( this: Server<T, any>, socket: InstanceType<T>, request: InstanceType<U> ) => void ): this; (event: 'error', cb: (this: Server<T, any>, error: Error) => void): this; ( event: 'headers', cb: ( this: Server<T, any>, headers: string[], request: InstanceType<U> ) => void ): this; (event: 'close' | 'listening', cb: (this: Server<T, any>) => void): this; ( event: string | symbol, listener: (this: Server<T, any>, ...args: any[]) => void ): this;};
method removeListener
removeListener: { ( event: 'connection', cb: (client: InstanceType<T>, request: InstanceType<U>) => void ): this; (event: 'error', cb: (err: Error) => void): this; ( event: 'headers', cb: (headers: string[], request: InstanceType<U>) => void ): this; (event: 'close' | 'listening', cb: () => void): this; (event: string | symbol, listener: (...args: any[]) => void): this;};
method shouldHandle
shouldHandle: (request: InstanceType<U>) => boolean | Promise<boolean>;
class WebSocket
class WebSocket extends EventEmitter {}
constructor
constructor(address: null);
constructor
constructor(address: any, options?: any);
constructor
constructor(address: any, protocols?: string | string[], options?: any);
property binaryType
binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments';
property bufferedAmount
readonly bufferedAmount: number;
property CLOSED
static readonly CLOSED: number;
The connection is closed.
property CLOSED
readonly CLOSED: number;
The connection is closed.
property CLOSING
static readonly CLOSING: number;
The connection is in the process of closing.
property CLOSING
readonly CLOSING: number;
The connection is in the process of closing.
property CONNECTING
static readonly CONNECTING: number;
The connection is not yet open.
property CONNECTING
readonly CONNECTING: number;
The connection is not yet open.
property extensions
readonly extensions: string;
property isPaused
readonly isPaused: boolean;
Indicates whether the websocket is paused
property onclose
onclose: (event: WebSocket.CloseEvent) => void;
property onerror
onerror: (event: WebSocket.ErrorEvent) => void;
property onmessage
onmessage: (event: WebSocket.MessageEvent) => void;
property onopen
onopen: (event: WebSocket.Event) => void;
property OPEN
static readonly OPEN: number;
The connection is open and ready to communicate.
property OPEN
readonly OPEN: number;
The connection is open and ready to communicate.
property protocol
readonly protocol: string;
property readyState
readonly readyState: 0 | 1 | 2 | 3;
The current state of the connection
property url
readonly url: string;
method addEventListener
addEventListener: <K extends keyof WebSocket.WebSocketEventMap>( type: K, listener: (event: WebSocket.WebSocketEventMap[K]) => void, options?: WebSocket.EventListenerOptions) => void;
method addListener
addListener: { (event: 'close', listener: (code: number, reason: Buffer) => void): this; (event: 'error', listener: (err: Error) => void): this; (event: 'upgrade', listener: (request: IncomingMessage) => void): this; (event: 'message', listener: (data: any, isBinary: boolean) => void): this; (event: 'open', listener: () => void): this; (event: 'ping' | 'pong', listener: (data: Buffer) => void): this; ( event: 'unexpected-response', listener: (request: ClientRequest, response: IncomingMessage) => void ): this; (event: string | symbol, listener: (...args: any[]) => void): this;};
method close
close: (code?: number, data?: string | Buffer) => void;
method off
off: { ( event: 'close', listener: (this: WebSocket, code: number, reason: Buffer) => void ): this; (event: 'error', listener: (this: WebSocket, err: Error) => void): this; ( event: 'upgrade', listener: (this: WebSocket, request: IncomingMessage) => void ): this; ( event: 'message', listener: (this: WebSocket, data: any, isBinary: boolean) => void ): this; (event: 'open', listener: (this: WebSocket) => void): this; ( event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void ): this; ( event: 'unexpected-response', listener: ( this: WebSocket, request: ClientRequest, response: IncomingMessage ) => void ): this; ( event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void ): this;};
method on
on: { ( event: 'close', listener: (this: WebSocket, code: number, reason: Buffer) => void ): this; (event: 'error', listener: (this: WebSocket, err: Error) => void): this; ( event: 'upgrade', listener: (this: WebSocket, request: IncomingMessage) => void ): this; ( event: 'message', listener: (this: WebSocket, data: any, isBinary: boolean) => void ): this; (event: 'open', listener: (this: WebSocket) => void): this; ( event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void ): this; ( event: 'unexpected-response', listener: ( this: WebSocket, request: ClientRequest, response: IncomingMessage ) => void ): this; ( event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void ): this;};
method once
once: { ( event: 'close', listener: (this: WebSocket, code: number, reason: Buffer) => void ): this; (event: 'error', listener: (this: WebSocket, err: Error) => void): this; ( event: 'upgrade', listener: (this: WebSocket, request: IncomingMessage) => void ): this; ( event: 'message', listener: (this: WebSocket, data: any, isBinary: boolean) => void ): this; (event: 'open', listener: (this: WebSocket) => void): this; ( event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void ): this; ( event: 'unexpected-response', listener: ( this: WebSocket, request: ClientRequest, response: IncomingMessage ) => void ): this; ( event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void ): this;};
method pause
pause: () => void;
Pause the websocket causing it to stop emitting events. Some events can still be emitted after this is called, until all buffered data is consumed. This method is a noop if the ready state is
CONNECTING
orCLOSED
.
method ping
ping: (data?: any, mask?: boolean, cb?: (err: Error) => void) => void;
method pong
pong: (data?: any, mask?: boolean, cb?: (err: Error) => void) => void;
method removeEventListener
removeEventListener: <K extends keyof WebSocket.WebSocketEventMap>( type: K, listener: (event: WebSocket.WebSocketEventMap[K]) => void) => void;
method removeListener
removeListener: { (event: 'close', listener: (code: number, reason: Buffer) => void): this; (event: 'error', listener: (err: Error) => void): this; (event: 'upgrade', listener: (request: IncomingMessage) => void): this; (event: 'message', listener: (data: any, isBinary: boolean) => void): this; (event: 'open', listener: () => void): this; (event: 'ping' | 'pong', listener: (data: Buffer) => void): this; ( event: 'unexpected-response', listener: (request: ClientRequest, response: IncomingMessage) => void ): this; (event: string | symbol, listener: (...args: any[]) => void): this;};
method resume
resume: () => void;
Make a paused socket resume emitting events. This method is a noop if the ready state is
CONNECTING
orCLOSED
.
method send
send: { (data: BufferLike, cb?: (err?: Error) => void): void; ( data: any, options: { mask?: boolean; binary?: boolean; compress?: boolean; fin?: boolean; }, cb?: (err?: Error) => void ): void;};
method terminate
terminate: () => void;
Interfaces
interface AddressInfo
interface AddressInfo {}
interface ClientOptions
interface ClientOptions extends SecureContextOptions {}
property agent
agent?: Agent | undefined;
property family
family?: number | undefined;
property finishRequest
finishRequest?: FinishRequestCallback | undefined;
property followRedirects
followRedirects?: boolean | undefined;
property handshakeTimeout
handshakeTimeout?: number | undefined;
property headers
headers?: { [key: string]: string } | undefined;
property host
host?: string | undefined;
property localAddress
localAddress?: string | undefined;
property maxPayload
maxPayload?: number | undefined;
property maxRedirects
maxRedirects?: number | undefined;
property origin
origin?: string | undefined;
property perMessageDeflate
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
property protocol
protocol?: string | undefined;
property protocolVersion
protocolVersion?: number | undefined;
property rejectUnauthorized
rejectUnauthorized?: boolean | undefined;
property skipUTF8Validation
skipUTF8Validation?: boolean | undefined;
method checkServerIdentity
checkServerIdentity: (servername: string, cert: CertMeta) => boolean;
method generateMask
generateMask: (mask: Buffer) => void;
interface CloseEvent
interface CloseEvent {}
interface ErrorEvent
interface ErrorEvent {}
interface EventListenerOptions
interface EventListenerOptions {}
property once
once?: boolean | undefined;
interface MessageEvent
interface MessageEvent {}
interface PerMessageDeflateOptions
interface PerMessageDeflateOptions {}
property clientMaxWindowBits
clientMaxWindowBits?: number | undefined;
property clientNoContextTakeover
clientNoContextTakeover?: boolean | undefined;
property concurrencyLimit
concurrencyLimit?: number | undefined;
property serverMaxWindowBits
serverMaxWindowBits?: number | undefined;
property serverNoContextTakeover
serverNoContextTakeover?: boolean | undefined;
property threshold
threshold?: number | undefined;
property zlibDeflateOptions
zlibDeflateOptions?: | { flush?: number | undefined; finishFlush?: number | undefined; chunkSize?: number | undefined; windowBits?: number | undefined; level?: number | undefined; memLevel?: number | undefined; strategy?: number | undefined; dictionary?: Buffer | Buffer[] | DataView | undefined; info?: boolean | undefined; } | undefined;
property zlibInflateOptions
zlibInflateOptions?: ZlibOptions | undefined;
interface ServerOptions
interface ServerOptions< U extends typeof WebSocket.WebSocket = typeof WebSocket.WebSocket, V extends typeof IncomingMessage = typeof IncomingMessage> {}
property backlog
backlog?: number | undefined;
property clientTracking
clientTracking?: boolean | undefined;
property handleProtocols
handleProtocols?: ( protocols: Set<string>, request: InstanceType<V>) => string | false;
property host
host?: string | undefined;
property maxPayload
maxPayload?: number | undefined;
property noServer
noServer?: boolean | undefined;
property path
path?: string | undefined;
property perMessageDeflate
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
property port
port?: number | undefined;
property server
server?: HTTPServer<V> | HTTPSServer<V> | undefined;
property skipUTF8Validation
skipUTF8Validation?: boolean | undefined;
property verifyClient
verifyClient?: | VerifyClientCallbackAsync<InstanceType<V>> | VerifyClientCallbackSync<InstanceType<V>> | undefined;
property WebSocket
WebSocket?: U | undefined;
interface WebSocket
interface WebSocket extends WebSocketAlias {}
interface WebSocketEventMap
interface WebSocketEventMap {}
interface WebSocketServer
interface WebSocketServer extends Server {}
Type Aliases
type CertMeta
type CertMeta = string | string[] | Buffer | Buffer[];
CertMeta represents the accepted types for certificate & key data.
type Data
type Data = string | Buffer | ArrayBuffer | Buffer[];
Data represents the message payload received over the WebSocket.
type FinishRequestCallback
type FinishRequestCallback = ( request: IncomingMessage, websocket: WebSocket) => void;
FinishRequestCallback is a callback for last minute customization of the headers. If finishRequest is set, then it has the responsibility to call request.end() once it is done setting request headers.
type RawData
type RawData = Buffer | ArrayBuffer | Buffer[];
Data represents the raw message payload received over the WebSocket.
type VerifyClientCallbackAsync
type VerifyClientCallbackAsync<Request extends IncomingMessage = IncomingMessage> = ( info: { origin: string; secure: boolean; req: Request }, callback: ( res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders ) => void) => void;
VerifyClientCallbackAsync is an asynchronous callback used to inspect the incoming message. The return value (boolean) of the function determines whether or not to accept the handshake.
type VerifyClientCallbackSync
type VerifyClientCallbackSync<Request extends IncomingMessage = IncomingMessage> = (info: { origin: string; secure: boolean; req: Request }) => boolean;
VerifyClientCallbackSync is a synchronous callback used to inspect the incoming message. The return value (boolean) of the function determines whether or not to accept the handshake.
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/ws
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/ws)
- HTML<a href="https://www.jsdocs.io/package/@types/ws"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5831 ms. - Missing or incorrect documentation? Open an issue for this package.