egos-transfer 0.1.1 → 0.1.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/constant.d.ts +1 -1
- package/dist/constant.js +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +7 -0
- package/package.json +1 -1
- package/src/constant.ts +1 -1
- package/src/index.ts +13 -2
package/dist/constant.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare const REQUEST_TIMEOUT = 18000;
|
|
|
2
2
|
export declare const HEARTBEAT_INTERVAL = 12000;
|
|
3
3
|
export declare const TRANSFER_TIMEOUT = 300000;
|
|
4
4
|
export declare const PING_TIMEOUT = 5000;
|
|
5
|
-
export declare const CONNECTION_TIMEOUT =
|
|
5
|
+
export declare const CONNECTION_TIMEOUT = 12000;
|
|
6
6
|
export declare const LOCKER_TIMEOUT = 15000;
|
|
7
7
|
export declare const RECONNECT_TIMEOUT = 5000;
|
|
8
8
|
export declare const PEER_OPEN_TIMEOUT = 15000;
|
package/dist/constant.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.REQUEST_TIMEOUT = 18000;
|
|
|
5
5
|
exports.HEARTBEAT_INTERVAL = 12000;
|
|
6
6
|
exports.TRANSFER_TIMEOUT = 300000;
|
|
7
7
|
exports.PING_TIMEOUT = 5000;
|
|
8
|
-
exports.CONNECTION_TIMEOUT =
|
|
8
|
+
exports.CONNECTION_TIMEOUT = 12000;
|
|
9
9
|
exports.LOCKER_TIMEOUT = 15000;
|
|
10
10
|
exports.RECONNECT_TIMEOUT = 5000;
|
|
11
11
|
exports.PEER_OPEN_TIMEOUT = 15000;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface ContentPayload {
|
|
|
7
7
|
parent: string;
|
|
8
8
|
}
|
|
9
9
|
type ResponseCb<T = any> = (args: T) => void;
|
|
10
|
+
type PeerTransferOptions = PeerOptions & {
|
|
11
|
+
turnExpiredAt: number;
|
|
12
|
+
};
|
|
10
13
|
export declare abstract class PeerTransfer {
|
|
11
14
|
protected peer: Peer | undefined;
|
|
12
15
|
protected peerPool: Map<string, Peer>;
|
|
@@ -18,7 +21,7 @@ export declare abstract class PeerTransfer {
|
|
|
18
21
|
reject: (reason?: any) => void;
|
|
19
22
|
}>;
|
|
20
23
|
protected retry: number;
|
|
21
|
-
protected peerConfig:
|
|
24
|
+
protected peerConfig: PeerTransferOptions | undefined;
|
|
22
25
|
deviceId: string;
|
|
23
26
|
protected requests: Map<string, ResponseCb>;
|
|
24
27
|
protected timeout: number;
|
|
@@ -28,7 +31,7 @@ export declare abstract class PeerTransfer {
|
|
|
28
31
|
protected checkerId: ReturnType<typeof setInterval>;
|
|
29
32
|
isPaused: boolean;
|
|
30
33
|
peerId: string;
|
|
31
|
-
constructor(deviceId: string, config:
|
|
34
|
+
constructor(deviceId: string, config: PeerTransferOptions, isRadomPeerId?: boolean);
|
|
32
35
|
abstract getStore(): any;
|
|
33
36
|
abstract online(deviceId: string): void;
|
|
34
37
|
abstract offline(deviceId: string): void;
|
|
@@ -38,6 +41,7 @@ export declare abstract class PeerTransfer {
|
|
|
38
41
|
abstract onDestroy(): void;
|
|
39
42
|
abstract requireAuth(): Promise<void>;
|
|
40
43
|
abstract onConnectLimit(): void;
|
|
44
|
+
abstract reloadConfig(config?: Record<string, any>): Promise<void>;
|
|
41
45
|
initialize(peer: Peer): Promise<string>;
|
|
42
46
|
handleSocketMessage(message: IMessage): void;
|
|
43
47
|
onHeartbeat(message: IMessage): void;
|
package/dist/index.js
CHANGED
|
@@ -215,6 +215,12 @@ class PeerTransfer {
|
|
|
215
215
|
if (!((_a = this.peer) === null || _a === void 0 ? void 0 : _a.open)) {
|
|
216
216
|
yield this.reconnect();
|
|
217
217
|
}
|
|
218
|
+
// turn credential expires
|
|
219
|
+
if (this.peerConfig.turnExpiredAt && Date.now() - 30000 > this.peerConfig.turnExpiredAt) {
|
|
220
|
+
yield this.createPeer(true);
|
|
221
|
+
this.connectPool.clear();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
218
224
|
const deviceIds = this.connectPool.keys();
|
|
219
225
|
for (const deviceId of deviceIds) {
|
|
220
226
|
const conn = this.connectPool.get(deviceId);
|
|
@@ -535,6 +541,7 @@ class PeerTransfer {
|
|
|
535
541
|
return this.peer;
|
|
536
542
|
}
|
|
537
543
|
this.destroy();
|
|
544
|
+
yield this.reloadConfig();
|
|
538
545
|
const peer = new peerjs_1.Peer(this.peerId, Object.assign(Object.assign({}, this.peerConfig), { pingInterval: 15000 }));
|
|
539
546
|
this.peer = peer;
|
|
540
547
|
if (this.checkerId) {
|
package/package.json
CHANGED
package/src/constant.ts
CHANGED
|
@@ -2,7 +2,7 @@ export const REQUEST_TIMEOUT = 18000;
|
|
|
2
2
|
export const HEARTBEAT_INTERVAL = 12000;
|
|
3
3
|
export const TRANSFER_TIMEOUT = 300000;
|
|
4
4
|
export const PING_TIMEOUT = 5000;
|
|
5
|
-
export const CONNECTION_TIMEOUT =
|
|
5
|
+
export const CONNECTION_TIMEOUT = 12000;
|
|
6
6
|
export const LOCKER_TIMEOUT = 15000;
|
|
7
7
|
export const RECONNECT_TIMEOUT = 5000;
|
|
8
8
|
export const PEER_OPEN_TIMEOUT = 15000;
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,9 @@ export interface ContentPayload {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
type ResponseCb<T = any> = (args: T) => void;
|
|
33
|
+
type PeerTransferOptions = PeerOptions & {
|
|
34
|
+
turnExpiredAt: number; // date time ms
|
|
35
|
+
};
|
|
33
36
|
|
|
34
37
|
export abstract class PeerTransfer {
|
|
35
38
|
protected peer: Peer | undefined;
|
|
@@ -49,7 +52,7 @@ export abstract class PeerTransfer {
|
|
|
49
52
|
|
|
50
53
|
protected retry = 0;
|
|
51
54
|
|
|
52
|
-
protected peerConfig:
|
|
55
|
+
protected peerConfig: PeerTransferOptions | undefined;
|
|
53
56
|
public deviceId: string;
|
|
54
57
|
protected requests: Map<string, ResponseCb>;
|
|
55
58
|
protected timeout: number;
|
|
@@ -60,7 +63,7 @@ export abstract class PeerTransfer {
|
|
|
60
63
|
public isPaused: boolean;
|
|
61
64
|
peerId: string;
|
|
62
65
|
|
|
63
|
-
constructor(deviceId: string, config:
|
|
66
|
+
constructor(deviceId: string, config: PeerTransferOptions, isRadomPeerId = false) {
|
|
64
67
|
this.connectPool = new Map<string, DataConnection>();
|
|
65
68
|
this.peerConfig = {
|
|
66
69
|
...config,
|
|
@@ -84,6 +87,7 @@ export abstract class PeerTransfer {
|
|
|
84
87
|
abstract onDestroy(): void;
|
|
85
88
|
abstract requireAuth(): Promise<void>;
|
|
86
89
|
abstract onConnectLimit(): void;
|
|
90
|
+
abstract reloadConfig(config?: Record<string, any>): Promise<void>;
|
|
87
91
|
async initialize(peer: Peer) {
|
|
88
92
|
try {
|
|
89
93
|
this.booted = new Promise((resolve) => {
|
|
@@ -252,6 +256,12 @@ export abstract class PeerTransfer {
|
|
|
252
256
|
if (!this.peer?.open) {
|
|
253
257
|
await this.reconnect();
|
|
254
258
|
}
|
|
259
|
+
// turn credential expires
|
|
260
|
+
if (this.peerConfig.turnExpiredAt && Date.now() - 30000 > this.peerConfig.turnExpiredAt) {
|
|
261
|
+
await this.createPeer(true);
|
|
262
|
+
this.connectPool.clear();
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
255
265
|
const deviceIds = this.connectPool.keys();
|
|
256
266
|
for (const deviceId of deviceIds) {
|
|
257
267
|
const conn = this.connectPool.get(deviceId);
|
|
@@ -594,6 +604,7 @@ export abstract class PeerTransfer {
|
|
|
594
604
|
}
|
|
595
605
|
|
|
596
606
|
this.destroy();
|
|
607
|
+
await this.reloadConfig();
|
|
597
608
|
const peer = new Peer(this.peerId, {
|
|
598
609
|
...this.peerConfig,
|
|
599
610
|
pingInterval: 15000,
|