Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/plantain-00/reconnection
A javascript library for browser or nodejs client reconnection.
https://github.com/plantain-00/reconnection
Last synced: 12 days ago
JSON representation
A javascript library for browser or nodejs client reconnection.
- Host: GitHub
- URL: https://github.com/plantain-00/reconnection
- Owner: plantain-00
- License: mit
- Created: 2016-12-27T06:04:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T23:43:47.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T19:07:24.791Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 1.22 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# reconnection
[![Dependency Status](https://david-dm.org/plantain-00/reconnection.svg)](https://david-dm.org/plantain-00/reconnection)
[![devDependency Status](https://david-dm.org/plantain-00/reconnection/dev-status.svg)](https://david-dm.org/plantain-00/reconnection#info=devDependencies)
[![Build Status: Windows](https://ci.appveyor.com/api/projects/status/github/plantain-00/reconnection?branch=master&svg=true)](https://ci.appveyor.com/project/plantain-00/reconnection/branch/master)
![Github CI](https://github.com/plantain-00/reconnection/workflows/Github%20CI/badge.svg)
[![npm version](https://badge.fury.io/js/reconnection.svg)](https://badge.fury.io/js/reconnection)
[![Downloads](https://img.shields.io/npm/dm/reconnection.svg)](https://www.npmjs.com/package/reconnection)
[![gzip size](https://img.badgesize.io/https://unpkg.com/reconnection?compression=gzip)](https://unpkg.com/reconnection)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fplantain-00%2Freconnection%2Fmaster%2Fpackage.json)](https://github.com/plantain-00/reconnection)## features
+ support browser and nodejs connection client
+ support client of websocket, tcp and so on## install
`npm i reconnection`
## usage
```ts
// nodejs:
import Reconnector from "reconnection";
import * as WebSocket from "ws";// browser(module):
import Reconnector from "reconnection";// browser(script tag):
//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
```ts
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
```ts
// v2
import Reconnector from "reconnection/nodejs/nodejs";
import Reconnector from "reconnection/browser/browser";// v1
import { Reconnector } from "reconnection/nodejs";
import { Reconnector } from "reconnection/browser";
```