Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@syncot/connection

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@syncot/connection - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.2.0](https://github.com/SyncOT/SyncOT/compare/@syncot/connection@0.1.4...@syncot/connection@0.2.0) (2020-04-24)
### Features
* add counterResetDelay option ([159469a](https://github.com/SyncOT/SyncOT/commit/159469ad2db1835eaffaaa3a50a43e882c662b78))
## [0.1.4](https://github.com/SyncOT/SyncOT/compare/@syncot/connection@0.1.3...@syncot/connection@0.1.4) (2020-01-28)

@@ -8,0 +19,0 @@

8

lib/manager.d.ts

@@ -46,2 +46,8 @@ import { EmitterInterface, SyncOtEmitter } from '@syncot/events';

delayFactor?: number;
/**
* The number of milliseconds to wait after establishing a connection
* before resetting the counter of failed connections.
* Default is 0.
*/
counterResetDelay?: number;
}

@@ -51,2 +57,2 @@ /**

*/
export declare function createStreamManager({ connection, createStream, minDelay, maxDelay, delayFactor, }: StreamManagerOptions): StreamManager;
export declare function createStreamManager({ connection, createStream, minDelay, maxDelay, delayFactor, counterResetDelay, }: StreamManagerOptions): StreamManager;

15

lib/manager.js

@@ -6,7 +6,7 @@ import { SyncOtEmitter } from '@syncot/events';

*/
export function createStreamManager({ connection, createStream, minDelay, maxDelay, delayFactor, }) {
return new Manager(connection, createStream, minDelay, maxDelay, delayFactor);
export function createStreamManager({ connection, createStream, minDelay, maxDelay, delayFactor, counterResetDelay, }) {
return new Manager(connection, createStream, minDelay, maxDelay, delayFactor, counterResetDelay);
}
class Manager extends SyncOtEmitter {
constructor(connection, createStream, minDelay = 1000, maxDelay = 10000, delayFactor = 1.5) {
constructor(connection, createStream, minDelay = 1000, maxDelay = 10000, delayFactor = 1.5, counterResetDelay = 0) {
super();

@@ -18,4 +18,6 @@ this.connection = connection;

this.delayFactor = delayFactor;
this.counterResetDelay = counterResetDelay;
this.attempt = -1;
this.scheduledConnect = undefined;
this.connectionTime = 0;
this.onConnect = () => {

@@ -25,3 +27,5 @@ this.cancelScheduledConnect();

this.onDisconnect = () => {
this.attempt = 0;
if (this.connectionTime + this.counterResetDelay <= Date.now()) {
this.attempt = 0;
}
this.scheduleConnect();

@@ -39,2 +43,4 @@ };

(this.delayFactor >= 1 || this.delayFactor === 0), 'Argument "delayFactor" must be a finite number >= 1 or == 0.');
assert(typeof this.counterResetDelay === 'number' &&
!Number.isNaN(this.counterResetDelay), 'Argument "counterResetDelay" must be a valid number.');
this.connection.on('connect', this.onConnect);

@@ -69,2 +75,3 @@ this.connection.on('disconnect', this.onDisconnect);

this.stream = stream;
this.connectionTime = Date.now();
this.connection.connect(stream);

@@ -71,0 +78,0 @@ }

{
"name": "@syncot/connection",
"version": "0.1.4",
"version": "0.2.0",
"description": "An RPC library for communication over Duplex object streams.",

@@ -42,3 +42,3 @@ "keywords": [

},
"gitHead": "4c301b17359a9fc7e7da55677f752f7b74a4b2e3"
"gitHead": "52d9f18d2fa330979af433745ff92d2bc0d4c8f8"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc