@pisell/core 0.0.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/README.md +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +63 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +101 -0
- package/lib/app/app.js +171 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +69 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +49 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Socket } from './socket';
|
|
2
|
+
import { SocketMessage, SocketStatus } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Socket历史消息记录项
|
|
5
|
+
*/
|
|
6
|
+
export interface SocketHistoryItem {
|
|
7
|
+
/** 消息ID */
|
|
8
|
+
id: string;
|
|
9
|
+
/** 消息时间戳 */
|
|
10
|
+
timestamp: number;
|
|
11
|
+
/** 消息方向(发送/接收) */
|
|
12
|
+
direction: 'in' | 'out';
|
|
13
|
+
/** 消息内容 */
|
|
14
|
+
message: SocketMessage;
|
|
15
|
+
/** 消息大小(字节) */
|
|
16
|
+
size?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Socket状态记录项
|
|
20
|
+
*/
|
|
21
|
+
export interface SocketStatusItem {
|
|
22
|
+
/** 状态变更时间戳 */
|
|
23
|
+
timestamp: number;
|
|
24
|
+
/** 变更前状态 */
|
|
25
|
+
from: SocketStatus;
|
|
26
|
+
/** 变更后状态 */
|
|
27
|
+
to: SocketStatus;
|
|
28
|
+
/** 相关事件(如果有) */
|
|
29
|
+
event?: string;
|
|
30
|
+
/** 附加信息 */
|
|
31
|
+
info?: any;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Socket监控配置选项
|
|
35
|
+
*/
|
|
36
|
+
export interface SocketMonitorOptions {
|
|
37
|
+
/** 最大历史消息记录数 */
|
|
38
|
+
maxHistoryItems?: number;
|
|
39
|
+
/** 最大状态变更记录数 */
|
|
40
|
+
maxStatusItems?: number;
|
|
41
|
+
/** 是否记录消息内容 */
|
|
42
|
+
recordMessageContent?: boolean;
|
|
43
|
+
/** 是否自动开始监控 */
|
|
44
|
+
autoStart?: boolean;
|
|
45
|
+
/** 过滤掉的消息类型(不记录) */
|
|
46
|
+
excludeEvents?: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Socket监控统计信息
|
|
50
|
+
*/
|
|
51
|
+
export interface SocketStats {
|
|
52
|
+
/** 总发送消息数 */
|
|
53
|
+
totalSent: number;
|
|
54
|
+
/** 总接收消息数 */
|
|
55
|
+
totalReceived: number;
|
|
56
|
+
/** 总发送字节数 */
|
|
57
|
+
bytesSent: number;
|
|
58
|
+
/** 总接收字节数 */
|
|
59
|
+
bytesReceived: number;
|
|
60
|
+
/** 连接次数 */
|
|
61
|
+
connectionCount: number;
|
|
62
|
+
/** 重连次数 */
|
|
63
|
+
reconnectionCount: number;
|
|
64
|
+
/** 错误次数 */
|
|
65
|
+
errorCount: number;
|
|
66
|
+
/** 心跳发送次数 */
|
|
67
|
+
heartbeatCount: number;
|
|
68
|
+
/** 心跳超时次数 */
|
|
69
|
+
heartbeatTimeoutCount: number;
|
|
70
|
+
/** 首次连接时间 */
|
|
71
|
+
firstConnectTime: number | null;
|
|
72
|
+
/** 最后连接时间 */
|
|
73
|
+
lastConnectTime: number | null;
|
|
74
|
+
/** 当前连接持续时间(毫秒,连接状态下有效) */
|
|
75
|
+
currentConnectionDuration: number | null;
|
|
76
|
+
/** 平均消息大小(字节) */
|
|
77
|
+
averageMessageSize: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Socket监控器
|
|
81
|
+
* 用于监控Socket的连接状态和消息历史
|
|
82
|
+
*/
|
|
83
|
+
export declare class SocketMonitor {
|
|
84
|
+
private socket;
|
|
85
|
+
private options;
|
|
86
|
+
private isMonitoring;
|
|
87
|
+
private messageHistory;
|
|
88
|
+
private statusHistory;
|
|
89
|
+
private stats;
|
|
90
|
+
private connectStartTime;
|
|
91
|
+
private eventHandlers;
|
|
92
|
+
/**
|
|
93
|
+
* 创建Socket监控器
|
|
94
|
+
* @param socket 要监控的Socket实例
|
|
95
|
+
* @param options 监控配置选项
|
|
96
|
+
*/
|
|
97
|
+
constructor(socket: Socket, options?: SocketMonitorOptions);
|
|
98
|
+
/**
|
|
99
|
+
* 开始监控
|
|
100
|
+
*/
|
|
101
|
+
start(): void;
|
|
102
|
+
/**
|
|
103
|
+
* 停止监控
|
|
104
|
+
*/
|
|
105
|
+
stop(): void;
|
|
106
|
+
/**
|
|
107
|
+
* 检查监控器是否处于活跃状态
|
|
108
|
+
*/
|
|
109
|
+
isActive(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* 清除历史记录
|
|
112
|
+
*/
|
|
113
|
+
clearHistory(): void;
|
|
114
|
+
/**
|
|
115
|
+
* 重置统计数据
|
|
116
|
+
*/
|
|
117
|
+
resetStats(): void;
|
|
118
|
+
/**
|
|
119
|
+
* 获取消息历史记录
|
|
120
|
+
* @param limit 返回的最大记录数
|
|
121
|
+
* @param direction 消息方向过滤
|
|
122
|
+
*/
|
|
123
|
+
getMessageHistory(limit?: number, direction?: 'in' | 'out'): SocketHistoryItem[];
|
|
124
|
+
/**
|
|
125
|
+
* 获取状态变更历史
|
|
126
|
+
* @param limit 返回的最大记录数
|
|
127
|
+
*/
|
|
128
|
+
getStatusHistory(limit?: number): SocketStatusItem[];
|
|
129
|
+
/**
|
|
130
|
+
* 获取统计信息
|
|
131
|
+
*/
|
|
132
|
+
getStats(): SocketStats;
|
|
133
|
+
/**
|
|
134
|
+
* 设置监控事件监听
|
|
135
|
+
*/
|
|
136
|
+
private setupEventListeners;
|
|
137
|
+
/**
|
|
138
|
+
* 移除监控事件监听
|
|
139
|
+
*/
|
|
140
|
+
private removeEventListeners;
|
|
141
|
+
/**
|
|
142
|
+
* 记录已发送的消息
|
|
143
|
+
*/
|
|
144
|
+
private recordMessageSent;
|
|
145
|
+
/**
|
|
146
|
+
* 记录已接收的消息
|
|
147
|
+
*/
|
|
148
|
+
private recordMessageReceived;
|
|
149
|
+
/**
|
|
150
|
+
* 记录状态变化
|
|
151
|
+
*/
|
|
152
|
+
private recordStatusChange;
|
|
153
|
+
/**
|
|
154
|
+
* 添加消息到历史记录,并控制记录数量
|
|
155
|
+
*/
|
|
156
|
+
private addToMessageHistory;
|
|
157
|
+
/**
|
|
158
|
+
* 添加状态到历史记录,并控制记录数量
|
|
159
|
+
*/
|
|
160
|
+
private addToStatusHistory;
|
|
161
|
+
/**
|
|
162
|
+
* 更新平均消息大小
|
|
163
|
+
*/
|
|
164
|
+
private updateAverageMessageSize;
|
|
165
|
+
/**
|
|
166
|
+
* 释放资源
|
|
167
|
+
*/
|
|
168
|
+
destroy(): void;
|
|
169
|
+
}
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
import { SocketEvents } from "./events";
|
|
18
|
+
import { SocketStatus } from "./types";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Socket历史消息记录项
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Socket状态记录项
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Socket监控配置选项
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Socket监控统计信息
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Socket监控器
|
|
38
|
+
* 用于监控Socket的连接状态和消息历史
|
|
39
|
+
*/
|
|
40
|
+
export var SocketMonitor = /*#__PURE__*/function () {
|
|
41
|
+
/**
|
|
42
|
+
* 创建Socket监控器
|
|
43
|
+
* @param socket 要监控的Socket实例
|
|
44
|
+
* @param options 监控配置选项
|
|
45
|
+
*/
|
|
46
|
+
function SocketMonitor(socket) {
|
|
47
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
48
|
+
_classCallCheck(this, SocketMonitor);
|
|
49
|
+
_defineProperty(this, "socket", void 0);
|
|
50
|
+
_defineProperty(this, "options", void 0);
|
|
51
|
+
_defineProperty(this, "isMonitoring", false);
|
|
52
|
+
// 历史记录存储
|
|
53
|
+
_defineProperty(this, "messageHistory", []);
|
|
54
|
+
_defineProperty(this, "statusHistory", []);
|
|
55
|
+
// 统计数据
|
|
56
|
+
_defineProperty(this, "stats", {
|
|
57
|
+
totalSent: 0,
|
|
58
|
+
totalReceived: 0,
|
|
59
|
+
bytesSent: 0,
|
|
60
|
+
bytesReceived: 0,
|
|
61
|
+
connectionCount: 0,
|
|
62
|
+
reconnectionCount: 0,
|
|
63
|
+
errorCount: 0,
|
|
64
|
+
heartbeatCount: 0,
|
|
65
|
+
heartbeatTimeoutCount: 0,
|
|
66
|
+
firstConnectTime: null,
|
|
67
|
+
lastConnectTime: null,
|
|
68
|
+
currentConnectionDuration: null,
|
|
69
|
+
averageMessageSize: 0
|
|
70
|
+
});
|
|
71
|
+
// 用于计算连接持续时间
|
|
72
|
+
_defineProperty(this, "connectStartTime", null);
|
|
73
|
+
// 事件句柄映射
|
|
74
|
+
_defineProperty(this, "eventHandlers", new Map());
|
|
75
|
+
this.socket = socket;
|
|
76
|
+
this.options = _objectSpread({
|
|
77
|
+
maxHistoryItems: 100,
|
|
78
|
+
maxStatusItems: 50,
|
|
79
|
+
recordMessageContent: true,
|
|
80
|
+
autoStart: true,
|
|
81
|
+
excludeEvents: ['ping', 'pong', 'heartbeat']
|
|
82
|
+
}, options);
|
|
83
|
+
if (this.options.autoStart) {
|
|
84
|
+
this.start();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 开始监控
|
|
90
|
+
*/
|
|
91
|
+
_createClass(SocketMonitor, [{
|
|
92
|
+
key: "start",
|
|
93
|
+
value: function start() {
|
|
94
|
+
if (this.isMonitoring) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.isMonitoring = true;
|
|
98
|
+
this.setupEventListeners();
|
|
99
|
+
|
|
100
|
+
// 记录初始状态
|
|
101
|
+
this.recordStatusChange(SocketStatus.CLOSED, this.socket.getStatus());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 停止监控
|
|
106
|
+
*/
|
|
107
|
+
}, {
|
|
108
|
+
key: "stop",
|
|
109
|
+
value: function stop() {
|
|
110
|
+
if (!this.isMonitoring) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.isMonitoring = false;
|
|
114
|
+
this.removeEventListeners();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 检查监控器是否处于活跃状态
|
|
119
|
+
*/
|
|
120
|
+
}, {
|
|
121
|
+
key: "isActive",
|
|
122
|
+
value: function isActive() {
|
|
123
|
+
return this.isMonitoring;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 清除历史记录
|
|
128
|
+
*/
|
|
129
|
+
}, {
|
|
130
|
+
key: "clearHistory",
|
|
131
|
+
value: function clearHistory() {
|
|
132
|
+
this.messageHistory = [];
|
|
133
|
+
this.statusHistory = [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 重置统计数据
|
|
138
|
+
*/
|
|
139
|
+
}, {
|
|
140
|
+
key: "resetStats",
|
|
141
|
+
value: function resetStats() {
|
|
142
|
+
this.stats = {
|
|
143
|
+
totalSent: 0,
|
|
144
|
+
totalReceived: 0,
|
|
145
|
+
bytesSent: 0,
|
|
146
|
+
bytesReceived: 0,
|
|
147
|
+
connectionCount: 0,
|
|
148
|
+
reconnectionCount: 0,
|
|
149
|
+
errorCount: 0,
|
|
150
|
+
heartbeatCount: 0,
|
|
151
|
+
heartbeatTimeoutCount: 0,
|
|
152
|
+
firstConnectTime: null,
|
|
153
|
+
lastConnectTime: null,
|
|
154
|
+
currentConnectionDuration: null,
|
|
155
|
+
averageMessageSize: 0
|
|
156
|
+
};
|
|
157
|
+
this.connectStartTime = null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 获取消息历史记录
|
|
162
|
+
* @param limit 返回的最大记录数
|
|
163
|
+
* @param direction 消息方向过滤
|
|
164
|
+
*/
|
|
165
|
+
}, {
|
|
166
|
+
key: "getMessageHistory",
|
|
167
|
+
value: function getMessageHistory(limit, direction) {
|
|
168
|
+
var history = this.messageHistory;
|
|
169
|
+
if (direction) {
|
|
170
|
+
history = history.filter(function (item) {
|
|
171
|
+
return item.direction === direction;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (limit && limit > 0) {
|
|
175
|
+
history = history.slice(-limit);
|
|
176
|
+
}
|
|
177
|
+
return history;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 获取状态变更历史
|
|
182
|
+
* @param limit 返回的最大记录数
|
|
183
|
+
*/
|
|
184
|
+
}, {
|
|
185
|
+
key: "getStatusHistory",
|
|
186
|
+
value: function getStatusHistory(limit) {
|
|
187
|
+
var history = this.statusHistory;
|
|
188
|
+
if (limit && limit > 0) {
|
|
189
|
+
history = history.slice(-limit);
|
|
190
|
+
}
|
|
191
|
+
return history;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 获取统计信息
|
|
196
|
+
*/
|
|
197
|
+
}, {
|
|
198
|
+
key: "getStats",
|
|
199
|
+
value: function getStats() {
|
|
200
|
+
// 如果当前处于连接状态,更新连接持续时间
|
|
201
|
+
if (this.socket.isConnected() && this.connectStartTime) {
|
|
202
|
+
this.stats.currentConnectionDuration = Date.now() - this.connectStartTime;
|
|
203
|
+
}
|
|
204
|
+
return _objectSpread({}, this.stats);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 设置监控事件监听
|
|
209
|
+
*/
|
|
210
|
+
}, {
|
|
211
|
+
key: "setupEventListeners",
|
|
212
|
+
value: function setupEventListeners() {
|
|
213
|
+
var _this = this;
|
|
214
|
+
// 监听消息发送事件
|
|
215
|
+
var onSend = function onSend(message) {
|
|
216
|
+
_this.recordMessageSent(message);
|
|
217
|
+
};
|
|
218
|
+
this.eventHandlers.set(SocketEvents.SEND, onSend);
|
|
219
|
+
this.socket.on(SocketEvents.SEND, onSend);
|
|
220
|
+
|
|
221
|
+
// 监听消息接收事件
|
|
222
|
+
var onMessage = function onMessage(message) {
|
|
223
|
+
_this.recordMessageReceived(message);
|
|
224
|
+
};
|
|
225
|
+
this.eventHandlers.set(SocketEvents.MESSAGE, onMessage);
|
|
226
|
+
this.socket.on(SocketEvents.MESSAGE, onMessage);
|
|
227
|
+
|
|
228
|
+
// 监听连接事件
|
|
229
|
+
var onConnect = function onConnect() {
|
|
230
|
+
var now = Date.now();
|
|
231
|
+
_this.connectStartTime = now;
|
|
232
|
+
if (!_this.stats.firstConnectTime) {
|
|
233
|
+
_this.stats.firstConnectTime = now;
|
|
234
|
+
}
|
|
235
|
+
_this.stats.lastConnectTime = now;
|
|
236
|
+
_this.stats.connectionCount++;
|
|
237
|
+
_this.recordStatusChange(_this.socket.getStatus() === SocketStatus.RECONNECTING ? SocketStatus.RECONNECTING : SocketStatus.CONNECTING, SocketStatus.OPEN, SocketEvents.CONNECT);
|
|
238
|
+
};
|
|
239
|
+
this.eventHandlers.set(SocketEvents.CONNECT, onConnect);
|
|
240
|
+
this.socket.on(SocketEvents.CONNECT, onConnect);
|
|
241
|
+
|
|
242
|
+
// 监听断开连接事件
|
|
243
|
+
var onDisconnect = function onDisconnect() {
|
|
244
|
+
_this.connectStartTime = null;
|
|
245
|
+
_this.stats.currentConnectionDuration = null;
|
|
246
|
+
_this.recordStatusChange(_this.socket.getStatus() === SocketStatus.CLOSING ? SocketStatus.CLOSING : SocketStatus.OPEN, SocketStatus.CLOSED, SocketEvents.DISCONNECT);
|
|
247
|
+
};
|
|
248
|
+
this.eventHandlers.set(SocketEvents.DISCONNECT, onDisconnect);
|
|
249
|
+
this.socket.on(SocketEvents.DISCONNECT, onDisconnect);
|
|
250
|
+
|
|
251
|
+
// 监听重连事件
|
|
252
|
+
var onReconnect = function onReconnect() {
|
|
253
|
+
_this.stats.reconnectionCount++;
|
|
254
|
+
};
|
|
255
|
+
this.eventHandlers.set(SocketEvents.RECONNECT, onReconnect);
|
|
256
|
+
this.socket.on(SocketEvents.RECONNECT, onReconnect);
|
|
257
|
+
|
|
258
|
+
// 监听重连尝试事件
|
|
259
|
+
var onReconnectAttempt = function onReconnectAttempt() {
|
|
260
|
+
_this.recordStatusChange(SocketStatus.CLOSED, SocketStatus.RECONNECTING, SocketEvents.RECONNECT_ATTEMPT);
|
|
261
|
+
};
|
|
262
|
+
this.eventHandlers.set(SocketEvents.RECONNECT_ATTEMPT, onReconnectAttempt);
|
|
263
|
+
this.socket.on(SocketEvents.RECONNECT_ATTEMPT, onReconnectAttempt);
|
|
264
|
+
|
|
265
|
+
// 监听错误事件
|
|
266
|
+
var onError = function onError(error) {
|
|
267
|
+
_this.stats.errorCount++;
|
|
268
|
+
_this.recordStatusChange(_this.socket.getStatus(), _this.socket.getStatus(), SocketEvents.ERROR, error);
|
|
269
|
+
};
|
|
270
|
+
this.eventHandlers.set(SocketEvents.ERROR, onError);
|
|
271
|
+
this.socket.on(SocketEvents.ERROR, onError);
|
|
272
|
+
|
|
273
|
+
// 监听心跳事件
|
|
274
|
+
var onHeartbeat = function onHeartbeat() {
|
|
275
|
+
_this.stats.heartbeatCount++;
|
|
276
|
+
};
|
|
277
|
+
this.eventHandlers.set(SocketEvents.HEARTBEAT, onHeartbeat);
|
|
278
|
+
this.socket.on(SocketEvents.HEARTBEAT, onHeartbeat);
|
|
279
|
+
|
|
280
|
+
// 监听心跳超时事件
|
|
281
|
+
var onHeartbeatTimeout = function onHeartbeatTimeout() {
|
|
282
|
+
_this.stats.heartbeatTimeoutCount++;
|
|
283
|
+
};
|
|
284
|
+
this.eventHandlers.set(SocketEvents.HEARTBEAT_TIMEOUT, onHeartbeatTimeout);
|
|
285
|
+
this.socket.on(SocketEvents.HEARTBEAT_TIMEOUT, onHeartbeatTimeout);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* 移除监控事件监听
|
|
290
|
+
*/
|
|
291
|
+
}, {
|
|
292
|
+
key: "removeEventListeners",
|
|
293
|
+
value: function removeEventListeners() {
|
|
294
|
+
var _iterator = _createForOfIteratorHelper(this.eventHandlers.entries()),
|
|
295
|
+
_step;
|
|
296
|
+
try {
|
|
297
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
298
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
299
|
+
event = _step$value[0],
|
|
300
|
+
handler = _step$value[1];
|
|
301
|
+
this.socket.off(event, handler);
|
|
302
|
+
}
|
|
303
|
+
} catch (err) {
|
|
304
|
+
_iterator.e(err);
|
|
305
|
+
} finally {
|
|
306
|
+
_iterator.f();
|
|
307
|
+
}
|
|
308
|
+
this.eventHandlers.clear();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 记录已发送的消息
|
|
313
|
+
*/
|
|
314
|
+
}, {
|
|
315
|
+
key: "recordMessageSent",
|
|
316
|
+
value: function recordMessageSent(message) {
|
|
317
|
+
var _this$options$exclude;
|
|
318
|
+
// 如果是排除的事件类型,则不记录
|
|
319
|
+
if ((_this$options$exclude = this.options.excludeEvents) !== null && _this$options$exclude !== void 0 && _this$options$exclude.includes(message.event)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
var messageStr = JSON.stringify(message);
|
|
323
|
+
var size = new Blob([messageStr]).size;
|
|
324
|
+
|
|
325
|
+
// 更新统计数据
|
|
326
|
+
this.stats.totalSent++;
|
|
327
|
+
this.stats.bytesSent += size;
|
|
328
|
+
this.updateAverageMessageSize(size);
|
|
329
|
+
|
|
330
|
+
// 添加到历史记录
|
|
331
|
+
this.addToMessageHistory({
|
|
332
|
+
id: message.id || "out_".concat(Date.now()),
|
|
333
|
+
timestamp: Date.now(),
|
|
334
|
+
direction: 'out',
|
|
335
|
+
//@ts-ignore
|
|
336
|
+
message: this.options.recordMessageContent ? message : {
|
|
337
|
+
event: message.event
|
|
338
|
+
},
|
|
339
|
+
size: size
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 记录已接收的消息
|
|
345
|
+
*/
|
|
346
|
+
}, {
|
|
347
|
+
key: "recordMessageReceived",
|
|
348
|
+
value: function recordMessageReceived(message) {
|
|
349
|
+
var _this$options$exclude2;
|
|
350
|
+
// 如果是排除的事件类型,则不记录
|
|
351
|
+
if ((_this$options$exclude2 = this.options.excludeEvents) !== null && _this$options$exclude2 !== void 0 && _this$options$exclude2.includes(message.event)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
var messageStr = JSON.stringify(message);
|
|
355
|
+
var size = new Blob([messageStr]).size;
|
|
356
|
+
|
|
357
|
+
// 更新统计数据
|
|
358
|
+
this.stats.totalReceived++;
|
|
359
|
+
this.stats.bytesReceived += size;
|
|
360
|
+
this.updateAverageMessageSize(size);
|
|
361
|
+
|
|
362
|
+
// 添加到历史记录
|
|
363
|
+
this.addToMessageHistory({
|
|
364
|
+
id: message.id || "in_".concat(Date.now()),
|
|
365
|
+
timestamp: Date.now(),
|
|
366
|
+
direction: 'in',
|
|
367
|
+
//@ts-ignore
|
|
368
|
+
message: this.options.recordMessageContent ? message : {
|
|
369
|
+
event: message.event
|
|
370
|
+
},
|
|
371
|
+
size: size
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 记录状态变化
|
|
377
|
+
*/
|
|
378
|
+
}, {
|
|
379
|
+
key: "recordStatusChange",
|
|
380
|
+
value: function recordStatusChange(fromStatus, toStatus, event, info) {
|
|
381
|
+
if (fromStatus === toStatus && !event) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
var statusItem = {
|
|
385
|
+
timestamp: Date.now(),
|
|
386
|
+
from: fromStatus,
|
|
387
|
+
to: toStatus,
|
|
388
|
+
event: event,
|
|
389
|
+
info: info
|
|
390
|
+
};
|
|
391
|
+
this.addToStatusHistory(statusItem);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* 添加消息到历史记录,并控制记录数量
|
|
396
|
+
*/
|
|
397
|
+
}, {
|
|
398
|
+
key: "addToMessageHistory",
|
|
399
|
+
value: function addToMessageHistory(item) {
|
|
400
|
+
this.messageHistory.push(item);
|
|
401
|
+
|
|
402
|
+
// 如果超过最大记录数,删除最早的记录
|
|
403
|
+
if (this.messageHistory.length > (this.options.maxHistoryItems || 100)) {
|
|
404
|
+
this.messageHistory.shift();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 添加状态到历史记录,并控制记录数量
|
|
410
|
+
*/
|
|
411
|
+
}, {
|
|
412
|
+
key: "addToStatusHistory",
|
|
413
|
+
value: function addToStatusHistory(item) {
|
|
414
|
+
this.statusHistory.push(item);
|
|
415
|
+
|
|
416
|
+
// 如果超过最大记录数,删除最早的记录
|
|
417
|
+
if (this.statusHistory.length > (this.options.maxStatusItems || 50)) {
|
|
418
|
+
this.statusHistory.shift();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* 更新平均消息大小
|
|
424
|
+
*/
|
|
425
|
+
}, {
|
|
426
|
+
key: "updateAverageMessageSize",
|
|
427
|
+
value: function updateAverageMessageSize(newSize) {
|
|
428
|
+
var totalMessages = this.stats.totalSent + this.stats.totalReceived;
|
|
429
|
+
if (totalMessages <= 1) {
|
|
430
|
+
this.stats.averageMessageSize = newSize;
|
|
431
|
+
} else {
|
|
432
|
+
this.stats.averageMessageSize = (this.stats.averageMessageSize * (totalMessages - 1) + newSize) / totalMessages;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* 释放资源
|
|
438
|
+
*/
|
|
439
|
+
}, {
|
|
440
|
+
key: "destroy",
|
|
441
|
+
value: function destroy() {
|
|
442
|
+
this.stop();
|
|
443
|
+
this.messageHistory = [];
|
|
444
|
+
this.statusHistory = [];
|
|
445
|
+
}
|
|
446
|
+
}]);
|
|
447
|
+
return SocketMonitor;
|
|
448
|
+
}();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ReconnectOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Socket重连管理器
|
|
4
|
+
* 处理断线重连逻辑
|
|
5
|
+
*/
|
|
6
|
+
export declare class ReconnectManager {
|
|
7
|
+
private options;
|
|
8
|
+
private attempts;
|
|
9
|
+
private timer;
|
|
10
|
+
private isReconnecting;
|
|
11
|
+
private reconnectCallback;
|
|
12
|
+
private onAttempt;
|
|
13
|
+
private onSuccess;
|
|
14
|
+
private onFail;
|
|
15
|
+
private onMaxAttemptsExceeded;
|
|
16
|
+
/**
|
|
17
|
+
* 创建重连管理器实例
|
|
18
|
+
* @param options 重连配置
|
|
19
|
+
* @param reconnectCallback 重连执行函数
|
|
20
|
+
* @param callbacks 回调函数集合
|
|
21
|
+
*/
|
|
22
|
+
constructor(options: ReconnectOptions, reconnectCallback: () => Promise<boolean>, callbacks?: {
|
|
23
|
+
onAttempt?: (attempt: number) => void;
|
|
24
|
+
onSuccess?: () => void;
|
|
25
|
+
onFail?: (error: Error) => void;
|
|
26
|
+
onMaxAttemptsExceeded?: () => void;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* 启动重连过程
|
|
30
|
+
*/
|
|
31
|
+
startReconnect(): void;
|
|
32
|
+
/**
|
|
33
|
+
* 停止重连过程
|
|
34
|
+
*/
|
|
35
|
+
stopReconnect(): void;
|
|
36
|
+
/**
|
|
37
|
+
* 获取当前重连尝试次数
|
|
38
|
+
*/
|
|
39
|
+
getReconnectAttempts(): number;
|
|
40
|
+
/**
|
|
41
|
+
* 获取当前是否正在重连
|
|
42
|
+
*/
|
|
43
|
+
isActive(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 重置重连状态
|
|
46
|
+
*/
|
|
47
|
+
reset(): void;
|
|
48
|
+
/**
|
|
49
|
+
* 安排下一次重连尝试
|
|
50
|
+
*/
|
|
51
|
+
private scheduleReconnect;
|
|
52
|
+
/**
|
|
53
|
+
* 执行重连操作
|
|
54
|
+
*/
|
|
55
|
+
private executeReconnect;
|
|
56
|
+
/**
|
|
57
|
+
* 计算重连延迟时间
|
|
58
|
+
* 支持指数退避算法,增加随机抖动
|
|
59
|
+
*/
|
|
60
|
+
private getReconnectDelay;
|
|
61
|
+
}
|