@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,340 @@
|
|
|
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/components/SocketMonitorPage.tsx
|
|
30
|
+
var SocketMonitorPage_exports = {};
|
|
31
|
+
__export(SocketMonitorPage_exports, {
|
|
32
|
+
default: () => SocketMonitorPage_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(SocketMonitorPage_exports);
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import__ = __toESM(require("../index"));
|
|
37
|
+
var import__2 = require("../index");
|
|
38
|
+
var formatTime = (timestamp) => {
|
|
39
|
+
if (timestamp === null) return "无";
|
|
40
|
+
const date = new Date(timestamp);
|
|
41
|
+
return date.toLocaleString();
|
|
42
|
+
};
|
|
43
|
+
var formatDuration = (ms) => {
|
|
44
|
+
if (ms === null) return "无";
|
|
45
|
+
const seconds = Math.floor(ms / 1e3);
|
|
46
|
+
const minutes = Math.floor(seconds / 60);
|
|
47
|
+
const hours = Math.floor(minutes / 60);
|
|
48
|
+
const remainingMinutes = minutes % 60;
|
|
49
|
+
const remainingSeconds = seconds % 60;
|
|
50
|
+
return `${hours}小时 ${remainingMinutes}分钟 ${remainingSeconds}秒`;
|
|
51
|
+
};
|
|
52
|
+
var formatBytes = (bytes) => {
|
|
53
|
+
if (bytes === 0) return "0 B";
|
|
54
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
55
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
56
|
+
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${units[i]}`;
|
|
57
|
+
};
|
|
58
|
+
var getStatusText = (status) => {
|
|
59
|
+
switch (status) {
|
|
60
|
+
case import__2.SocketStatus.CONNECTING:
|
|
61
|
+
return "连接中";
|
|
62
|
+
case import__2.SocketStatus.OPEN:
|
|
63
|
+
return "已连接";
|
|
64
|
+
case import__2.SocketStatus.CLOSING:
|
|
65
|
+
return "关闭中";
|
|
66
|
+
case import__2.SocketStatus.CLOSED:
|
|
67
|
+
return "已关闭";
|
|
68
|
+
case import__2.SocketStatus.RECONNECTING:
|
|
69
|
+
return "重连中";
|
|
70
|
+
default:
|
|
71
|
+
return "未知状态";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var SocketMonitorPage = () => {
|
|
75
|
+
const [socketKeys, setSocketKeys] = (0, import_react.useState)([]);
|
|
76
|
+
const [selectedKey, setSelectedKey] = (0, import_react.useState)(null);
|
|
77
|
+
const [currentSocket, setCurrentSocket] = (0, import_react.useState)(null);
|
|
78
|
+
const [stats, setStats] = (0, import_react.useState)(null);
|
|
79
|
+
const [messageHistory, setMessageHistory] = (0, import_react.useState)([]);
|
|
80
|
+
const [statusHistory, setStatusHistory] = (0, import_react.useState)([]);
|
|
81
|
+
const [autoRefresh, setAutoRefresh] = (0, import_react.useState)(true);
|
|
82
|
+
const [messageFilter, setMessageFilter] = (0, import_react.useState)(
|
|
83
|
+
"all"
|
|
84
|
+
);
|
|
85
|
+
const loadSocketList = (0, import_react.useCallback)(() => {
|
|
86
|
+
const keys = import__.default.getKeys();
|
|
87
|
+
setSocketKeys(keys);
|
|
88
|
+
if (keys.length > 0 && !selectedKey) {
|
|
89
|
+
setSelectedKey(keys[0]);
|
|
90
|
+
}
|
|
91
|
+
}, [selectedKey]);
|
|
92
|
+
const loadSocketData = (0, import_react.useCallback)(() => {
|
|
93
|
+
if (!selectedKey) return;
|
|
94
|
+
const socketInstance = import__.default.get(selectedKey);
|
|
95
|
+
if (!socketInstance) return;
|
|
96
|
+
setCurrentSocket(socketInstance);
|
|
97
|
+
const monitor = socketInstance.getMonitor() || socketInstance.enableMonitoring();
|
|
98
|
+
if (!monitor) return;
|
|
99
|
+
setStats(monitor.getStats());
|
|
100
|
+
const direction = messageFilter === "all" ? void 0 : messageFilter === "in" ? "in" : "out";
|
|
101
|
+
setMessageHistory(monitor.getMessageHistory(50, direction));
|
|
102
|
+
setStatusHistory(monitor.getStatusHistory(20));
|
|
103
|
+
}, [selectedKey, messageFilter]);
|
|
104
|
+
(0, import_react.useEffect)(() => {
|
|
105
|
+
loadSocketList();
|
|
106
|
+
}, [loadSocketList]);
|
|
107
|
+
(0, import_react.useEffect)(() => {
|
|
108
|
+
if (selectedKey) {
|
|
109
|
+
loadSocketData();
|
|
110
|
+
}
|
|
111
|
+
}, [selectedKey, loadSocketData]);
|
|
112
|
+
(0, import_react.useEffect)(() => {
|
|
113
|
+
let intervalId;
|
|
114
|
+
if (autoRefresh && selectedKey) {
|
|
115
|
+
intervalId = window.setInterval(() => {
|
|
116
|
+
loadSocketData();
|
|
117
|
+
}, 1e3);
|
|
118
|
+
}
|
|
119
|
+
return () => {
|
|
120
|
+
if (intervalId) {
|
|
121
|
+
clearInterval(intervalId);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}, [autoRefresh, selectedKey, loadSocketData]);
|
|
125
|
+
const handleConnect = () => {
|
|
126
|
+
if (currentSocket) {
|
|
127
|
+
currentSocket.connect().catch(console.error);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const handleDisconnect = () => {
|
|
131
|
+
if (currentSocket) {
|
|
132
|
+
currentSocket.disconnect();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const handleClearHistory = () => {
|
|
136
|
+
if (currentSocket) {
|
|
137
|
+
const monitor = currentSocket.getMonitor();
|
|
138
|
+
if (monitor) {
|
|
139
|
+
monitor.clearHistory();
|
|
140
|
+
loadSocketData();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const handleResetStats = () => {
|
|
145
|
+
if (currentSocket) {
|
|
146
|
+
const monitor = currentSocket.getMonitor();
|
|
147
|
+
if (monitor) {
|
|
148
|
+
monitor.resetStats();
|
|
149
|
+
loadSocketData();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const handleSendTestMessage = () => {
|
|
154
|
+
if (currentSocket && currentSocket.isConnected()) {
|
|
155
|
+
try {
|
|
156
|
+
currentSocket.send("test_message", {
|
|
157
|
+
content: "这是一条测试消息",
|
|
158
|
+
timestamp: Date.now()
|
|
159
|
+
});
|
|
160
|
+
loadSocketData();
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error("发送测试消息失败:", error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "socket-monitor-container", style: { padding: "20px" } }, /* @__PURE__ */ import_react.default.createElement("h1", null, "Socket连接监控"), /* @__PURE__ */ import_react.default.createElement("div", { className: "socket-selector", style: { marginBottom: "20px" } }, /* @__PURE__ */ import_react.default.createElement("label", null, "选择Socket: "), /* @__PURE__ */ import_react.default.createElement(
|
|
167
|
+
"select",
|
|
168
|
+
{
|
|
169
|
+
value: selectedKey || "",
|
|
170
|
+
onChange: (e) => setSelectedKey(e.target.value || null),
|
|
171
|
+
style: { marginRight: "10px" }
|
|
172
|
+
},
|
|
173
|
+
/* @__PURE__ */ import_react.default.createElement("option", { value: "" }, "-- 请选择 --"),
|
|
174
|
+
socketKeys.map((key) => /* @__PURE__ */ import_react.default.createElement("option", { key, value: key }, key))
|
|
175
|
+
), /* @__PURE__ */ import_react.default.createElement("button", { onClick: loadSocketList, style: { marginRight: "10px" } }, "刷新列表"), /* @__PURE__ */ import_react.default.createElement("label", null, /* @__PURE__ */ import_react.default.createElement(
|
|
176
|
+
"input",
|
|
177
|
+
{
|
|
178
|
+
type: "checkbox",
|
|
179
|
+
checked: autoRefresh,
|
|
180
|
+
onChange: (e) => setAutoRefresh(e.target.checked)
|
|
181
|
+
}
|
|
182
|
+
), "自动刷新")), currentSocket && /* @__PURE__ */ import_react.default.createElement("div", { className: "socket-actions", style: { marginBottom: "20px" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
183
|
+
"button",
|
|
184
|
+
{
|
|
185
|
+
onClick: handleConnect,
|
|
186
|
+
disabled: currentSocket.isConnected(),
|
|
187
|
+
style: { marginRight: "10px" }
|
|
188
|
+
},
|
|
189
|
+
"连接"
|
|
190
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
191
|
+
"button",
|
|
192
|
+
{
|
|
193
|
+
onClick: handleDisconnect,
|
|
194
|
+
disabled: !currentSocket.isConnected(),
|
|
195
|
+
style: { marginRight: "10px" }
|
|
196
|
+
},
|
|
197
|
+
"断开"
|
|
198
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
199
|
+
"button",
|
|
200
|
+
{
|
|
201
|
+
onClick: handleSendTestMessage,
|
|
202
|
+
disabled: !currentSocket.isConnected(),
|
|
203
|
+
style: { marginRight: "10px" }
|
|
204
|
+
},
|
|
205
|
+
"发送测试消息"
|
|
206
|
+
), /* @__PURE__ */ import_react.default.createElement("button", { onClick: handleClearHistory, style: { marginRight: "10px" } }, "清除历史记录"), /* @__PURE__ */ import_react.default.createElement("button", { onClick: handleResetStats }, "重置统计")), currentSocket && stats && /* @__PURE__ */ import_react.default.createElement("div", { className: "socket-stats", style: { marginBottom: "20px" } }, /* @__PURE__ */ import_react.default.createElement("h2", null, "Socket状态和统计"), /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", flexWrap: "wrap" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { flex: "1 1 300px", margin: "0 20px 20px 0" } }, /* @__PURE__ */ import_react.default.createElement("h3", null, "连接信息"), /* @__PURE__ */ import_react.default.createElement("table", { style: { width: "100%", borderCollapse: "collapse" } }, /* @__PURE__ */ import_react.default.createElement("tbody", null, /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "URL:")), /* @__PURE__ */ import_react.default.createElement("td", null, currentSocket["url"])), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "当前状态:")), /* @__PURE__ */ import_react.default.createElement("td", null, getStatusText(currentSocket.getStatus()))), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "首次连接时间:")), /* @__PURE__ */ import_react.default.createElement("td", null, formatTime(stats.firstConnectTime))), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "最后连接时间:")), /* @__PURE__ */ import_react.default.createElement("td", null, formatTime(stats.lastConnectTime))), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "当前连接持续时间:")), /* @__PURE__ */ import_react.default.createElement("td", null, formatDuration(stats.currentConnectionDuration)))))), /* @__PURE__ */ import_react.default.createElement("div", { style: { flex: "1 1 300px", margin: "0 20px 20px 0" } }, /* @__PURE__ */ import_react.default.createElement("h3", null, "统计数据"), /* @__PURE__ */ import_react.default.createElement("table", { style: { width: "100%", borderCollapse: "collapse" } }, /* @__PURE__ */ import_react.default.createElement("tbody", null, /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "连接次数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.connectionCount)), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "重连次数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.reconnectionCount)), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "错误次数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.errorCount)), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "心跳发送次数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.heartbeatCount)), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "心跳超时次数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.heartbeatTimeoutCount))))), /* @__PURE__ */ import_react.default.createElement("div", { style: { flex: "1 1 300px", margin: "0 0 20px 0" } }, /* @__PURE__ */ import_react.default.createElement("h3", null, "消息统计"), /* @__PURE__ */ import_react.default.createElement("table", { style: { width: "100%", borderCollapse: "collapse" } }, /* @__PURE__ */ import_react.default.createElement("tbody", null, /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "发送消息数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.totalSent)), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "接收消息数:")), /* @__PURE__ */ import_react.default.createElement("td", null, stats.totalReceived)), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "发送数据量:")), /* @__PURE__ */ import_react.default.createElement("td", null, formatBytes(stats.bytesSent))), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "接收数据量:")), /* @__PURE__ */ import_react.default.createElement("td", null, formatBytes(stats.bytesReceived))), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("strong", null, "平均消息大小:")), /* @__PURE__ */ import_react.default.createElement("td", null, formatBytes(stats.averageMessageSize)))))))), currentSocket && statusHistory.length > 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: "socket-status-history", style: { marginBottom: "20px" } }, /* @__PURE__ */ import_react.default.createElement("h2", null, "状态变更历史"), /* @__PURE__ */ import_react.default.createElement(
|
|
207
|
+
"table",
|
|
208
|
+
{
|
|
209
|
+
style: {
|
|
210
|
+
width: "100%",
|
|
211
|
+
borderCollapse: "collapse",
|
|
212
|
+
border: "1px solid #ddd"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
/* @__PURE__ */ import_react.default.createElement("thead", null, /* @__PURE__ */ import_react.default.createElement("tr", { style: { backgroundColor: "#f2f2f2" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
216
|
+
"th",
|
|
217
|
+
{
|
|
218
|
+
style: {
|
|
219
|
+
padding: "8px",
|
|
220
|
+
borderBottom: "1px solid #ddd",
|
|
221
|
+
textAlign: "left"
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
"时间"
|
|
225
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
226
|
+
"th",
|
|
227
|
+
{
|
|
228
|
+
style: {
|
|
229
|
+
padding: "8px",
|
|
230
|
+
borderBottom: "1px solid #ddd",
|
|
231
|
+
textAlign: "left"
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
"变更前状态"
|
|
235
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
236
|
+
"th",
|
|
237
|
+
{
|
|
238
|
+
style: {
|
|
239
|
+
padding: "8px",
|
|
240
|
+
borderBottom: "1px solid #ddd",
|
|
241
|
+
textAlign: "left"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"变更后状态"
|
|
245
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
246
|
+
"th",
|
|
247
|
+
{
|
|
248
|
+
style: {
|
|
249
|
+
padding: "8px",
|
|
250
|
+
borderBottom: "1px solid #ddd",
|
|
251
|
+
textAlign: "left"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
"触发事件"
|
|
255
|
+
))),
|
|
256
|
+
/* @__PURE__ */ import_react.default.createElement("tbody", null, statusHistory.map((item, index) => /* @__PURE__ */ import_react.default.createElement("tr", { key: index, style: { borderBottom: "1px solid #ddd" } }, /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, formatTime(item.timestamp)), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, getStatusText(item.from)), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, getStatusText(item.to)), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, item.event || "-"))))
|
|
257
|
+
)), currentSocket && /* @__PURE__ */ import_react.default.createElement("div", { className: "socket-message-history" }, /* @__PURE__ */ import_react.default.createElement("h2", null, "消息历史记录"), /* @__PURE__ */ import_react.default.createElement("div", { style: { marginBottom: "10px" } }, /* @__PURE__ */ import_react.default.createElement("label", null, "过滤: "), /* @__PURE__ */ import_react.default.createElement(
|
|
258
|
+
"select",
|
|
259
|
+
{
|
|
260
|
+
value: messageFilter,
|
|
261
|
+
onChange: (e) => setMessageFilter(e.target.value),
|
|
262
|
+
style: { marginRight: "10px" }
|
|
263
|
+
},
|
|
264
|
+
/* @__PURE__ */ import_react.default.createElement("option", { value: "all" }, "全部消息"),
|
|
265
|
+
/* @__PURE__ */ import_react.default.createElement("option", { value: "in" }, "接收的消息"),
|
|
266
|
+
/* @__PURE__ */ import_react.default.createElement("option", { value: "out" }, "发送的消息")
|
|
267
|
+
)), messageHistory.length > 0 ? /* @__PURE__ */ import_react.default.createElement(
|
|
268
|
+
"table",
|
|
269
|
+
{
|
|
270
|
+
style: {
|
|
271
|
+
width: "100%",
|
|
272
|
+
borderCollapse: "collapse",
|
|
273
|
+
border: "1px solid #ddd"
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
/* @__PURE__ */ import_react.default.createElement("thead", null, /* @__PURE__ */ import_react.default.createElement("tr", { style: { backgroundColor: "#f2f2f2" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
277
|
+
"th",
|
|
278
|
+
{
|
|
279
|
+
style: {
|
|
280
|
+
padding: "8px",
|
|
281
|
+
borderBottom: "1px solid #ddd",
|
|
282
|
+
textAlign: "left"
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
"时间"
|
|
286
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
287
|
+
"th",
|
|
288
|
+
{
|
|
289
|
+
style: {
|
|
290
|
+
padding: "8px",
|
|
291
|
+
borderBottom: "1px solid #ddd",
|
|
292
|
+
textAlign: "left"
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
"方向"
|
|
296
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
297
|
+
"th",
|
|
298
|
+
{
|
|
299
|
+
style: {
|
|
300
|
+
padding: "8px",
|
|
301
|
+
borderBottom: "1px solid #ddd",
|
|
302
|
+
textAlign: "left"
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
"事件类型"
|
|
306
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
307
|
+
"th",
|
|
308
|
+
{
|
|
309
|
+
style: {
|
|
310
|
+
padding: "8px",
|
|
311
|
+
borderBottom: "1px solid #ddd",
|
|
312
|
+
textAlign: "left"
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
"大小"
|
|
316
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
317
|
+
"th",
|
|
318
|
+
{
|
|
319
|
+
style: {
|
|
320
|
+
padding: "8px",
|
|
321
|
+
borderBottom: "1px solid #ddd",
|
|
322
|
+
textAlign: "left"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
"内容"
|
|
326
|
+
))),
|
|
327
|
+
/* @__PURE__ */ import_react.default.createElement("tbody", null, messageHistory.map((item) => /* @__PURE__ */ import_react.default.createElement("tr", { key: item.id, style: { borderBottom: "1px solid #ddd" } }, /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, formatTime(item.timestamp)), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, item.direction === "in" ? "接收" : "发送"), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, item.message.event), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, formatBytes(item.size || 0)), /* @__PURE__ */ import_react.default.createElement("td", { style: { padding: "8px" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
328
|
+
"pre",
|
|
329
|
+
{
|
|
330
|
+
style: {
|
|
331
|
+
margin: 0,
|
|
332
|
+
maxWidth: "400px",
|
|
333
|
+
overflow: "auto"
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
JSON.stringify(item.message.data, null, 2)
|
|
337
|
+
)))))
|
|
338
|
+
) : /* @__PURE__ */ import_react.default.createElement("p", null, "暂无消息记录")));
|
|
339
|
+
};
|
|
340
|
+
var SocketMonitorPage_default = SocketMonitorPage;
|
|
@@ -0,0 +1,39 @@
|
|
|
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/components/index.ts
|
|
30
|
+
var components_exports = {};
|
|
31
|
+
__export(components_exports, {
|
|
32
|
+
SocketMonitorPage: () => import_SocketMonitorPage.default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(components_exports);
|
|
35
|
+
var import_SocketMonitorPage = __toESM(require("./SocketMonitorPage"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
SocketMonitorPage
|
|
39
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket模块常量
|
|
3
|
+
*/
|
|
4
|
+
/** 默认配置选项 */
|
|
5
|
+
export declare const DEFAULT_SOCKET_OPTIONS: {
|
|
6
|
+
autoConnect: boolean;
|
|
7
|
+
reconnection: boolean;
|
|
8
|
+
reconnectionAttempts: number;
|
|
9
|
+
reconnectionDelay: number;
|
|
10
|
+
reconnectionDelayMax: number;
|
|
11
|
+
heartbeat: boolean;
|
|
12
|
+
heartbeatInterval: number;
|
|
13
|
+
heartbeatTimeout: number;
|
|
14
|
+
timeout: number;
|
|
15
|
+
};
|
|
16
|
+
/** 默认心跳消息 */
|
|
17
|
+
export declare const DEFAULT_HEARTBEAT_MESSAGE: {
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
/** 默认心跳响应事件 */
|
|
21
|
+
export declare const DEFAULT_HEARTBEAT_RESPONSE = "pong";
|
|
22
|
+
/** 最小心跳间隔(毫秒) */
|
|
23
|
+
export declare const MIN_HEARTBEAT_INTERVAL = 1000;
|
|
24
|
+
/** 最小重连延迟(毫秒) */
|
|
25
|
+
export declare const MIN_RECONNECTION_DELAY = 500;
|
|
26
|
+
/** 连接状态码映射 */
|
|
27
|
+
export declare const WS_STATUS_MAP: {
|
|
28
|
+
0: string;
|
|
29
|
+
1: string;
|
|
30
|
+
2: string;
|
|
31
|
+
3: string;
|
|
32
|
+
4: string;
|
|
33
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
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/constants.ts
|
|
20
|
+
var constants_exports = {};
|
|
21
|
+
__export(constants_exports, {
|
|
22
|
+
DEFAULT_HEARTBEAT_MESSAGE: () => DEFAULT_HEARTBEAT_MESSAGE,
|
|
23
|
+
DEFAULT_HEARTBEAT_RESPONSE: () => DEFAULT_HEARTBEAT_RESPONSE,
|
|
24
|
+
DEFAULT_SOCKET_OPTIONS: () => DEFAULT_SOCKET_OPTIONS,
|
|
25
|
+
MIN_HEARTBEAT_INTERVAL: () => MIN_HEARTBEAT_INTERVAL,
|
|
26
|
+
MIN_RECONNECTION_DELAY: () => MIN_RECONNECTION_DELAY,
|
|
27
|
+
WS_STATUS_MAP: () => WS_STATUS_MAP
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(constants_exports);
|
|
30
|
+
var DEFAULT_SOCKET_OPTIONS = {
|
|
31
|
+
autoConnect: true,
|
|
32
|
+
reconnection: true,
|
|
33
|
+
reconnectionAttempts: Infinity,
|
|
34
|
+
reconnectionDelay: 1e3,
|
|
35
|
+
reconnectionDelayMax: 5e3,
|
|
36
|
+
heartbeat: true,
|
|
37
|
+
heartbeatInterval: 3e4,
|
|
38
|
+
heartbeatTimeout: 1e4,
|
|
39
|
+
timeout: 2e4
|
|
40
|
+
};
|
|
41
|
+
var DEFAULT_HEARTBEAT_MESSAGE = {
|
|
42
|
+
type: "ping"
|
|
43
|
+
};
|
|
44
|
+
var DEFAULT_HEARTBEAT_RESPONSE = "pong";
|
|
45
|
+
var MIN_HEARTBEAT_INTERVAL = 1e3;
|
|
46
|
+
var MIN_RECONNECTION_DELAY = 500;
|
|
47
|
+
var WS_STATUS_MAP = {
|
|
48
|
+
0: "连接中",
|
|
49
|
+
1: "已连接",
|
|
50
|
+
2: "关闭中",
|
|
51
|
+
3: "已关闭",
|
|
52
|
+
4: "重连中"
|
|
53
|
+
};
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
DEFAULT_HEARTBEAT_MESSAGE,
|
|
57
|
+
DEFAULT_HEARTBEAT_RESPONSE,
|
|
58
|
+
DEFAULT_SOCKET_OPTIONS,
|
|
59
|
+
MIN_HEARTBEAT_INTERVAL,
|
|
60
|
+
MIN_RECONNECTION_DELAY,
|
|
61
|
+
WS_STATUS_MAP
|
|
62
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket标准事件类型
|
|
3
|
+
*/
|
|
4
|
+
export declare enum SocketEvents {
|
|
5
|
+
/** 连接成功事件 */
|
|
6
|
+
CONNECT = "connect",
|
|
7
|
+
/** 连接断开事件 */
|
|
8
|
+
DISCONNECT = "disconnect",
|
|
9
|
+
/** 连接错误事件 */
|
|
10
|
+
ERROR = "error",
|
|
11
|
+
/** 接收消息事件 */
|
|
12
|
+
MESSAGE = "message",
|
|
13
|
+
/** 发送消息事件 */
|
|
14
|
+
SEND = "send",
|
|
15
|
+
/** 重连中事件 */
|
|
16
|
+
RECONNECTING = "reconnecting",
|
|
17
|
+
/** 重连尝试事件 */
|
|
18
|
+
RECONNECT_ATTEMPT = "reconnect_attempt",
|
|
19
|
+
/** 重连成功事件 */
|
|
20
|
+
RECONNECT = "reconnect",
|
|
21
|
+
/** 重连失败事件 */
|
|
22
|
+
RECONNECT_ERROR = "reconnect_error",
|
|
23
|
+
/** 重连次数超限 */
|
|
24
|
+
RECONNECT_FAILED = "reconnect_failed",
|
|
25
|
+
/** 心跳发送事件 */
|
|
26
|
+
HEARTBEAT = "heartbeat",
|
|
27
|
+
/** 心跳响应事件 */
|
|
28
|
+
HEARTBEAT_RESPONSE = "heartbeat_response",
|
|
29
|
+
/** 心跳超时事件 */
|
|
30
|
+
HEARTBEAT_TIMEOUT = "heartbeat_timeout"
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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/events.ts
|
|
20
|
+
var events_exports = {};
|
|
21
|
+
__export(events_exports, {
|
|
22
|
+
SocketEvents: () => SocketEvents
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(events_exports);
|
|
25
|
+
var SocketEvents = /* @__PURE__ */ ((SocketEvents2) => {
|
|
26
|
+
SocketEvents2["CONNECT"] = "connect";
|
|
27
|
+
SocketEvents2["DISCONNECT"] = "disconnect";
|
|
28
|
+
SocketEvents2["ERROR"] = "error";
|
|
29
|
+
SocketEvents2["MESSAGE"] = "message";
|
|
30
|
+
SocketEvents2["SEND"] = "send";
|
|
31
|
+
SocketEvents2["RECONNECTING"] = "reconnecting";
|
|
32
|
+
SocketEvents2["RECONNECT_ATTEMPT"] = "reconnect_attempt";
|
|
33
|
+
SocketEvents2["RECONNECT"] = "reconnect";
|
|
34
|
+
SocketEvents2["RECONNECT_ERROR"] = "reconnect_error";
|
|
35
|
+
SocketEvents2["RECONNECT_FAILED"] = "reconnect_failed";
|
|
36
|
+
SocketEvents2["HEARTBEAT"] = "heartbeat";
|
|
37
|
+
SocketEvents2["HEARTBEAT_RESPONSE"] = "heartbeat_response";
|
|
38
|
+
SocketEvents2["HEARTBEAT_TIMEOUT"] = "heartbeat_timeout";
|
|
39
|
+
return SocketEvents2;
|
|
40
|
+
})(SocketEvents || {});
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
SocketEvents
|
|
44
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { HeartbeatOptions, SocketMessage } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Socket心跳管理器
|
|
4
|
+
* 处理WebSocket连接的心跳检测
|
|
5
|
+
*/
|
|
6
|
+
export declare class HeartbeatManager {
|
|
7
|
+
private options;
|
|
8
|
+
private intervalTimer;
|
|
9
|
+
private timeoutTimer;
|
|
10
|
+
private lastHeartbeatTime;
|
|
11
|
+
private lastHeartbeatResponse;
|
|
12
|
+
private active;
|
|
13
|
+
private sendHeartbeat;
|
|
14
|
+
private onTimeout;
|
|
15
|
+
private onResponse;
|
|
16
|
+
/**
|
|
17
|
+
* 创建心跳管理器
|
|
18
|
+
* @param options 心跳配置选项
|
|
19
|
+
* @param sendHeartbeat 发送心跳的回调函数
|
|
20
|
+
* @param callbacks 回调函数集合
|
|
21
|
+
*/
|
|
22
|
+
constructor(options: HeartbeatOptions, sendHeartbeat: (msg: SocketMessage) => void, callbacks?: {
|
|
23
|
+
onTimeout?: () => void;
|
|
24
|
+
onResponse?: () => void;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* 启动心跳检测
|
|
28
|
+
*/
|
|
29
|
+
start(): void;
|
|
30
|
+
/**
|
|
31
|
+
* 停止心跳检测
|
|
32
|
+
*/
|
|
33
|
+
stop(): void;
|
|
34
|
+
/**
|
|
35
|
+
* 重启心跳检测
|
|
36
|
+
*/
|
|
37
|
+
restart(): void;
|
|
38
|
+
/**
|
|
39
|
+
* 接收到心跳响应
|
|
40
|
+
*/
|
|
41
|
+
receiveHeartbeatResponse(): void;
|
|
42
|
+
/**
|
|
43
|
+
* 获取上次心跳时间
|
|
44
|
+
*/
|
|
45
|
+
getLastHeartbeatTime(): number;
|
|
46
|
+
/**
|
|
47
|
+
* 获取上次心跳响应时间
|
|
48
|
+
*/
|
|
49
|
+
getLastHeartbeatResponseTime(): number;
|
|
50
|
+
/**
|
|
51
|
+
* 获取心跳是否活跃
|
|
52
|
+
*/
|
|
53
|
+
isActive(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 安排下一次心跳
|
|
56
|
+
*/
|
|
57
|
+
private scheduleHeartbeat;
|
|
58
|
+
/**
|
|
59
|
+
* 发送心跳消息
|
|
60
|
+
*/
|
|
61
|
+
private sendHeartbeatMessage;
|
|
62
|
+
/**
|
|
63
|
+
* 清除所有计时器
|
|
64
|
+
*/
|
|
65
|
+
private clearTimers;
|
|
66
|
+
}
|