@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,157 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/socket/heartbeat.ts
|
|
20
|
+
var heartbeat_exports = {};
|
|
21
|
+
__export(heartbeat_exports, {
|
|
22
|
+
HeartbeatManager: () => HeartbeatManager
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(heartbeat_exports);
|
|
25
|
+
var import_constants = require("./constants");
|
|
26
|
+
var HeartbeatManager = class {
|
|
27
|
+
options;
|
|
28
|
+
intervalTimer = null;
|
|
29
|
+
timeoutTimer = null;
|
|
30
|
+
lastHeartbeatTime = 0;
|
|
31
|
+
lastHeartbeatResponse = 0;
|
|
32
|
+
active = false;
|
|
33
|
+
// 心跳回调函数
|
|
34
|
+
sendHeartbeat;
|
|
35
|
+
onTimeout;
|
|
36
|
+
onResponse;
|
|
37
|
+
/**
|
|
38
|
+
* 创建心跳管理器
|
|
39
|
+
* @param options 心跳配置选项
|
|
40
|
+
* @param sendHeartbeat 发送心跳的回调函数
|
|
41
|
+
* @param callbacks 回调函数集合
|
|
42
|
+
*/
|
|
43
|
+
constructor(options, sendHeartbeat, callbacks = {}) {
|
|
44
|
+
this.options = {
|
|
45
|
+
...options,
|
|
46
|
+
interval: Math.max(options.interval, import_constants.MIN_HEARTBEAT_INTERVAL),
|
|
47
|
+
message: options.message || import_constants.DEFAULT_HEARTBEAT_MESSAGE
|
|
48
|
+
};
|
|
49
|
+
this.sendHeartbeat = sendHeartbeat;
|
|
50
|
+
this.onTimeout = callbacks.onTimeout || (() => {
|
|
51
|
+
});
|
|
52
|
+
this.onResponse = callbacks.onResponse || (() => {
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 启动心跳检测
|
|
57
|
+
*/
|
|
58
|
+
start() {
|
|
59
|
+
if (this.active) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.active = true;
|
|
63
|
+
this.scheduleHeartbeat();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 停止心跳检测
|
|
67
|
+
*/
|
|
68
|
+
stop() {
|
|
69
|
+
this.active = false;
|
|
70
|
+
this.clearTimers();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 重启心跳检测
|
|
74
|
+
*/
|
|
75
|
+
restart() {
|
|
76
|
+
this.stop();
|
|
77
|
+
this.start();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 接收到心跳响应
|
|
81
|
+
*/
|
|
82
|
+
receiveHeartbeatResponse() {
|
|
83
|
+
this.lastHeartbeatResponse = Date.now();
|
|
84
|
+
if (this.timeoutTimer) {
|
|
85
|
+
clearTimeout(this.timeoutTimer);
|
|
86
|
+
this.timeoutTimer = null;
|
|
87
|
+
}
|
|
88
|
+
this.onResponse();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 获取上次心跳时间
|
|
92
|
+
*/
|
|
93
|
+
getLastHeartbeatTime() {
|
|
94
|
+
return this.lastHeartbeatTime;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 获取上次心跳响应时间
|
|
98
|
+
*/
|
|
99
|
+
getLastHeartbeatResponseTime() {
|
|
100
|
+
return this.lastHeartbeatResponse;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 获取心跳是否活跃
|
|
104
|
+
*/
|
|
105
|
+
isActive() {
|
|
106
|
+
return this.active;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 安排下一次心跳
|
|
110
|
+
*/
|
|
111
|
+
scheduleHeartbeat() {
|
|
112
|
+
if (!this.active) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.clearTimers();
|
|
116
|
+
this.intervalTimer = setInterval(() => {
|
|
117
|
+
this.sendHeartbeatMessage();
|
|
118
|
+
}, this.options.interval);
|
|
119
|
+
this.sendHeartbeatMessage();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 发送心跳消息
|
|
123
|
+
*/
|
|
124
|
+
sendHeartbeatMessage() {
|
|
125
|
+
if (!this.active) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.lastHeartbeatTime = Date.now();
|
|
129
|
+
if (this.timeoutTimer) {
|
|
130
|
+
clearTimeout(this.timeoutTimer);
|
|
131
|
+
this.timeoutTimer = null;
|
|
132
|
+
}
|
|
133
|
+
this.sendHeartbeat(this.options.message);
|
|
134
|
+
this.timeoutTimer = setTimeout(() => {
|
|
135
|
+
if (this.active) {
|
|
136
|
+
this.onTimeout();
|
|
137
|
+
}
|
|
138
|
+
}, this.options.timeout);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 清除所有计时器
|
|
142
|
+
*/
|
|
143
|
+
clearTimers() {
|
|
144
|
+
if (this.intervalTimer) {
|
|
145
|
+
clearInterval(this.intervalTimer);
|
|
146
|
+
this.intervalTimer = null;
|
|
147
|
+
}
|
|
148
|
+
if (this.timeoutTimer) {
|
|
149
|
+
clearTimeout(this.timeoutTimer);
|
|
150
|
+
this.timeoutTimer = null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
HeartbeatManager
|
|
157
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Socket } from './socket';
|
|
2
|
+
import { SocketOptions, SocketStatus, SocketMessage } from './types';
|
|
3
|
+
import { SocketEvents } from './events';
|
|
4
|
+
import { SocketMonitor, SocketMonitorOptions, SocketHistoryItem, SocketStatusItem, SocketStats } from './monitor';
|
|
5
|
+
import * as components from './components';
|
|
6
|
+
/**
|
|
7
|
+
* 创建Socket实例
|
|
8
|
+
* @param url WebSocket连接URL
|
|
9
|
+
* @param options Socket配置选项
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSocket(url: string, options?: Partial<Omit<SocketOptions, 'url'>>): Socket;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
/**
|
|
14
|
+
* 创建新的Socket实例
|
|
15
|
+
*/
|
|
16
|
+
create: (url: string, options?: Partial<Omit<SocketOptions, "url">>, key?: string | undefined) => Socket;
|
|
17
|
+
/**
|
|
18
|
+
* 获取指定键的Socket实例
|
|
19
|
+
*/
|
|
20
|
+
get: (key: string) => Socket | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* 移除Socket实例
|
|
23
|
+
*/
|
|
24
|
+
remove: (key: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 关闭并移除所有Socket实例
|
|
27
|
+
*/
|
|
28
|
+
closeAll: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* 检查指定键的Socket是否存在
|
|
31
|
+
*/
|
|
32
|
+
has: (key: string) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 获取所有Socket标识键
|
|
35
|
+
*/
|
|
36
|
+
getKeys: () => string[];
|
|
37
|
+
/**
|
|
38
|
+
* 获取所有Socket实例
|
|
39
|
+
*/
|
|
40
|
+
getAllSockets: () => Socket[];
|
|
41
|
+
/**
|
|
42
|
+
* 为指定的Socket启用监控
|
|
43
|
+
*/
|
|
44
|
+
enableMonitoring: (key: string, options?: SocketMonitorOptions | undefined) => SocketMonitor | null;
|
|
45
|
+
/**
|
|
46
|
+
* 获取指定Socket的监控器
|
|
47
|
+
*/
|
|
48
|
+
getMonitor: (key: string) => SocketMonitor | null;
|
|
49
|
+
/**
|
|
50
|
+
* 获取所有Socket的监控信息
|
|
51
|
+
*/
|
|
52
|
+
getAllMonitors: () => Map<string, SocketMonitor | null>;
|
|
53
|
+
/**
|
|
54
|
+
* 监控组件
|
|
55
|
+
*/
|
|
56
|
+
components: typeof components;
|
|
57
|
+
};
|
|
58
|
+
export default _default;
|
|
59
|
+
export { Socket, SocketMonitor };
|
|
60
|
+
export type { SocketOptions, SocketMessage, SocketMonitorOptions, SocketHistoryItem, SocketStatusItem, SocketStats };
|
|
61
|
+
export { SocketStatus, SocketEvents };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/socket/index.ts
|
|
30
|
+
var socket_exports = {};
|
|
31
|
+
__export(socket_exports, {
|
|
32
|
+
Socket: () => import_socket.Socket,
|
|
33
|
+
SocketEvents: () => import_events.SocketEvents,
|
|
34
|
+
SocketMonitor: () => import_monitor.SocketMonitor,
|
|
35
|
+
SocketStatus: () => import_types.SocketStatus,
|
|
36
|
+
createSocket: () => createSocket,
|
|
37
|
+
default: () => socket_default
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(socket_exports);
|
|
40
|
+
var import_socket = require("./socket");
|
|
41
|
+
var import_types = require("./types");
|
|
42
|
+
var import_events = require("./events");
|
|
43
|
+
var import_monitor = require("./monitor");
|
|
44
|
+
var components = __toESM(require("./components"));
|
|
45
|
+
function createSocket(url, options = {}) {
|
|
46
|
+
return new import_socket.Socket({ url, ...options });
|
|
47
|
+
}
|
|
48
|
+
var SocketFactory = class {
|
|
49
|
+
sockets = /* @__PURE__ */ new Map();
|
|
50
|
+
/**
|
|
51
|
+
* 创建新的Socket实例
|
|
52
|
+
* @param url WebSocket连接URL
|
|
53
|
+
* @param options Socket配置选项
|
|
54
|
+
* @param key 可选的标识键,用于后续获取该Socket实例
|
|
55
|
+
*/
|
|
56
|
+
create(url, options = {}, key) {
|
|
57
|
+
const socket = new import_socket.Socket({ url, ...options });
|
|
58
|
+
if (key) {
|
|
59
|
+
this.sockets.set(key, socket);
|
|
60
|
+
}
|
|
61
|
+
return socket;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 获取Socket实例
|
|
65
|
+
* @param key Socket标识键
|
|
66
|
+
*/
|
|
67
|
+
get(key) {
|
|
68
|
+
return this.sockets.get(key);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 移除Socket实例
|
|
72
|
+
* @param key Socket标识键
|
|
73
|
+
*/
|
|
74
|
+
remove(key) {
|
|
75
|
+
const socket = this.sockets.get(key);
|
|
76
|
+
if (socket) {
|
|
77
|
+
socket.destroy();
|
|
78
|
+
return this.sockets.delete(key);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 关闭并移除所有Socket实例
|
|
84
|
+
*/
|
|
85
|
+
closeAll() {
|
|
86
|
+
for (const socket of this.sockets.values()) {
|
|
87
|
+
socket.destroy();
|
|
88
|
+
}
|
|
89
|
+
this.sockets.clear();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 检查指定键的Socket是否存在
|
|
93
|
+
* @param key Socket标识键
|
|
94
|
+
*/
|
|
95
|
+
has(key) {
|
|
96
|
+
return this.sockets.has(key);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 获取所有Socket实例的标识键
|
|
100
|
+
*/
|
|
101
|
+
getKeys() {
|
|
102
|
+
return Array.from(this.sockets.keys());
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 获取所有Socket实例
|
|
106
|
+
*/
|
|
107
|
+
getAllSockets() {
|
|
108
|
+
return Array.from(this.sockets.values());
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 为指定的Socket启用监控
|
|
112
|
+
* @param key Socket标识键
|
|
113
|
+
* @param options 监控配置选项
|
|
114
|
+
*/
|
|
115
|
+
enableMonitoring(key, options) {
|
|
116
|
+
const socket = this.get(key);
|
|
117
|
+
if (socket) {
|
|
118
|
+
return socket.enableMonitoring(options);
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 获取指定Socket的监控器
|
|
124
|
+
* @param key Socket标识键
|
|
125
|
+
*/
|
|
126
|
+
getMonitor(key) {
|
|
127
|
+
const socket = this.get(key);
|
|
128
|
+
if (socket) {
|
|
129
|
+
return socket.getMonitor();
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 获取所有Socket的监控信息
|
|
135
|
+
*/
|
|
136
|
+
getAllMonitors() {
|
|
137
|
+
const result = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const [key, socket] of this.sockets.entries()) {
|
|
139
|
+
result.set(key, socket.getMonitor());
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var socketFactory = new SocketFactory();
|
|
145
|
+
var socket_default = {
|
|
146
|
+
/**
|
|
147
|
+
* 创建新的Socket实例
|
|
148
|
+
*/
|
|
149
|
+
create: socketFactory.create.bind(socketFactory),
|
|
150
|
+
/**
|
|
151
|
+
* 获取指定键的Socket实例
|
|
152
|
+
*/
|
|
153
|
+
get: socketFactory.get.bind(socketFactory),
|
|
154
|
+
/**
|
|
155
|
+
* 移除Socket实例
|
|
156
|
+
*/
|
|
157
|
+
remove: socketFactory.remove.bind(socketFactory),
|
|
158
|
+
/**
|
|
159
|
+
* 关闭并移除所有Socket实例
|
|
160
|
+
*/
|
|
161
|
+
closeAll: socketFactory.closeAll.bind(socketFactory),
|
|
162
|
+
/**
|
|
163
|
+
* 检查指定键的Socket是否存在
|
|
164
|
+
*/
|
|
165
|
+
has: socketFactory.has.bind(socketFactory),
|
|
166
|
+
/**
|
|
167
|
+
* 获取所有Socket标识键
|
|
168
|
+
*/
|
|
169
|
+
getKeys: socketFactory.getKeys.bind(socketFactory),
|
|
170
|
+
/**
|
|
171
|
+
* 获取所有Socket实例
|
|
172
|
+
*/
|
|
173
|
+
getAllSockets: socketFactory.getAllSockets.bind(socketFactory),
|
|
174
|
+
/**
|
|
175
|
+
* 为指定的Socket启用监控
|
|
176
|
+
*/
|
|
177
|
+
enableMonitoring: socketFactory.enableMonitoring.bind(socketFactory),
|
|
178
|
+
/**
|
|
179
|
+
* 获取指定Socket的监控器
|
|
180
|
+
*/
|
|
181
|
+
getMonitor: socketFactory.getMonitor.bind(socketFactory),
|
|
182
|
+
/**
|
|
183
|
+
* 获取所有Socket的监控信息
|
|
184
|
+
*/
|
|
185
|
+
getAllMonitors: socketFactory.getAllMonitors.bind(socketFactory),
|
|
186
|
+
/**
|
|
187
|
+
* 监控组件
|
|
188
|
+
*/
|
|
189
|
+
components
|
|
190
|
+
};
|
|
191
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
192
|
+
0 && (module.exports = {
|
|
193
|
+
Socket,
|
|
194
|
+
SocketEvents,
|
|
195
|
+
SocketMonitor,
|
|
196
|
+
SocketStatus,
|
|
197
|
+
createSocket
|
|
198
|
+
});
|
|
@@ -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
|
+
}
|