egos-transfer 0.1.6 → 0.1.8

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.
Files changed (3) hide show
  1. package/dist/index.js +20 -21
  2. package/package.json +1 -1
  3. package/src/index.ts +15 -15
package/dist/index.js CHANGED
@@ -119,7 +119,7 @@ class PeerTransfer {
119
119
  return this.reconnect();
120
120
  }
121
121
  done(null);
122
- return this.reconnect();
122
+ return this.createPeer(true);
123
123
  }));
124
124
  });
125
125
  peer.on('connection', (conn) => {
@@ -227,7 +227,7 @@ class PeerTransfer {
227
227
  }
228
228
  checkConnection() {
229
229
  if (this.checkerId) {
230
- return;
230
+ clearInterval(this.checkerId);
231
231
  }
232
232
  this.checkerId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
233
233
  var _a;
@@ -235,21 +235,22 @@ class PeerTransfer {
235
235
  yield this.reconnect();
236
236
  }
237
237
  // turn credential expires
238
- if (this.peerConfig.turnExpiredAt && Date.now() - 30000 > this.peerConfig.turnExpiredAt) {
238
+ if (this.peerConfig.turnExpiredAt && this.peerConfig.turnExpiredAt - 30000 < Date.now()) {
239
239
  // this.connectPool.clear();
240
+ yield this.reloadConfig();
240
241
  yield this.createPeer(true);
241
242
  return;
242
243
  }
243
- // const deviceIds = this.connectPool.keys();
244
- // for (const deviceId of deviceIds) {
245
- // const conn = this.connectPool.get(deviceId);
246
- // if (!this.isValidConnection(conn)) {
247
- // this.removeConnection(conn.peer);
248
- // this.peer?._removeConnection(conn);
249
- // } else {
250
- // this.ping(conn.peer);
251
- // }
252
- // }
244
+ const deviceIds = this.connectPool.keys();
245
+ for (const deviceId of deviceIds) {
246
+ const conn = this.connectPool.get(deviceId);
247
+ if (!this.isValidConnection(conn)) {
248
+ this.removeConnection(conn.peer);
249
+ }
250
+ else {
251
+ this.ping(conn.peer);
252
+ }
253
+ }
253
254
  }), constant_1.HEARTBEAT_INTERVAL);
254
255
  }
255
256
  getApiHost() {
@@ -418,19 +419,17 @@ class PeerTransfer {
418
419
  }
419
420
  });
420
421
  conn.on('error', (err) => __awaiter(this, void 0, void 0, function* () {
421
- var _a;
422
422
  this.removeConnection(conn.peer, conn.connectionId);
423
- if (!((_a = this.peer) === null || _a === void 0 ? void 0 : _a.open)) {
424
- yield this.reconnect();
425
- }
423
+ // if (!this.peer?.open) {
424
+ // await this.reconnect();
425
+ // }
426
426
  done(null);
427
427
  }));
428
428
  conn.on('close', () => __awaiter(this, void 0, void 0, function* () {
429
- var _a;
430
429
  this.removeConnection(conn.peer, conn.connectionId);
431
- if (!((_a = this.peer) === null || _a === void 0 ? void 0 : _a.open)) {
432
- yield this.reconnect();
433
- }
430
+ // if (!this.peer?.open) {
431
+ // await this.reconnect();
432
+ // }
434
433
  done(null);
435
434
  }));
436
435
  conn.on('open', () => __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egos-transfer",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "1234",
5
5
  "homepage": "https://github.com/superbogy/peer-transfer#readme",
6
6
  "bugs": {
package/src/index.ts CHANGED
@@ -161,7 +161,7 @@ export abstract class PeerTransfer {
161
161
  return this.reconnect();
162
162
  }
163
163
  done(null);
164
- return this.reconnect();
164
+ return this.createPeer(true);
165
165
  });
166
166
  });
167
167
  peer.on('connection', (conn: DataConnection) => {
@@ -272,28 +272,28 @@ export abstract class PeerTransfer {
272
272
 
273
273
  checkConnection() {
274
274
  if (this.checkerId) {
275
- return;
275
+ clearInterval(this.checkerId);
276
276
  }
277
277
  this.checkerId = setInterval(async () => {
278
278
  if (!this.peer?.open) {
279
279
  await this.reconnect();
280
280
  }
281
281
  // turn credential expires
282
- if (this.peerConfig.turnExpiredAt && Date.now() - 30000 > this.peerConfig.turnExpiredAt) {
282
+ if (this.peerConfig.turnExpiredAt && this.peerConfig.turnExpiredAt - 30000 < Date.now()) {
283
283
  // this.connectPool.clear();
284
+ await this.reloadConfig();
284
285
  await this.createPeer(true);
285
286
  return;
286
287
  }
287
- // const deviceIds = this.connectPool.keys();
288
- // for (const deviceId of deviceIds) {
289
- // const conn = this.connectPool.get(deviceId);
290
- // if (!this.isValidConnection(conn)) {
291
- // this.removeConnection(conn.peer);
292
- // this.peer?._removeConnection(conn);
293
- // } else {
294
- // this.ping(conn.peer);
295
- // }
296
- // }
288
+ const deviceIds = this.connectPool.keys();
289
+ for (const deviceId of deviceIds) {
290
+ const conn = this.connectPool.get(deviceId);
291
+ if (!this.isValidConnection(conn)) {
292
+ this.removeConnection(conn.peer);
293
+ } else {
294
+ this.ping(conn.peer);
295
+ }
296
+ }
297
297
  }, HEARTBEAT_INTERVAL);
298
298
  }
299
299
 
@@ -457,14 +457,14 @@ export abstract class PeerTransfer {
457
457
  }
458
458
  });
459
459
  conn.on('error', async (err) => {
460
- // this.removeConnection(conn.peer, conn.connectionId);
460
+ this.removeConnection(conn.peer, conn.connectionId);
461
461
  // if (!this.peer?.open) {
462
462
  // await this.reconnect();
463
463
  // }
464
464
  done(null);
465
465
  });
466
466
  conn.on('close', async () => {
467
- // this.removeConnection(conn.peer, conn.connectionId);
467
+ this.removeConnection(conn.peer, conn.connectionId);
468
468
  // if (!this.peer?.open) {
469
469
  // await this.reconnect();
470
470
  // }