reconnecting-websocket

  • Version 4.4.0
  • Published
  • 156 kB
  • No dependencies
  • MIT license

Install

npm i reconnecting-websocket
yarn add reconnecting-websocket
pnpm add reconnecting-websocket

Overview

Reconnecting WebSocket

Index

Classes

class ReconnectingWebSocket

class ReconnectingWebSocket {}

    constructor

    constructor(url: UrlProvider, protocols?: string | string[], options?: Options);

      property binaryType

      binaryType: BinaryType;

        property bufferedAmount

        readonly bufferedAmount: number;
        • The number of bytes of data that have been queued using calls to send() but not yet transmitted to the network. This value resets to zero once all queued data has been sent. This value does not reset to zero when the connection is closed; if you keep calling send(), this will continue to climb. Read only

        property CLOSED

        static readonly CLOSED: number;

          property CLOSED

          readonly CLOSED: number;

            property CLOSING

            static readonly CLOSING: number;

              property CLOSING

              readonly CLOSING: number;

                property CONNECTING

                static readonly CONNECTING: number;

                  property CONNECTING

                  readonly CONNECTING: number;

                    property extensions

                    readonly extensions: string;
                    • The extensions selected by the server. This is currently only the empty string or a list of extensions as negotiated by the connection

                    property onclose

                    onclose: (event: Events.CloseEvent) => void;
                    • An event listener to be called when the WebSocket connection's readyState changes to CLOSED

                    property onerror

                    onerror: (event: Events.ErrorEvent) => void;
                    • An event listener to be called when an error occurs

                    property onmessage

                    onmessage: (event: MessageEvent) => void;
                    • An event listener to be called when a message is received from the server

                    property onopen

                    onopen: (event: Event) => void;
                    • An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data

                    property OPEN

                    static readonly OPEN: number;

                      property OPEN

                      readonly OPEN: number;

                        property protocol

                        readonly protocol: string;
                        • A string indicating the name of the sub-protocol the server selected; this will be one of the strings specified in the protocols parameter when creating the WebSocket object

                        property readyState

                        readonly readyState: number;
                        • The current state of the connection; this is one of the Ready state constants

                        property retryCount

                        readonly retryCount: number;
                        • Returns the number or connection retries

                        property url

                        readonly url: string;
                        • The URL as resolved by the constructor

                        method addEventListener

                        addEventListener: <T extends keyof Events.WebSocketEventListenerMap>(
                        type: T,
                        listener: Events.WebSocketEventListenerMap[T]
                        ) => void;
                        • Register an event handler of a specific event type

                        method close

                        close: (code?: number, reason?: string) => void;
                        • Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED, this method does nothing

                        method dispatchEvent

                        dispatchEvent: (event: Event) => boolean;

                          method reconnect

                          reconnect: (code?: number, reason?: string) => void;
                          • Closes the WebSocket connection or connection attempt and connects again. Resets retry counter;

                          method removeEventListener

                          removeEventListener: <T extends keyof Events.WebSocketEventListenerMap>(
                          type: T,
                          listener: Events.WebSocketEventListenerMap[T]
                          ) => void;
                          • Removes an event listener

                          method send

                          send: (data: Message) => void;
                          • Enqueue specified data to be transmitted to the server over the WebSocket connection

                          Type Aliases

                          type CloseEvent

                          type CloseEvent = Events.CloseEvent;

                            type ErrorEvent

                            type ErrorEvent = Events.ErrorEvent;

                              type Event

                              type Event = Events.Event;

                                type ListenersMap

                                type ListenersMap = {
                                error: Array<Events.WebSocketEventListenerMap['error']>;
                                message: Array<Events.WebSocketEventListenerMap['message']>;
                                open: Array<Events.WebSocketEventListenerMap['open']>;
                                close: Array<Events.WebSocketEventListenerMap['close']>;
                                };

                                  type Message

                                  type Message = string | ArrayBuffer | Blob | ArrayBufferView;

                                    type Options

                                    type Options = {
                                    WebSocket?: any;
                                    maxReconnectionDelay?: number;
                                    minReconnectionDelay?: number;
                                    reconnectionDelayGrowFactor?: number;
                                    minUptime?: number;
                                    connectionTimeout?: number;
                                    maxRetries?: number;
                                    maxEnqueuedMessages?: number;
                                    startClosed?: boolean;
                                    debug?: boolean;
                                    };

                                      type UrlProvider

                                      type UrlProvider = string | (() => string) | (() => Promise<string>);

                                        Package Files (1)

                                        Dependencies (0)

                                        No dependencies.

                                        Dev Dependencies (15)

                                        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/reconnecting-websocket.

                                        • Markdown
                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/reconnecting-websocket)
                                        • HTML
                                          <a href="https://www.jsdocs.io/package/reconnecting-websocket"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>