@types/ws
Advanced tools
Comparing version 8.5.4 to 8.5.5
@@ -234,3 +234,7 @@ // Type definitions for ws 8.5 | ||
*/ | ||
type VerifyClientCallbackSync = (info: { origin: string; secure: boolean; req: IncomingMessage }) => boolean; | ||
type VerifyClientCallbackSync<Request extends IncomingMessage = IncomingMessage> = (info: { | ||
origin: string; | ||
secure: boolean; | ||
req: Request; | ||
}) => boolean; | ||
@@ -242,4 +246,4 @@ /** | ||
*/ | ||
type VerifyClientCallbackAsync = ( | ||
info: { origin: string; secure: boolean; req: IncomingMessage }, | ||
type VerifyClientCallbackAsync<Request extends IncomingMessage = IncomingMessage> = ( | ||
info: { origin: string; secure: boolean; req: Request }, | ||
callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void, | ||
@@ -319,9 +323,15 @@ ) => void; | ||
interface ServerOptions { | ||
interface ServerOptions< | ||
U extends typeof WebSocket.WebSocket = typeof WebSocket.WebSocket, | ||
V extends typeof IncomingMessage = typeof IncomingMessage, | ||
> { | ||
host?: string | undefined; | ||
port?: number | undefined; | ||
backlog?: number | undefined; | ||
server?: HTTPServer | HTTPSServer | undefined; | ||
verifyClient?: VerifyClientCallbackAsync | VerifyClientCallbackSync | undefined; | ||
handleProtocols?: (protocols: Set<string>, request: IncomingMessage) => string | false; | ||
server?: HTTPServer<V> | HTTPSServer<V> | undefined; | ||
verifyClient?: | ||
| VerifyClientCallbackAsync<InstanceType<V>> | ||
| VerifyClientCallbackSync<InstanceType<V>> | ||
| undefined; | ||
handleProtocols?: (protocols: Set<string>, request: InstanceType<V>) => string | false; | ||
path?: string | undefined; | ||
@@ -333,3 +343,3 @@ noServer?: boolean | undefined; | ||
skipUTF8Validation?: boolean | undefined; | ||
WebSocket?: typeof WebSocket.WebSocket | undefined; | ||
WebSocket?: U | undefined; | ||
} | ||
@@ -344,8 +354,11 @@ | ||
// WebSocket Server | ||
class Server<T extends WebSocket = WebSocket> extends EventEmitter { | ||
options: ServerOptions; | ||
class Server< | ||
T extends typeof WebSocket.WebSocket = typeof WebSocket.WebSocket, | ||
U extends typeof IncomingMessage = typeof IncomingMessage, | ||
> extends EventEmitter { | ||
options: ServerOptions<T, U>; | ||
path: string; | ||
clients: Set<T>; | ||
clients: Set<InstanceType<T>>; | ||
constructor(options?: ServerOptions, callback?: () => void); | ||
constructor(options?: ServerOptions<T, U>, callback?: () => void); | ||
@@ -355,37 +368,37 @@ address(): AddressInfo | string; | ||
handleUpgrade( | ||
request: IncomingMessage, | ||
request: InstanceType<U>, | ||
socket: Duplex, | ||
upgradeHead: Buffer, | ||
callback: (client: T, request: IncomingMessage) => void, | ||
callback: (client: InstanceType<T>, request: InstanceType<U>) => void, | ||
): void; | ||
shouldHandle(request: IncomingMessage): boolean | Promise<boolean>; | ||
shouldHandle(request: InstanceType<U>): boolean | Promise<boolean>; | ||
// Events | ||
on(event: "connection", cb: (this: Server<T>, socket: T, request: IncomingMessage) => void): this; | ||
on(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this; | ||
on(event: "error", cb: (this: Server<T>, error: Error) => void): this; | ||
on(event: "headers", cb: (this: Server<T>, headers: string[], request: IncomingMessage) => void): this; | ||
on(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this; | ||
on(event: "close" | "listening", cb: (this: Server<T>) => void): this; | ||
on(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this; | ||
once(event: "connection", cb: (this: Server<T>, socket: T, request: IncomingMessage) => void): this; | ||
once(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this; | ||
once(event: "error", cb: (this: Server<T>, error: Error) => void): this; | ||
once(event: "headers", cb: (this: Server<T>, headers: string[], request: IncomingMessage) => void): this; | ||
once(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this; | ||
once(event: "close" | "listening", cb: (this: Server<T>) => void): this; | ||
once(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this; | ||
off(event: "connection", cb: (this: Server<T>, socket: T, request: IncomingMessage) => void): this; | ||
off(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this; | ||
off(event: "error", cb: (this: Server<T>, error: Error) => void): this; | ||
off(event: "headers", cb: (this: Server<T>, headers: string[], request: IncomingMessage) => void): this; | ||
off(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this; | ||
off(event: "close" | "listening", cb: (this: Server<T>) => void): this; | ||
off(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this; | ||
addListener(event: "connection", cb: (client: T, request: IncomingMessage) => void): this; | ||
addListener(event: "connection", cb: (client: InstanceType<T>, request: InstanceType<U>) => void): this; | ||
addListener(event: "error", cb: (err: Error) => void): this; | ||
addListener(event: "headers", cb: (headers: string[], request: IncomingMessage) => void): this; | ||
addListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this; | ||
addListener(event: "close" | "listening", cb: () => void): this; | ||
addListener(event: string | symbol, listener: (...args: any[]) => void): this; | ||
removeListener(event: "connection", cb: (client: T) => void): this; | ||
removeListener(event: "connection", cb: (client: InstanceType<T>, request: InstanceType<U>) => void): this; | ||
removeListener(event: "error", cb: (err: Error) => void): this; | ||
removeListener(event: "headers", cb: (headers: string[], request: IncomingMessage) => void): this; | ||
removeListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this; | ||
removeListener(event: "close" | "listening", cb: () => void): this; | ||
@@ -392,0 +405,0 @@ removeListener(event: string | symbol, listener: (...args: any[]) => void): this; |
{ | ||
"name": "@types/ws", | ||
"version": "8.5.4", | ||
"version": "8.5.5", | ||
"description": "TypeScript definitions for ws", | ||
@@ -60,4 +60,4 @@ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ws", | ||
}, | ||
"typesPublisherContentHash": "d78ccf27d7710f245ab25f9d4957067c8fc0f7aadc035919f7a890427d7360ca", | ||
"typeScriptVersion": "4.2", | ||
"typesPublisherContentHash": "6eea0ac9982d9cb29e842a5be3f7d3e0103c444a7b96a324c0ce4a86980da93f", | ||
"typeScriptVersion": "4.3", | ||
"exports": { | ||
@@ -64,0 +64,0 @@ ".": { |
@@ -11,3 +11,3 @@ # Installation | ||
### Additional Details | ||
* Last updated: Fri, 30 Dec 2022 00:32:41 GMT | ||
* Last updated: Thu, 08 Jun 2023 20:02:52 GMT | ||
* Dependencies: [@types/node](https://npmjs.com/package/@types/node) | ||
@@ -14,0 +14,0 @@ * Global values: none |
22086
368