robust-websocket icon indicating copy to clipboard operation
robust-websocket copied to clipboard

TypeScript types

Open AkisArou opened this issue 2 years ago • 1 comments

Hello, I will use your lib in a project of mine, and I've implemented some typings. Maybe you can add them if you'd like to!

declare module "robust-websocket" {
  declare class RobustWebSocket {
    constructor(streamUri: string | ((ws: WebSocket) => string), protocols: string[], options?: {
      timeout?: number;
      shouldReconnect?: (event: CloseEvent, ws: WebSocket) => number | boolean;
      automaticOpen?: boolean;
      ignoreConnectivityEvents?: boolean;
    });

    attempts: number;
    reconnects: number;
    readyState: number;
    url: string;
    protocol: string;
    extensions: string;
    bufferedAmount: number;
    binaryType: BinaryType;

    send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;

    close(code?: number, reason?: string): void;

    dispatchEvent(event: Event): boolean;


    addEventListener(type: "open", callback: (event: Event) => void): void;
    addEventListener(type: "close", callback: (event: CloseEvent) => void): void;
    addEventListener(type: "error", callback: (event: Event) => void): void;
    addEventListener(type: "message", callback: (event: MessageEvent) => void): void;

    removeEventListener(type: "open", callback: (event: Event) => void): void;
    removeEventListener(type: "close", callback: (event: CloseEvent) => void): void;
    removeEventListener(type: "error", callback: (event: Event) => void): void;
    removeEventListener(type: "message", callback: (event: MessageEvent) => void): void;
  }
}

AkisArou avatar Jul 12 '22 21:07 AkisArou

I'm more than happy to take a pull request for it!

nathanboktae avatar Jul 13 '22 20:07 nathanboktae