@types/ws

  • Version 7.4.7
  • Published
  • 18.9 kB
  • 1 dependency
  • MIT license

Install

npm i @types/ws
yarn add @types/ws
pnpm add @types/ws

Overview

TypeScript definitions for ws

Index

Functions

function createWebSocketStream

createWebSocketStream: (websocket: WebSocket, options?: any) => any;

    Classes

    class Server

    class Server extends EventEmitter {}

      constructor

      constructor(options?: ServerOptions, callback?: () => void);

        property clients

        clients: Set<WebSocket>;

          property options

          options: ServerOptions;

            property path

            path: string;

              method addListener

              addListener: {
              (event: 'connection', cb: (client: WebSocket, request: any) => void): this;
              (event: 'error', cb: (err: Error) => void): this;
              (event: 'headers', cb: (headers: string[], request: any) => void): this;
              (event: 'close' | 'listening', cb: () => void): this;
              (event: string | symbol, listener: (...args: any[]) => void): this;
              };

                method address

                address: () => AddressInfo | string;

                  method close

                  close: (cb?: (err?: Error) => void) => void;

                    method handleUpgrade

                    handleUpgrade: (
                    request: any,
                    socket: any,
                    upgradeHead: any,
                    callback: (client: WebSocket, request: any) => void
                    ) => void;

                      method off

                      off: {
                      (
                      event: 'connection',
                      cb: (this: Server, socket: WebSocket, request: any) => void
                      ): this;
                      (event: 'error', cb: (this: Server, error: Error) => void): this;
                      (
                      event: 'headers',
                      cb: (this: Server, headers: string[], request: any) => void
                      ): this;
                      (event: 'close' | 'listening', cb: (this: Server) => void): this;
                      (
                      event: string | symbol,
                      listener: (this: Server, ...args: any[]) => void
                      ): this;
                      };

                        method on

                        on: {
                        (
                        event: 'connection',
                        cb: (this: Server, socket: WebSocket, request: any) => void
                        ): this;
                        (event: 'error', cb: (this: Server, error: Error) => void): this;
                        (
                        event: 'headers',
                        cb: (this: Server, headers: string[], request: any) => void
                        ): this;
                        (event: 'close' | 'listening', cb: (this: Server) => void): this;
                        (
                        event: string | symbol,
                        listener: (this: Server, ...args: any[]) => void
                        ): this;
                        };

                          method once

                          once: {
                          (
                          event: 'connection',
                          cb: (this: Server, socket: WebSocket, request: any) => void
                          ): this;
                          (event: 'error', cb: (this: Server, error: Error) => void): this;
                          (
                          event: 'headers',
                          cb: (this: Server, headers: string[], request: any) => void
                          ): this;
                          (event: 'close' | 'listening', cb: (this: Server) => void): this;
                          (event: string | symbol, listener: (...args: any[]) => void): this;
                          };

                            method removeListener

                            removeListener: {
                            (event: 'connection', cb: (client: WebSocket) => void): this;
                            (event: 'error', cb: (err: Error) => void): this;
                            (event: 'headers', cb: (headers: string[], request: any) => void): this;
                            (event: 'close' | 'listening', cb: () => void): this;
                            (event: string | symbol, listener: (...args: any[]) => void): this;
                            };

                              method shouldHandle

                              shouldHandle: (request: any) => boolean | Promise<boolean>;

                                class WebSocket

                                class WebSocket extends EventEmitter {}

                                  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 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.OpenEvent) => 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: {
                                                        (
                                                        method: 'message',
                                                        cb: (event: { data: any; type: string; target: WebSocket }) => void,
                                                        options?: WebSocket.EventListenerOptions
                                                        ): void;
                                                        (
                                                        method: 'close',
                                                        cb: (event: {
                                                        wasClean: boolean;
                                                        code: number;
                                                        reason: string;
                                                        target: WebSocket;
                                                        }) => void,
                                                        options?: WebSocket.EventListenerOptions
                                                        ): void;
                                                        (
                                                        method: 'error',
                                                        cb: (event: {
                                                        error: any;
                                                        message: any;
                                                        type: string;
                                                        target: WebSocket;
                                                        }) => void,
                                                        options?: WebSocket.EventListenerOptions
                                                        ): void;
                                                        (
                                                        method: 'open',
                                                        cb: (event: { target: WebSocket }) => void,
                                                        options?: WebSocket.EventListenerOptions
                                                        ): void;
                                                        (
                                                        method: string,
                                                        listener: () => void,
                                                        options?: WebSocket.EventListenerOptions
                                                        ): void;
                                                        };

                                                          method addListener

                                                          addListener: {
                                                          (event: 'close', listener: (code: number, message: string) => void): this;
                                                          (event: 'error', listener: (err: Error) => void): this;
                                                          (event: 'upgrade', listener: (request: any) => void): this;
                                                          (event: 'message', listener: (data: any) => void): this;
                                                          (event: 'open', listener: () => void): this;
                                                          (event: 'ping' | 'pong', listener: (data: any) => void): this;
                                                          (
                                                          event: 'unexpected-response',
                                                          listener: (request: any, response: any) => void
                                                          ): this;
                                                          (event: string | symbol, listener: (...args: any[]) => void): this;
                                                          };

                                                            method close

                                                            close: (code?: number, data?: string) => void;

                                                              method off

                                                              off: {
                                                              (
                                                              event: 'close',
                                                              listener: (this: WebSocket, code: number, reason: string) => void
                                                              ): this;
                                                              (event: 'error', listener: (this: WebSocket, err: Error) => void): this;
                                                              (event: 'upgrade', listener: (this: WebSocket, request: any) => void): this;
                                                              (event: 'message', listener: (this: WebSocket, data: any) => void): this;
                                                              (event: 'open', listener: (this: WebSocket) => void): this;
                                                              (
                                                              event: 'ping' | 'pong',
                                                              listener: (this: WebSocket, data: any) => void
                                                              ): this;
                                                              (
                                                              event: 'unexpected-response',
                                                              listener: (this: WebSocket, request: any, response: any) => void
                                                              ): this;
                                                              (
                                                              event: string | symbol,
                                                              listener: (this: WebSocket, ...args: any[]) => void
                                                              ): this;
                                                              };

                                                                method on

                                                                on: {
                                                                (
                                                                event: 'close',
                                                                listener: (this: WebSocket, code: number, reason: string) => void
                                                                ): this;
                                                                (event: 'error', listener: (this: WebSocket, err: Error) => void): this;
                                                                (event: 'upgrade', listener: (this: WebSocket, request: any) => void): this;
                                                                (event: 'message', listener: (this: WebSocket, data: any) => void): this;
                                                                (event: 'open', listener: (this: WebSocket) => void): this;
                                                                (
                                                                event: 'ping' | 'pong',
                                                                listener: (this: WebSocket, data: any) => void
                                                                ): this;
                                                                (
                                                                event: 'unexpected-response',
                                                                listener: (this: WebSocket, request: any, response: any) => void
                                                                ): this;
                                                                (
                                                                event: string | symbol,
                                                                listener: (this: WebSocket, ...args: any[]) => void
                                                                ): this;
                                                                };

                                                                  method once

                                                                  once: {
                                                                  (
                                                                  event: 'close',
                                                                  listener: (this: WebSocket, code: number, reason: string) => void
                                                                  ): this;
                                                                  (event: 'error', listener: (this: WebSocket, err: Error) => void): this;
                                                                  (event: 'upgrade', listener: (this: WebSocket, request: any) => void): this;
                                                                  (event: 'message', listener: (this: WebSocket, data: any) => void): this;
                                                                  (event: 'open', listener: (this: WebSocket) => void): this;
                                                                  (
                                                                  event: 'ping' | 'pong',
                                                                  listener: (this: WebSocket, data: any) => void
                                                                  ): this;
                                                                  (
                                                                  event: 'unexpected-response',
                                                                  listener: (this: WebSocket, request: any, response: any) => void
                                                                  ): this;
                                                                  (
                                                                  event: string | symbol,
                                                                  listener: (this: WebSocket, ...args: any[]) => void
                                                                  ): this;
                                                                  };

                                                                    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: {
                                                                        (
                                                                        method: 'message',
                                                                        cb?: (event: { data: any; type: string; target: WebSocket }) => void
                                                                        ): void;
                                                                        (
                                                                        method: 'close',
                                                                        cb?: (event: {
                                                                        wasClean: boolean;
                                                                        code: number;
                                                                        reason: string;
                                                                        target: WebSocket;
                                                                        }) => void
                                                                        ): void;
                                                                        (
                                                                        method: 'error',
                                                                        cb?: (event: {
                                                                        error: any;
                                                                        message: any;
                                                                        type: string;
                                                                        target: WebSocket;
                                                                        }) => void
                                                                        ): void;
                                                                        (method: 'open', cb?: (event: { target: WebSocket }) => void): void;
                                                                        (method: string, listener?: () => void): void;
                                                                        };

                                                                          method removeListener

                                                                          removeListener: {
                                                                          (event: 'close', listener: (code: number, message: string) => void): this;
                                                                          (event: 'error', listener: (err: Error) => void): this;
                                                                          (event: 'upgrade', listener: (request: any) => void): this;
                                                                          (event: 'message', listener: (data: any) => void): this;
                                                                          (event: 'open', listener: () => void): this;
                                                                          (event: 'ping' | 'pong', listener: (data: any) => void): this;
                                                                          (
                                                                          event: 'unexpected-response',
                                                                          listener: (request: any, response: any) => void
                                                                          ): this;
                                                                          (event: string | symbol, listener: (...args: any[]) => void): this;
                                                                          };

                                                                            method send

                                                                            send: {
                                                                            (data: any, 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 {}

                                                                                  property address

                                                                                  address: string;

                                                                                    property family

                                                                                    family: string;

                                                                                      property port

                                                                                      port: number;

                                                                                        interface ClientOptions

                                                                                        interface ClientOptions extends SecureContextOptions {}

                                                                                          property agent

                                                                                          agent?: Agent | undefined;

                                                                                            property family

                                                                                            family?: number | 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;

                                                                                                                      method checkServerIdentity

                                                                                                                      checkServerIdentity: (servername: string, cert: CertMeta) => boolean;

                                                                                                                        interface CloseEvent

                                                                                                                        interface CloseEvent {}

                                                                                                                          property code

                                                                                                                          code: number;

                                                                                                                            property reason

                                                                                                                            reason: string;

                                                                                                                              property target

                                                                                                                              target: WebSocket;

                                                                                                                                property type

                                                                                                                                type: string;

                                                                                                                                  property wasClean

                                                                                                                                  wasClean: boolean;

                                                                                                                                    interface ErrorEvent

                                                                                                                                    interface ErrorEvent {}

                                                                                                                                      property error

                                                                                                                                      error: any;

                                                                                                                                        property message

                                                                                                                                        message: string;

                                                                                                                                          property target

                                                                                                                                          target: WebSocket;

                                                                                                                                            property type

                                                                                                                                            type: string;

                                                                                                                                              interface EventListenerOptions

                                                                                                                                              interface EventListenerOptions {}

                                                                                                                                                property once

                                                                                                                                                once?: boolean | undefined;

                                                                                                                                                  interface MessageEvent

                                                                                                                                                  interface MessageEvent {}

                                                                                                                                                    property data

                                                                                                                                                    data: Data;

                                                                                                                                                      property target

                                                                                                                                                      target: WebSocket;

                                                                                                                                                        property type

                                                                                                                                                        type: string;

                                                                                                                                                          interface OpenEvent

                                                                                                                                                          interface OpenEvent {}

                                                                                                                                                            property target

                                                                                                                                                            target: WebSocket;

                                                                                                                                                              property type

                                                                                                                                                              type: string;

                                                                                                                                                                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 {}

                                                                                                                                                                                    property backlog

                                                                                                                                                                                    backlog?: number | undefined;

                                                                                                                                                                                      property clientTracking

                                                                                                                                                                                      clientTracking?: boolean | undefined;

                                                                                                                                                                                        property handleProtocols

                                                                                                                                                                                        handleProtocols?: any;

                                                                                                                                                                                          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 | HTTPSServer | undefined;

                                                                                                                                                                                                        property verifyClient

                                                                                                                                                                                                        verifyClient?: VerifyClientCallbackAsync | VerifyClientCallbackSync | undefined;

                                                                                                                                                                                                          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 VerifyClientCallbackAsync

                                                                                                                                                                                                          type VerifyClientCallbackAsync = (
                                                                                                                                                                                                          info: { origin: string; secure: boolean; req: IncomingMessage },
                                                                                                                                                                                                          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 = (info: {
                                                                                                                                                                                                          origin: string;
                                                                                                                                                                                                          secure: boolean;
                                                                                                                                                                                                          req: IncomingMessage;
                                                                                                                                                                                                          }) => 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 onejsDocs.io badgeto 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>