Added type definition for reconnectingwebsocket. (#18705)

This commit is contained in:
Nicholas Guarracino
2017-08-08 13:16:49 -07:00
committed by Mohamed Hegazy
parent c23b6de8cf
commit 24debbc209
4 changed files with 113 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
// Type definitions for reconnectingwebsocket 1.0
// Project: https://github.com/joewalnes/reconnecting-websocket
// Definitions by: Nicholas Guarracino <https://github.com/nguarracino/>
// 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;
}
@@ -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();
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }