@types/ws

  • Version 7.4.4
  • Published
  • 17.8 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 events.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 events.EventEmitter {}

                                  constructor

                                  constructor(address: any, options?: any);

                                    constructor

                                    constructor(address: any, protocols?: string | string[], options?: any);

                                      property binaryType

                                      binaryType: string;

                                        property bufferedAmount

                                        bufferedAmount: number;

                                          property CLOSED

                                          static CLOSED: number;
                                          • The connection is closed.

                                          property CLOSED

                                          CLOSED: number;
                                          • The connection is closed.

                                          property CLOSING

                                          static CLOSING: number;
                                          • The connection is in the process of closing.

                                          property CLOSING

                                          CLOSING: number;
                                          • The connection is in the process of closing.

                                          property CONNECTING

                                          static CONNECTING: number;
                                          • The connection is not yet open.

                                          property CONNECTING

                                          CONNECTING: number;
                                          • The connection is not yet open.

                                          property extensions

                                          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 OPEN: number;
                                                    • The connection is open and ready to communicate.

                                                    property OPEN

                                                    OPEN: number;
                                                    • The connection is open and ready to communicate.

                                                    property protocol

                                                    protocol: string;

                                                      property readyState

                                                      readyState: 0 | 1 | 2 | 3;
                                                      • The current state of the connection

                                                      property url

                                                      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?: http.Agent;

                                                                                            property family

                                                                                            family?: number;

                                                                                              property followRedirects

                                                                                              followRedirects?: boolean;

                                                                                                property handshakeTimeout

                                                                                                handshakeTimeout?: number;

                                                                                                  property headers

                                                                                                  headers?: { [key: string]: string };

                                                                                                    property host

                                                                                                    host?: string;

                                                                                                      property localAddress

                                                                                                      localAddress?: string;

                                                                                                        property maxPayload

                                                                                                        maxPayload?: number;

                                                                                                          property maxRedirects

                                                                                                          maxRedirects?: number;

                                                                                                            property origin

                                                                                                            origin?: string;

                                                                                                              property perMessageDeflate

                                                                                                              perMessageDeflate?: boolean | PerMessageDeflateOptions;

                                                                                                                property protocol

                                                                                                                protocol?: string;

                                                                                                                  property protocolVersion

                                                                                                                  protocolVersion?: number;

                                                                                                                    property rejectUnauthorized

                                                                                                                    rejectUnauthorized?: boolean;

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

                                                                                                                                                interface MessageEvent

                                                                                                                                                interface MessageEvent {}

                                                                                                                                                  property data

                                                                                                                                                  data: Data;

                                                                                                                                                    property target

                                                                                                                                                    target: WebSocket;

                                                                                                                                                      property type

                                                                                                                                                      type: string;

                                                                                                                                                        interface OpenEvent

                                                                                                                                                        interface OpenEvent {}

                                                                                                                                                          property target

                                                                                                                                                          target: WebSocket;

                                                                                                                                                            interface PerMessageDeflateOptions

                                                                                                                                                            interface PerMessageDeflateOptions {}

                                                                                                                                                              property clientMaxWindowBits

                                                                                                                                                              clientMaxWindowBits?: number;

                                                                                                                                                                property clientNoContextTakeover

                                                                                                                                                                clientNoContextTakeover?: boolean;

                                                                                                                                                                  property concurrencyLimit

                                                                                                                                                                  concurrencyLimit?: number;

                                                                                                                                                                    property serverMaxWindowBits

                                                                                                                                                                    serverMaxWindowBits?: number;

                                                                                                                                                                      property serverNoContextTakeover

                                                                                                                                                                      serverNoContextTakeover?: boolean;

                                                                                                                                                                        property threshold

                                                                                                                                                                        threshold?: number;

                                                                                                                                                                          property zlibDeflateOptions

                                                                                                                                                                          zlibDeflateOptions?: {
                                                                                                                                                                          flush?: number;
                                                                                                                                                                          finishFlush?: number;
                                                                                                                                                                          chunkSize?: number;
                                                                                                                                                                          windowBits?: number;
                                                                                                                                                                          level?: number;
                                                                                                                                                                          memLevel?: number;
                                                                                                                                                                          strategy?: number;
                                                                                                                                                                          dictionary?: Buffer | Buffer[] | DataView;
                                                                                                                                                                          info?: boolean;
                                                                                                                                                                          };

                                                                                                                                                                            property zlibInflateOptions

                                                                                                                                                                            zlibInflateOptions?: zlib.ZlibOptions;

                                                                                                                                                                              interface ServerOptions

                                                                                                                                                                              interface ServerOptions {}

                                                                                                                                                                                property backlog

                                                                                                                                                                                backlog?: number;

                                                                                                                                                                                  property clientTracking

                                                                                                                                                                                  clientTracking?: boolean;

                                                                                                                                                                                    property handleProtocols

                                                                                                                                                                                    handleProtocols?: any;

                                                                                                                                                                                      property host

                                                                                                                                                                                      host?: string;

                                                                                                                                                                                        property maxPayload

                                                                                                                                                                                        maxPayload?: number;

                                                                                                                                                                                          property noServer

                                                                                                                                                                                          noServer?: boolean;

                                                                                                                                                                                            property path

                                                                                                                                                                                            path?: string;

                                                                                                                                                                                              property perMessageDeflate

                                                                                                                                                                                              perMessageDeflate?: boolean | PerMessageDeflateOptions;

                                                                                                                                                                                                property port

                                                                                                                                                                                                port?: number;

                                                                                                                                                                                                  property server

                                                                                                                                                                                                  server?: http.Server | https.Server;

                                                                                                                                                                                                    property verifyClient

                                                                                                                                                                                                    verifyClient?: VerifyClientCallbackAsync | VerifyClientCallbackSync;

                                                                                                                                                                                                      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: http.IncomingMessage },
                                                                                                                                                                                                      callback: (
                                                                                                                                                                                                      res: boolean,
                                                                                                                                                                                                      code?: number,
                                                                                                                                                                                                      message?: string,
                                                                                                                                                                                                      headers?: http.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: http.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>