Socket
Socket
Sign inDemoInstall

@types/ws

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/ws - npm Package Compare versions

Comparing version 7.4.4 to 7.4.5

273

ws/index.d.ts

@@ -14,28 +14,35 @@ // Type definitions for ws 7.4

import * as events from 'events';
import * as http from 'http';
import * as https from 'https';
import * as net from 'net';
import * as url from 'url';
import * as zlib from 'zlib';
import * as stream from 'stream';
import { SecureContextOptions } from 'tls';
import { EventEmitter } from "events";
import {
Agent,
ClientRequest,
ClientRequestArgs,
IncomingMessage,
OutgoingHttpHeaders,
Server as HTTPServer,
} from "http";
import { Server as HTTPSServer } from "https";
import { Socket } from "net";
import { Duplex, DuplexOptions } from "stream";
import { SecureContextOptions } from "tls";
import { URL } from "url";
import { ZlibOptions } from "zlib";
// WebSocket socket.
declare class WebSocket extends events.EventEmitter {
declare class WebSocket extends EventEmitter {
/** The connection is not yet open. */
static CONNECTING: 0;
static readonly CONNECTING: 0;
/** The connection is open and ready to communicate. */
static OPEN: 1;
static readonly OPEN: 1;
/** The connection is in the process of closing. */
static CLOSING: 2;
static readonly CLOSING: 2;
/** The connection is closed. */
static CLOSED: 3;
static readonly CLOSED: 3;
binaryType: string;
bufferedAmount: number;
extensions: string;
protocol: string;
binaryType: "nodebuffer" | "arraybuffer" | "fragments";
readonly bufferedAmount: number;
readonly extensions: string;
readonly protocol: string;
/** The current state of the connection */
readyState:
readonly readyState:
| typeof WebSocket.CONNECTING

@@ -45,12 +52,12 @@ | typeof WebSocket.OPEN

| typeof WebSocket.CLOSED;
url: string;
readonly url: string;
/** The connection is not yet open. */
CONNECTING: 0;
readonly CONNECTING: 0;
/** The connection is open and ready to communicate. */
OPEN: 1;
readonly OPEN: 1;
/** The connection is in the process of closing. */
CLOSING: 2;
readonly CLOSING: 2;
/** The connection is closed. */
CLOSED: 3;
readonly CLOSED: 3;

@@ -62,4 +69,8 @@ onopen: (event: WebSocket.OpenEvent) => void;

constructor(address: string | url.URL, options?: WebSocket.ClientOptions | http.ClientRequestArgs);
constructor(address: string | url.URL, protocols?: string | string[], options?: WebSocket.ClientOptions | http.ClientRequestArgs);
constructor(address: string | URL, options?: WebSocket.ClientOptions | ClientRequestArgs);
constructor(
address: string | URL,
protocols?: string | string[],
options?: WebSocket.ClientOptions | ClientRequestArgs,
);

@@ -70,77 +81,103 @@ close(code?: number, data?: string): void;

send(data: any, cb?: (err?: Error) => void): void;
send(data: any, options: { mask?: boolean; binary?: boolean; compress?: boolean; fin?: boolean }, cb?: (err?: Error) => void): void;
send(
data: any,
options: { mask?: boolean; binary?: boolean; compress?: boolean; fin?: boolean },
cb?: (err?: Error) => void,
): void;
terminate(): void;
// HTML5 WebSocket events
addEventListener(method: 'message', cb: (event: {
data: any;
type: string;
target: WebSocket
}) => void, options?: WebSocket.EventListenerOptions): void;
addEventListener(method: 'close', cb: (event: {
wasClean: boolean; code: number;
reason: string; target: WebSocket
}) => void, options?: WebSocket.EventListenerOptions): void;
addEventListener(method: 'error', cb: (event: {
error: any,
message: any,
type: string,
target: WebSocket
}) => void, options?: WebSocket.EventListenerOptions): void;
addEventListener(method: 'open', cb: (event: { target: WebSocket }) => void, options?: WebSocket.EventListenerOptions): void;
addEventListener(
method: "message",
cb: (event: { data: any; type: string; target: WebSocket }) => void,
options?: WebSocket.EventListenerOptions,
): void;
addEventListener(
method: "close",
cb: (event: { wasClean: boolean; code: number; reason: string; target: WebSocket }) => void,
options?: WebSocket.EventListenerOptions,
): void;
addEventListener(
method: "error",
cb: (event: { error: any; message: any; type: string; target: WebSocket }) => void,
options?: WebSocket.EventListenerOptions,
): void;
addEventListener(
method: "open",
cb: (event: { target: WebSocket }) => void,
options?: WebSocket.EventListenerOptions,
): void;
addEventListener(method: string, listener: () => void, options?: WebSocket.EventListenerOptions): void;
removeEventListener(method: 'message', cb?: (event: { data: any; type: string; target: WebSocket }) => void): void;
removeEventListener(method: 'close', cb?: (event: {
wasClean: boolean; code: number;
reason: string; target: WebSocket
}) => void): void;
removeEventListener(method: 'error', cb?: (event: {error: any, message: any, type: string, target: WebSocket }) => void): void;
removeEventListener(method: 'open', cb?: (event: { target: WebSocket }) => void): void;
removeEventListener(method: "message", cb?: (event: { data: any; type: string; target: WebSocket }) => void): void;
removeEventListener(
method: "close",
cb?: (event: { wasClean: boolean; code: number; reason: string; target: WebSocket }) => void,
): void;
removeEventListener(
method: "error",
cb?: (event: { error: any; message: any; type: string; target: WebSocket }) => void,
): void;
removeEventListener(method: "open", cb?: (event: { target: WebSocket }) => void): void;
removeEventListener(method: string, listener?: () => void): void;
// Events
on(event: 'close', listener: (this: WebSocket, code: number, reason: string) => void): this;
on(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
on(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'message', listener: (this: WebSocket, data: WebSocket.Data) => void): this;
on(event: 'open' , listener: (this: WebSocket) => void): this;
on(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
on(event: 'unexpected-response', listener: (this: WebSocket, request: http.ClientRequest, response: http.IncomingMessage) => void): this;
on(event: "close", listener: (this: WebSocket, code: number, reason: string) => void): this;
on(event: "error", listener: (this: WebSocket, err: Error) => void): this;
on(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
on(event: "message", listener: (this: WebSocket, data: WebSocket.Data) => void): this;
on(event: "open", listener: (this: WebSocket) => void): this;
on(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
on(
event: "unexpected-response",
listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void,
): this;
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
once(event: 'close', listener: (this: WebSocket, code: number, reason: string) => void): this;
once(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
once(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
once(event: 'message', listener: (this: WebSocket, data: WebSocket.Data) => void): this;
once(event: 'open' , listener: (this: WebSocket) => void): this;
once(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
once(event: 'unexpected-response', listener: (this: WebSocket, request: http.ClientRequest, response: http.IncomingMessage) => void): this;
once(event: "close", listener: (this: WebSocket, code: number, reason: string) => void): this;
once(event: "error", listener: (this: WebSocket, err: Error) => void): this;
once(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
once(event: "message", listener: (this: WebSocket, data: WebSocket.Data) => void): this;
once(event: "open", listener: (this: WebSocket) => void): this;
once(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
once(
event: "unexpected-response",
listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void,
): this;
once(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
off(event: 'close', listener: (this: WebSocket, code: number, reason: string) => void): this;
off(event: 'error', listener: (this: WebSocket, err: Error) => void): this;
off(event: 'upgrade', listener: (this: WebSocket, request: http.IncomingMessage) => void): this;
off(event: 'message', listener: (this: WebSocket, data: WebSocket.Data) => void): this;
off(event: 'open' , listener: (this: WebSocket) => void): this;
off(event: 'ping' | 'pong', listener: (this: WebSocket, data: Buffer) => void): this;
off(event: 'unexpected-response', listener: (this: WebSocket, request: http.ClientRequest, response: http.IncomingMessage) => void): this;
off(event: "close", listener: (this: WebSocket, code: number, reason: string) => void): this;
off(event: "error", listener: (this: WebSocket, err: Error) => void): this;
off(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
off(event: "message", listener: (this: WebSocket, data: WebSocket.Data) => void): this;
off(event: "open", listener: (this: WebSocket) => void): this;
off(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
off(
event: "unexpected-response",
listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void,
): this;
off(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
addListener(event: 'close', listener: (code: number, message: string) => void): this;
addListener(event: 'error', listener: (err: Error) => void): this;
addListener(event: 'upgrade', listener: (request: http.IncomingMessage) => void): this;
addListener(event: 'message', listener: (data: WebSocket.Data) => void): this;
addListener(event: 'open' , listener: () => void): this;
addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this;
addListener(event: 'unexpected-response', listener: (request: http.ClientRequest, response: http.IncomingMessage) => void): this;
addListener(event: "close", listener: (code: number, message: string) => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
addListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
addListener(event: "message", listener: (data: WebSocket.Data) => void): this;
addListener(event: "open", listener: () => void): this;
addListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
addListener(
event: "unexpected-response",
listener: (request: ClientRequest, response: IncomingMessage) => void,
): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: 'close', listener: (code: number, message: string) => void): this;
removeListener(event: 'error', listener: (err: Error) => void): this;
removeListener(event: 'upgrade', listener: (request: http.IncomingMessage) => void): this;
removeListener(event: 'message', listener: (data: WebSocket.Data) => void): this;
removeListener(event: 'open' , listener: () => void): this;
removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this;
removeListener(event: 'unexpected-response', listener: (request: http.ClientRequest, response: http.IncomingMessage) => void): this;
removeListener(event: "close", listener: (code: number, message: string) => void): this;
removeListener(event: "error", listener: (err: Error) => void): this;
removeListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
removeListener(event: "message", listener: (data: WebSocket.Data) => void): this;
removeListener(event: "open", listener: () => void): this;
removeListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
removeListener(
event: "unexpected-response",
listener: (request: ClientRequest, response: IncomingMessage) => void,
): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;

@@ -165,3 +202,3 @@ }

*/
type VerifyClientCallbackSync = (info: { origin: string; secure: boolean; req: http.IncomingMessage }) => boolean;
type VerifyClientCallbackSync = (info: { origin: string; secure: boolean; req: IncomingMessage }) => boolean;

@@ -173,4 +210,6 @@ /**

*/
type VerifyClientCallbackAsync = (info: { origin: string; secure: boolean; req: http.IncomingMessage }
, callback: (res: boolean, code?: number, message?: string, headers?: http.OutgoingHttpHeaders) => void) => void;
type VerifyClientCallbackAsync = (
info: { origin: string; secure: boolean; req: IncomingMessage },
callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void,
) => void;

@@ -187,3 +226,3 @@ interface ClientOptions extends SecureContextOptions {

origin?: string;
agent?: http.Agent;
agent?: Agent;
host?: string;

@@ -212,3 +251,3 @@ family?: number;

};
zlibInflateOptions?: zlib.ZlibOptions;
zlibInflateOptions?: ZlibOptions;
threshold?: number;

@@ -250,3 +289,3 @@ concurrencyLimit?: number;

backlog?: number;
server?: http.Server | https.Server;
server?: HTTPServer | HTTPSServer;
verifyClient?: VerifyClientCallbackAsync | VerifyClientCallbackSync;

@@ -268,3 +307,3 @@ handleProtocols?: any;

// WebSocket Server
class Server extends events.EventEmitter {
class Server extends EventEmitter {
options: ServerOptions;

@@ -278,35 +317,39 @@ path: string;

close(cb?: (err?: Error) => void): void;
handleUpgrade(request: http.IncomingMessage, socket: net.Socket,
upgradeHead: Buffer, callback: (client: WebSocket, request: http.IncomingMessage) => void): void;
shouldHandle(request: http.IncomingMessage): boolean | Promise<boolean>;
handleUpgrade(
request: IncomingMessage,
socket: Socket,
upgradeHead: Buffer,
callback: (client: WebSocket, request: IncomingMessage) => void,
): void;
shouldHandle(request: IncomingMessage): boolean | Promise<boolean>;
// Events
on(event: 'connection', cb: (this: Server, socket: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'error', cb: (this: Server, error: Error) => void): this;
on(event: 'headers', cb: (this: Server, headers: string[], request: http.IncomingMessage) => void): this;
on(event: 'close' | 'listening', cb: (this: Server) => void): this;
on(event: "connection", cb: (this: Server, socket: WebSocket, request: IncomingMessage) => void): this;
on(event: "error", cb: (this: Server, error: Error) => void): this;
on(event: "headers", cb: (this: Server, headers: string[], request: IncomingMessage) => void): this;
on(event: "close" | "listening", cb: (this: Server) => void): this;
on(event: string | symbol, listener: (this: Server, ...args: any[]) => void): this;
once(event: 'connection', cb: (this: Server, socket: WebSocket, request: http.IncomingMessage) => void): this;
once(event: 'error', cb: (this: Server, error: Error) => void): this;
once(event: 'headers', cb: (this: Server, headers: string[], request: http.IncomingMessage) => void): this;
once(event: 'close' | 'listening', cb: (this: Server) => void): this;
once(event: "connection", cb: (this: Server, socket: WebSocket, request: IncomingMessage) => void): this;
once(event: "error", cb: (this: Server, error: Error) => void): this;
once(event: "headers", cb: (this: Server, headers: string[], request: IncomingMessage) => void): this;
once(event: "close" | "listening", cb: (this: Server) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
off(event: 'connection', cb: (this: Server, socket: WebSocket, request: http.IncomingMessage) => void): this;
off(event: 'error', cb: (this: Server, error: Error) => void): this;
off(event: 'headers', cb: (this: Server, headers: string[], request: http.IncomingMessage) => void): this;
off(event: 'close' | 'listening', cb: (this: Server) => void): this;
off(event: "connection", cb: (this: Server, socket: WebSocket, request: IncomingMessage) => void): this;
off(event: "error", cb: (this: Server, error: Error) => void): this;
off(event: "headers", cb: (this: Server, headers: string[], request: IncomingMessage) => void): this;
off(event: "close" | "listening", cb: (this: Server) => void): this;
off(event: string | symbol, listener: (this: Server, ...args: any[]) => void): this;
addListener(event: 'connection', cb: (client: WebSocket, request: http.IncomingMessage) => void): this;
addListener(event: 'error', cb: (err: Error) => void): this;
addListener(event: 'headers', cb: (headers: string[], request: http.IncomingMessage) => void): this;
addListener(event: 'close' | 'listening', cb: () => void): this;
addListener(event: "connection", cb: (client: WebSocket, request: IncomingMessage) => void): this;
addListener(event: "error", cb: (err: Error) => void): this;
addListener(event: "headers", cb: (headers: string[], request: IncomingMessage) => void): this;
addListener(event: "close" | "listening", cb: () => void): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: 'connection', cb: (client: WebSocket) => void): this;
removeListener(event: 'error', cb: (err: Error) => void): this;
removeListener(event: 'headers', cb: (headers: string[], request: http.IncomingMessage) => void): this;
removeListener(event: 'close' | 'listening', cb: () => void): this;
removeListener(event: "connection", cb: (client: WebSocket) => void): this;
removeListener(event: "error", cb: (err: Error) => void): this;
removeListener(event: "headers", cb: (headers: string[], request: IncomingMessage) => void): this;
removeListener(event: "close" | "listening", cb: () => void): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;

@@ -316,5 +359,5 @@ }

// WebSocket stream
function createWebSocketStream(websocket: WebSocket, options?: stream.DuplexOptions): stream.Duplex;
function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
}
export = WebSocket;
{
"name": "@types/ws",
"version": "7.4.4",
"version": "7.4.5",
"description": "TypeScript definitions for ws",
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ws",
"license": "MIT",

@@ -54,4 +55,4 @@ "contributors": [

},
"typesPublisherContentHash": "0f06c4f2be6fc0cd19d4bc725964e3dd0e74843083aadf1716985b5be42bbb4d",
"typeScriptVersion": "3.5"
"typesPublisherContentHash": "9f28541650b7333d7fc31658780f4f9ad35b01395809ef964089854b8846b2e8",
"typeScriptVersion": "3.6"
}

@@ -11,3 +11,3 @@ # Installation

### Additional Details
* Last updated: Tue, 11 May 2021 01:01:57 GMT
* Last updated: Thu, 17 Jun 2021 09:31:14 GMT
* Dependencies: [@types/node](https://npmjs.com/package/@types/node)

@@ -14,0 +14,0 @@ * Global values: none

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc