From 24debbc209b0fd8e91c1b9a93c1f04508978eb54 Mon Sep 17 00:00:00 2001 From: Nicholas Guarracino Date: Tue, 8 Aug 2017 16:16:49 -0400 Subject: [PATCH] Added type definition for reconnectingwebsocket. (#18705) --- types/reconnectingwebsocket/index.d.ts | 43 +++++++++++++++++ .../reconnectingwebsocket-tests.ts | 46 +++++++++++++++++++ types/reconnectingwebsocket/tsconfig.json | 23 ++++++++++ types/reconnectingwebsocket/tslint.json | 1 + 4 files changed, 113 insertions(+) create mode 100644 types/reconnectingwebsocket/index.d.ts create mode 100644 types/reconnectingwebsocket/reconnectingwebsocket-tests.ts create mode 100644 types/reconnectingwebsocket/tsconfig.json create mode 100644 types/reconnectingwebsocket/tslint.json diff --git a/types/reconnectingwebsocket/index.d.ts b/types/reconnectingwebsocket/index.d.ts new file mode 100644 index 0000000000..f8e218c008 --- /dev/null +++ b/types/reconnectingwebsocket/index.d.ts @@ -0,0 +1,43 @@ +// Type definitions for reconnectingwebsocket 1.0 +// Project: https://github.com/joewalnes/reconnecting-websocket +// Definitions by: Nicholas Guarracino +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Options { + automaticOpen?: boolean; + binaryType?: 'blob' | 'arraybuffer'; + debug?: boolean; + maxReconnectAttempts?: number | null; + maxReconnectInterval?: number; + reconnectDecay?: number; + reconnectInterval?: number; + timeoutInterval?: number; +} + +export default class ReconnectingWebSocket { + constructor(url: string, protocols?: string[], options?: Options); + + static debugAll: boolean; + + static CONNECTING: number; + static OPEN: number; + static CLOSING: number; + static CLOSED: number; + + onclose: (event: any) => void; + onconnecting: (event: any) => void; + onerror: (event: any) => void; + onmessage: (event: any) => void; + onopen: (event: any) => void; + + close(code?: number, reason?: string): void; + open(reconnectAttempt?: boolean): void; + refresh(): void; + send(data: any): void; + + maxReconnectAttempts: number; + protocol: string | null; + readyState: number; + reconnectAttempts: number; + url: string; +} diff --git a/types/reconnectingwebsocket/reconnectingwebsocket-tests.ts b/types/reconnectingwebsocket/reconnectingwebsocket-tests.ts new file mode 100644 index 0000000000..d0c3bf600d --- /dev/null +++ b/types/reconnectingwebsocket/reconnectingwebsocket-tests.ts @@ -0,0 +1,46 @@ +import ReconnectingWebSocket from "reconnectingwebsocket"; +import { Options } from "reconnectingwebsocket"; + +const options: Options = { + automaticOpen: false, + binaryType: "blob", + debug: false, + maxReconnectAttempts: 1, + maxReconnectInterval: 1000, + reconnectDecay: 1.5, + reconnectInterval: 1000, + timeoutInterval: 1000 +}; + +const ws1: ReconnectingWebSocket = new ReconnectingWebSocket("url", ["protocol"], options); +const ws2: ReconnectingWebSocket = new ReconnectingWebSocket("url", ["protocol"]); +const ws3: ReconnectingWebSocket = new ReconnectingWebSocket("url"); + +ReconnectingWebSocket.debugAll = true; +ReconnectingWebSocket.CONNECTING = WebSocket.CONNECTING; +ReconnectingWebSocket.OPEN = WebSocket.OPEN; +ReconnectingWebSocket.CLOSING = WebSocket.CLOSING; +ReconnectingWebSocket.CLOSED = WebSocket.CLOSED; + +ws1.onclose = (event: any) => { +}; + +ws2.onconnecting = (event: any) => { +}; + +ws3.onerror = (event: any) => { +}; + +ws1.onmessage = (event: any) => { +}; + +ws1.onopen = (event: any) => { +}; + +ws1.open(true); + +ws1.refresh(); + +ws1.send({}); + +ws1.close(); diff --git a/types/reconnectingwebsocket/tsconfig.json b/types/reconnectingwebsocket/tsconfig.json new file mode 100644 index 0000000000..5810760606 --- /dev/null +++ b/types/reconnectingwebsocket/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "reconnectingwebsocket-tests.ts" + ] +} diff --git a/types/reconnectingwebsocket/tslint.json b/types/reconnectingwebsocket/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/reconnectingwebsocket/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }