egos-transfer 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -108,7 +108,6 @@ class PeerTransfer {
108
108
  return;
109
109
  }
110
110
  if (err.message === constant_1.CONNECTION_LIMIT_EXCEED) {
111
- this.stop();
112
111
  this.onConnectLimit();
113
112
  return done(null);
114
113
  }
@@ -206,7 +205,7 @@ class PeerTransfer {
206
205
  }
207
206
  removeConnection(peerId, connectionId) {
208
207
  var _a, _b, _c;
209
- // console.log('removeConnection@', peerId, connectionId);
208
+ // console.trace('removeConnection@', peerId, connectionId);
210
209
  const conn = this.connectPool.get(peerId);
211
210
  if (conn) {
212
211
  if (connectionId && conn.connectionId !== connectionId) {
@@ -414,15 +413,19 @@ class PeerTransfer {
414
413
  this.removeConnection(exists.peer, exists.connectionId);
415
414
  }
416
415
  }
416
+ let timer = null;
417
417
  return new Promise((resolve) => {
418
418
  const done = (connection) => {
419
419
  if (connection) {
420
420
  this.addConnection(connection);
421
421
  }
422
- clearTimeout(timer);
422
+ if (timer) {
423
+ clearTimeout(timer);
424
+ timer = null;
425
+ }
423
426
  resolve(connection);
424
427
  };
425
- const timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
428
+ timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
426
429
  if (this.isValidConnection(conn)) {
427
430
  this.addConnection(conn);
428
431
  done(conn);
@@ -431,6 +434,7 @@ class PeerTransfer {
431
434
  this.removeConnection(conn.peer, conn.connectionId);
432
435
  done(undefined);
433
436
  }
437
+ timer = null;
434
438
  }), constant_1.CONNECTION_TIMEOUT);
435
439
  conn.on('data', (message) => {
436
440
  switch (message.scope) {
@@ -463,6 +467,10 @@ class PeerTransfer {
463
467
  done(conn);
464
468
  }));
465
469
  if (this.isValidConnection(conn)) {
470
+ if (timer) {
471
+ clearTimeout(timer);
472
+ }
473
+ timer = null;
466
474
  done(conn);
467
475
  }
468
476
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egos-transfer",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "1234",
5
5
  "homepage": "https://github.com/superbogy/peer-transfer#readme",
6
6
  "bugs": {
package/src/index.ts CHANGED
@@ -150,7 +150,6 @@ export abstract class PeerTransfer {
150
150
  return;
151
151
  }
152
152
  if (err.message === CONNECTION_LIMIT_EXCEED) {
153
- this.stop();
154
153
  this.onConnectLimit();
155
154
  return done(null);
156
155
  }
@@ -248,7 +247,7 @@ export abstract class PeerTransfer {
248
247
  }
249
248
 
250
249
  removeConnection(peerId: string, connectionId?: string) {
251
- // console.log('removeConnection@', peerId, connectionId);
250
+ // console.trace('removeConnection@', peerId, connectionId);
252
251
  const conn = this.connectPool.get(peerId);
253
252
  if (conn) {
254
253
  if (connectionId && conn.connectionId !== connectionId) {
@@ -451,15 +450,19 @@ export abstract class PeerTransfer {
451
450
  this.removeConnection(exists.peer, exists.connectionId);
452
451
  }
453
452
  }
453
+ let timer = null;
454
454
  return new Promise((resolve) => {
455
455
  const done = (connection?: DataConnection) => {
456
456
  if (connection) {
457
457
  this.addConnection(connection);
458
458
  }
459
- clearTimeout(timer);
459
+ if (timer) {
460
+ clearTimeout(timer);
461
+ timer = null;
462
+ }
460
463
  resolve(connection);
461
464
  };
462
- const timer = setTimeout(async () => {
465
+ timer = setTimeout(async () => {
463
466
  if (this.isValidConnection(conn)) {
464
467
  this.addConnection(conn);
465
468
  done(conn);
@@ -467,6 +470,7 @@ export abstract class PeerTransfer {
467
470
  this.removeConnection(conn.peer, conn.connectionId);
468
471
  done(undefined);
469
472
  }
473
+ timer = null;
470
474
  }, CONNECTION_TIMEOUT);
471
475
  conn.on('data', (message: any) => {
472
476
  switch (message.scope) {
@@ -499,6 +503,10 @@ export abstract class PeerTransfer {
499
503
  done(conn);
500
504
  });
501
505
  if (this.isValidConnection(conn)) {
506
+ if (timer) {
507
+ clearTimeout(timer);
508
+ }
509
+ timer = null;
502
510
  done(conn);
503
511
  }
504
512
  });