egos-transfer 0.2.0 → 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 +17 -7
- package/package.json +1 -1
- package/src/index.ts +17 -7
package/dist/index.js
CHANGED
|
@@ -49,7 +49,7 @@ class PeerTransfer {
|
|
|
49
49
|
createPeer() {
|
|
50
50
|
return __awaiter(this, arguments, void 0, function* (force = false) {
|
|
51
51
|
var _a;
|
|
52
|
-
if (this.isPaused) {
|
|
52
|
+
if (this.isPaused && !force) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
if (this.booted) {
|
|
@@ -77,7 +77,6 @@ class PeerTransfer {
|
|
|
77
77
|
if (this.booted) {
|
|
78
78
|
return this.booted;
|
|
79
79
|
}
|
|
80
|
-
console.log('create peer@@@', Date.now());
|
|
81
80
|
this.booted = new Promise((resolve) => {
|
|
82
81
|
const timer = setTimeout(() => {
|
|
83
82
|
resolve(null);
|
|
@@ -207,7 +206,7 @@ class PeerTransfer {
|
|
|
207
206
|
}
|
|
208
207
|
removeConnection(peerId, connectionId) {
|
|
209
208
|
var _a, _b, _c;
|
|
210
|
-
// console.
|
|
209
|
+
// console.trace('removeConnection@', peerId, connectionId);
|
|
211
210
|
const conn = this.connectPool.get(peerId);
|
|
212
211
|
if (conn) {
|
|
213
212
|
if (connectionId && conn.connectionId !== connectionId) {
|
|
@@ -301,7 +300,7 @@ class PeerTransfer {
|
|
|
301
300
|
}
|
|
302
301
|
const peerId = deviceId;
|
|
303
302
|
const existingConn = this.connectPool.get(peerId);
|
|
304
|
-
console.log('connectToPeer',
|
|
303
|
+
console.log('connectToPeer', this.isPaused, this.connectPool.size);
|
|
305
304
|
if (existingConn) {
|
|
306
305
|
if (this.isValidConnection(existingConn)) {
|
|
307
306
|
return existingConn;
|
|
@@ -415,15 +414,19 @@ class PeerTransfer {
|
|
|
415
414
|
this.removeConnection(exists.peer, exists.connectionId);
|
|
416
415
|
}
|
|
417
416
|
}
|
|
417
|
+
let timer = null;
|
|
418
418
|
return new Promise((resolve) => {
|
|
419
419
|
const done = (connection) => {
|
|
420
420
|
if (connection) {
|
|
421
421
|
this.addConnection(connection);
|
|
422
422
|
}
|
|
423
|
-
|
|
423
|
+
if (timer) {
|
|
424
|
+
clearTimeout(timer);
|
|
425
|
+
timer = null;
|
|
426
|
+
}
|
|
424
427
|
resolve(connection);
|
|
425
428
|
};
|
|
426
|
-
|
|
429
|
+
timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
427
430
|
if (this.isValidConnection(conn)) {
|
|
428
431
|
this.addConnection(conn);
|
|
429
432
|
done(conn);
|
|
@@ -432,6 +435,7 @@ class PeerTransfer {
|
|
|
432
435
|
this.removeConnection(conn.peer, conn.connectionId);
|
|
433
436
|
done(undefined);
|
|
434
437
|
}
|
|
438
|
+
timer = null;
|
|
435
439
|
}), constant_1.CONNECTION_TIMEOUT);
|
|
436
440
|
conn.on('data', (message) => {
|
|
437
441
|
switch (message.scope) {
|
|
@@ -464,6 +468,10 @@ class PeerTransfer {
|
|
|
464
468
|
done(conn);
|
|
465
469
|
}));
|
|
466
470
|
if (this.isValidConnection(conn)) {
|
|
471
|
+
if (timer) {
|
|
472
|
+
clearTimeout(timer);
|
|
473
|
+
}
|
|
474
|
+
timer = null;
|
|
467
475
|
done(conn);
|
|
468
476
|
}
|
|
469
477
|
});
|
|
@@ -617,6 +625,8 @@ class PeerTransfer {
|
|
|
617
625
|
onRequest(conn, message) {
|
|
618
626
|
return __awaiter(this, void 0, void 0, function* () {
|
|
619
627
|
try {
|
|
628
|
+
// @todo default folder
|
|
629
|
+
// console.log('onRequest-->', message.route);
|
|
620
630
|
// @todo default folder
|
|
621
631
|
yield this.router.run(conn, message);
|
|
622
632
|
}
|
|
@@ -671,7 +681,7 @@ class PeerTransfer {
|
|
|
671
681
|
}
|
|
672
682
|
resume() {
|
|
673
683
|
this.isPaused = false;
|
|
674
|
-
return this.createPeer();
|
|
684
|
+
return this.createPeer(true);
|
|
675
685
|
}
|
|
676
686
|
}
|
|
677
687
|
exports.PeerTransfer = PeerTransfer;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -89,7 +89,7 @@ export abstract class PeerTransfer {
|
|
|
89
89
|
abstract reloadConfig(config?: Record<string, any>): Promise<void>;
|
|
90
90
|
|
|
91
91
|
async createPeer(force = false): Promise<Peer | undefined> {
|
|
92
|
-
if (this.isPaused) {
|
|
92
|
+
if (this.isPaused && !force) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
if (this.booted) {
|
|
@@ -119,7 +119,6 @@ export abstract class PeerTransfer {
|
|
|
119
119
|
if (this.booted) {
|
|
120
120
|
return this.booted;
|
|
121
121
|
}
|
|
122
|
-
console.log('create peer@@@', Date.now());
|
|
123
122
|
this.booted = new Promise((resolve) => {
|
|
124
123
|
const timer = setTimeout(() => {
|
|
125
124
|
resolve(null);
|
|
@@ -249,7 +248,7 @@ export abstract class PeerTransfer {
|
|
|
249
248
|
}
|
|
250
249
|
|
|
251
250
|
removeConnection(peerId: string, connectionId?: string) {
|
|
252
|
-
// console.
|
|
251
|
+
// console.trace('removeConnection@', peerId, connectionId);
|
|
253
252
|
const conn = this.connectPool.get(peerId);
|
|
254
253
|
if (conn) {
|
|
255
254
|
if (connectionId && conn.connectionId !== connectionId) {
|
|
@@ -341,7 +340,7 @@ export abstract class PeerTransfer {
|
|
|
341
340
|
|
|
342
341
|
const peerId = deviceId;
|
|
343
342
|
const existingConn = this.connectPool.get(peerId);
|
|
344
|
-
console.log('connectToPeer',
|
|
343
|
+
console.log('connectToPeer', this.isPaused, this.connectPool.size);
|
|
345
344
|
if (existingConn) {
|
|
346
345
|
if (this.isValidConnection(existingConn)) {
|
|
347
346
|
return existingConn;
|
|
@@ -452,15 +451,19 @@ export abstract class PeerTransfer {
|
|
|
452
451
|
this.removeConnection(exists.peer, exists.connectionId);
|
|
453
452
|
}
|
|
454
453
|
}
|
|
454
|
+
let timer = null;
|
|
455
455
|
return new Promise((resolve) => {
|
|
456
456
|
const done = (connection?: DataConnection) => {
|
|
457
457
|
if (connection) {
|
|
458
458
|
this.addConnection(connection);
|
|
459
459
|
}
|
|
460
|
-
|
|
460
|
+
if (timer) {
|
|
461
|
+
clearTimeout(timer);
|
|
462
|
+
timer = null;
|
|
463
|
+
}
|
|
461
464
|
resolve(connection);
|
|
462
465
|
};
|
|
463
|
-
|
|
466
|
+
timer = setTimeout(async () => {
|
|
464
467
|
if (this.isValidConnection(conn)) {
|
|
465
468
|
this.addConnection(conn);
|
|
466
469
|
done(conn);
|
|
@@ -468,6 +471,7 @@ export abstract class PeerTransfer {
|
|
|
468
471
|
this.removeConnection(conn.peer, conn.connectionId);
|
|
469
472
|
done(undefined);
|
|
470
473
|
}
|
|
474
|
+
timer = null;
|
|
471
475
|
}, CONNECTION_TIMEOUT);
|
|
472
476
|
conn.on('data', (message: any) => {
|
|
473
477
|
switch (message.scope) {
|
|
@@ -500,6 +504,10 @@ export abstract class PeerTransfer {
|
|
|
500
504
|
done(conn);
|
|
501
505
|
});
|
|
502
506
|
if (this.isValidConnection(conn)) {
|
|
507
|
+
if (timer) {
|
|
508
|
+
clearTimeout(timer);
|
|
509
|
+
}
|
|
510
|
+
timer = null;
|
|
503
511
|
done(conn);
|
|
504
512
|
}
|
|
505
513
|
});
|
|
@@ -689,6 +697,8 @@ export abstract class PeerTransfer {
|
|
|
689
697
|
|
|
690
698
|
async onRequest(conn: DataConnection, message: PeerMessage) {
|
|
691
699
|
try {
|
|
700
|
+
// @todo default folder
|
|
701
|
+
// console.log('onRequest-->', message.route);
|
|
692
702
|
// @todo default folder
|
|
693
703
|
await this.router.run(conn, message);
|
|
694
704
|
} catch (err: any) {
|
|
@@ -747,7 +757,7 @@ export abstract class PeerTransfer {
|
|
|
747
757
|
|
|
748
758
|
resume() {
|
|
749
759
|
this.isPaused = false;
|
|
750
|
-
return this.createPeer();
|
|
760
|
+
return this.createPeer(true);
|
|
751
761
|
}
|
|
752
762
|
}
|
|
753
763
|
|