2.0.4 • Published 4 years ago

reconnection v2.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

reconnection

Dependency Status devDependency Status Build Status: Linux Build Status: Windows npm version Downloads gzip size type-coverage

features

  • support browser and nodejs connection client
  • support client of websocket, tcp and so on

install

npm i reconnection

usage

// nodejs:
import Reconnector from "reconnection";
import * as WebSocket from "ws";

// browser(module):
import Reconnector from "reconnection";

// browser(script tag):
// <script src="./node_modules/reconnection/reconnection.min.js"></script>

let ws;
const reconnector = new Reconnector(() => {
    console.log(`connecting...`);
    ws = new WebSocket("ws://localhost:8000");
    ws.onclose = () => {
        console.log(`disconnected...`);
        reconnector.reconnect();
    };
    ws.onopen = () => {
        console.log("connected...");
        reconnector.reset();
    };
    ws.onerror = error => {
        console.log(error);
    };
});

options

const reconnector = new Reconnector(() => {
    // ...
}, {
    startTimeout: 3000, // 3000->4500->6750->10125->15187->22781->30000->30000...
    increaseRate: 1.5,
    endTimeout: 30000,
    maxTimes: Infinity // for Infinity, never give up; for 3, just reconnect 3 times, if fails, stop.
});

change logs

// v2
import Reconnector from "reconnection/nodejs/nodejs";
import Reconnector from "reconnection/browser/browser";

// v1
import { Reconnector } from "reconnection/nodejs";
import { Reconnector } from "reconnection/browser";
2.0.4

4 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago