egos-transfer 0.2.1 → 0.2.2
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 +12 -3
- package/package.json +1 -1
- package/src/index.ts +12 -3
package/dist/index.js
CHANGED
|
@@ -206,7 +206,7 @@ class PeerTransfer {
|
|
|
206
206
|
}
|
|
207
207
|
removeConnection(peerId, connectionId) {
|
|
208
208
|
var _a, _b, _c;
|
|
209
|
-
// console.
|
|
209
|
+
// console.trace('removeConnection@', peerId, connectionId);
|
|
210
210
|
const conn = this.connectPool.get(peerId);
|
|
211
211
|
if (conn) {
|
|
212
212
|
if (connectionId && conn.connectionId !== connectionId) {
|
|
@@ -414,15 +414,19 @@ class PeerTransfer {
|
|
|
414
414
|
this.removeConnection(exists.peer, exists.connectionId);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
+
let timer = null;
|
|
417
418
|
return new Promise((resolve) => {
|
|
418
419
|
const done = (connection) => {
|
|
419
420
|
if (connection) {
|
|
420
421
|
this.addConnection(connection);
|
|
421
422
|
}
|
|
422
|
-
|
|
423
|
+
if (timer) {
|
|
424
|
+
clearTimeout(timer);
|
|
425
|
+
timer = null;
|
|
426
|
+
}
|
|
423
427
|
resolve(connection);
|
|
424
428
|
};
|
|
425
|
-
|
|
429
|
+
timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
426
430
|
if (this.isValidConnection(conn)) {
|
|
427
431
|
this.addConnection(conn);
|
|
428
432
|
done(conn);
|
|
@@ -431,6 +435,7 @@ class PeerTransfer {
|
|
|
431
435
|
this.removeConnection(conn.peer, conn.connectionId);
|
|
432
436
|
done(undefined);
|
|
433
437
|
}
|
|
438
|
+
timer = null;
|
|
434
439
|
}), constant_1.CONNECTION_TIMEOUT);
|
|
435
440
|
conn.on('data', (message) => {
|
|
436
441
|
switch (message.scope) {
|
|
@@ -463,6 +468,10 @@ class PeerTransfer {
|
|
|
463
468
|
done(conn);
|
|
464
469
|
}));
|
|
465
470
|
if (this.isValidConnection(conn)) {
|
|
471
|
+
if (timer) {
|
|
472
|
+
clearTimeout(timer);
|
|
473
|
+
}
|
|
474
|
+
timer = null;
|
|
466
475
|
done(conn);
|
|
467
476
|
}
|
|
468
477
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -248,7 +248,7 @@ export abstract class PeerTransfer {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
removeConnection(peerId: string, connectionId?: string) {
|
|
251
|
-
// console.
|
|
251
|
+
// console.trace('removeConnection@', peerId, connectionId);
|
|
252
252
|
const conn = this.connectPool.get(peerId);
|
|
253
253
|
if (conn) {
|
|
254
254
|
if (connectionId && conn.connectionId !== connectionId) {
|
|
@@ -451,15 +451,19 @@ export abstract class PeerTransfer {
|
|
|
451
451
|
this.removeConnection(exists.peer, exists.connectionId);
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
|
+
let timer = null;
|
|
454
455
|
return new Promise((resolve) => {
|
|
455
456
|
const done = (connection?: DataConnection) => {
|
|
456
457
|
if (connection) {
|
|
457
458
|
this.addConnection(connection);
|
|
458
459
|
}
|
|
459
|
-
|
|
460
|
+
if (timer) {
|
|
461
|
+
clearTimeout(timer);
|
|
462
|
+
timer = null;
|
|
463
|
+
}
|
|
460
464
|
resolve(connection);
|
|
461
465
|
};
|
|
462
|
-
|
|
466
|
+
timer = setTimeout(async () => {
|
|
463
467
|
if (this.isValidConnection(conn)) {
|
|
464
468
|
this.addConnection(conn);
|
|
465
469
|
done(conn);
|
|
@@ -467,6 +471,7 @@ export abstract class PeerTransfer {
|
|
|
467
471
|
this.removeConnection(conn.peer, conn.connectionId);
|
|
468
472
|
done(undefined);
|
|
469
473
|
}
|
|
474
|
+
timer = null;
|
|
470
475
|
}, CONNECTION_TIMEOUT);
|
|
471
476
|
conn.on('data', (message: any) => {
|
|
472
477
|
switch (message.scope) {
|
|
@@ -499,6 +504,10 @@ export abstract class PeerTransfer {
|
|
|
499
504
|
done(conn);
|
|
500
505
|
});
|
|
501
506
|
if (this.isValidConnection(conn)) {
|
|
507
|
+
if (timer) {
|
|
508
|
+
clearTimeout(timer);
|
|
509
|
+
}
|
|
510
|
+
timer = null;
|
|
502
511
|
done(conn);
|
|
503
512
|
}
|
|
504
513
|
});
|