egos-transfer 0.2.4 → 0.2.6
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/.claude/settings.local.json +7 -0
- package/dist/index.d.ts +19 -58
- package/dist/index.js +285 -577
- package/package.json +1 -1
- package/src/connection-manager.ts +223 -0
- package/src/file-transfer.ts +0 -1
- package/src/index.ts +2 -924
- package/src/interfaces.ts +7 -0
- package/src/peer-transfer.ts +671 -0
- package/src/server.ts +0 -5
package/dist/index.d.ts
CHANGED
|
@@ -13,31 +13,17 @@ type PeerTransferOptions = PeerOptions & {
|
|
|
13
13
|
export declare abstract class PeerTransfer {
|
|
14
14
|
protected peer: Peer | undefined;
|
|
15
15
|
protected connectPool: Map<string, DataConnection>;
|
|
16
|
-
static connecting: Map<string, {
|
|
17
|
-
promise: Promise<any>;
|
|
18
|
-
resolve: (value: any | PromiseLike<any>) => void;
|
|
19
|
-
reject: (reason?: any) => void;
|
|
20
|
-
}>;
|
|
21
16
|
protected peerConfig: PeerTransferOptions | undefined;
|
|
22
17
|
readonly deviceId: string;
|
|
23
|
-
/** 接入 peerjs 服务端的 peerId,默认与 deviceId 相同 */
|
|
24
18
|
readonly peerId: string;
|
|
25
|
-
protected requests: Map<string, ResponseCb
|
|
26
|
-
/** 追踪 addRequest 的延时清理定时器,避免重试时误删新回调 */
|
|
27
|
-
protected requestTimers: Map<string, ReturnType<typeof setTimeout>>;
|
|
28
|
-
protected timeout: number;
|
|
19
|
+
protected requests: Map<string, ResponseCb<any>>;
|
|
29
20
|
protected router: PeerRouter;
|
|
30
|
-
protected booted: Promise<Peer | undefined> | undefined;
|
|
31
|
-
protected reconnectingPromise: Promise<Peer | undefined> | undefined;
|
|
32
|
-
protected checkerId: ReturnType<typeof setInterval> | null;
|
|
33
|
-
isPaused: boolean;
|
|
34
|
-
/** 重连尝试次数,成功连接后归零 */
|
|
35
21
|
protected reconnectAttempt: number;
|
|
36
|
-
/** 标记实例已销毁,防止异步操作继续 */
|
|
37
22
|
protected destroyed: boolean;
|
|
38
|
-
/**
|
|
39
|
-
private
|
|
40
|
-
|
|
23
|
+
/** connectionId → Set<requestId> — settle in-flight requests on connection drop */
|
|
24
|
+
private connRequests;
|
|
25
|
+
private _reconnecting;
|
|
26
|
+
constructor(deviceId: string, config: PeerTransferOptions);
|
|
41
27
|
abstract getStore(): any;
|
|
42
28
|
abstract online(deviceId: string): void;
|
|
43
29
|
abstract offline(deviceId: string): void;
|
|
@@ -48,42 +34,18 @@ export declare abstract class PeerTransfer {
|
|
|
48
34
|
abstract requireAuth(): Promise<void>;
|
|
49
35
|
abstract onConnectLimit(): void;
|
|
50
36
|
abstract reloadConfig(config?: Record<string, any>): Promise<void>;
|
|
51
|
-
createPeer(
|
|
52
|
-
|
|
37
|
+
createPeer(): Promise<Peer>;
|
|
38
|
+
private waitForOpen;
|
|
53
39
|
handleSocketMessage(message: IMessage): void;
|
|
54
|
-
onHeartbeat(message: IMessage): void;
|
|
55
|
-
onError(message: IMessage): void;
|
|
56
|
-
onOpen(message: IMessage): void;
|
|
57
|
-
onDeviceOnline(message: IMessage): Promise<void>;
|
|
58
|
-
onDeviceOffline(message: IMessage): void;
|
|
59
|
-
removeConnection(peerId: string, connectionId?: string): void;
|
|
60
|
-
/**
|
|
61
|
-
* 连接关闭时尝试快速重连(5s 超时):
|
|
62
|
-
* - 重连成功 → 保留 inRequest 条目,更新 conn 引用
|
|
63
|
-
* - 重连失败 → 触发 feedback 并清理 inRequest
|
|
64
|
-
*/
|
|
65
|
-
private handleConnectionClose;
|
|
66
|
-
addConnection(conn: DataConnection): void;
|
|
67
|
-
checkConnection(): void;
|
|
68
|
-
getApiHost(): string;
|
|
69
|
-
getDeviceStatus(peerId: string): Promise<IDeviceStatus | undefined>;
|
|
70
40
|
connectToPeer(peerId: string): Promise<DataConnection | undefined>;
|
|
71
41
|
private createConnection;
|
|
72
|
-
/**
|
|
73
|
-
* 心跳检测 - 直接 send,不走 request 管线,避免重试放大
|
|
74
|
-
*/
|
|
75
|
-
ping(peerId: string): Promise<boolean>;
|
|
76
42
|
onConnect(conn: DataConnection): Promise<DataConnection | undefined>;
|
|
77
|
-
|
|
43
|
+
private setupConnection;
|
|
44
|
+
private onConnClosed;
|
|
45
|
+
removeConnection(peerId: string, connectionId?: string): void;
|
|
46
|
+
isValidConnection(conn?: DataConnection): boolean;
|
|
78
47
|
private bindConnectionData;
|
|
79
48
|
request(peerId: string, payload: PeerRequestPayload): Promise<PeerMessage>;
|
|
80
|
-
/**
|
|
81
|
-
* 执行一次请求,返回带错误码的结果供外层判断是否重试
|
|
82
|
-
* @param peerId - 目标 peerId
|
|
83
|
-
* @param payload - 请求负载
|
|
84
|
-
* @param requestId - 请求ID(重试时复用)
|
|
85
|
-
* @returns error.code: CONN_CLOSED/CONN_FAILED(可重试)、TIMEOUT(不重试)
|
|
86
|
-
*/
|
|
87
49
|
private doRequestOnce;
|
|
88
50
|
reply(conn: DataConnection, oldMessage: PeerMessage, message: {
|
|
89
51
|
body?: Record<string, any>;
|
|
@@ -91,6 +53,10 @@ export declare abstract class PeerTransfer {
|
|
|
91
53
|
error?: string | Record<string, any>;
|
|
92
54
|
}): Promise<void>;
|
|
93
55
|
send(conn: DataConnection, message: PeerRequestPayload): Promise<void>;
|
|
56
|
+
ping(peerId: string): Promise<boolean>;
|
|
57
|
+
getApiHost(): string;
|
|
58
|
+
getDeviceStatus(peerId: string): Promise<IDeviceStatus | undefined>;
|
|
59
|
+
reconnect(): Promise<Peer | undefined>;
|
|
94
60
|
inheritMessage(receiveMsg: PeerMessage): {
|
|
95
61
|
src: string;
|
|
96
62
|
id: string;
|
|
@@ -99,20 +65,15 @@ export declare abstract class PeerTransfer {
|
|
|
99
65
|
createdAt: string | number;
|
|
100
66
|
action: PeerAction;
|
|
101
67
|
};
|
|
102
|
-
reconnect(): Promise<Peer | undefined>;
|
|
103
|
-
isValidConnection(conn: DataConnection): boolean;
|
|
104
|
-
private doReconnect;
|
|
105
|
-
clearInstance(): void;
|
|
106
|
-
destroy(): void;
|
|
107
68
|
onRequest(conn: DataConnection, message: PeerMessage): Promise<void>;
|
|
108
|
-
onResponse(
|
|
69
|
+
onResponse(_conn: DataConnection, message: PeerMessage): Promise<void>;
|
|
109
70
|
responseOk(conn: DataConnection, message: PeerMessage): Promise<void>;
|
|
110
71
|
responseFail(conn: DataConnection, message: PeerMessage, err: string | Record<string, any>): Promise<void>;
|
|
111
|
-
addRequest(id: string, cb: ResponseCb): void;
|
|
112
72
|
use(handler: RequestCallbackFn, prefix?: string): void;
|
|
113
73
|
addRoute(route: Omit<RouteItem, 'scope'>): void;
|
|
114
|
-
|
|
115
|
-
|
|
74
|
+
clearInstance(): void;
|
|
75
|
+
destroy(): void;
|
|
76
|
+
private destroyPeer;
|
|
116
77
|
}
|
|
117
78
|
export * from './interfaces';
|
|
118
79
|
export * from './handler';
|