@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,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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket模块常量
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** 默认配置选项 */
|
|
6
|
+
export var DEFAULT_SOCKET_OPTIONS = {
|
|
7
|
+
autoConnect: true,
|
|
8
|
+
reconnection: true,
|
|
9
|
+
reconnectionAttempts: Infinity,
|
|
10
|
+
reconnectionDelay: 1000,
|
|
11
|
+
reconnectionDelayMax: 5000,
|
|
12
|
+
heartbeat: true,
|
|
13
|
+
heartbeatInterval: 30000,
|
|
14
|
+
heartbeatTimeout: 10000,
|
|
15
|
+
timeout: 20000
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** 默认心跳消息 */
|
|
19
|
+
export var DEFAULT_HEARTBEAT_MESSAGE = {
|
|
20
|
+
type: "ping"
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** 默认心跳响应事件 */
|
|
24
|
+
export var DEFAULT_HEARTBEAT_RESPONSE = "pong";
|
|
25
|
+
|
|
26
|
+
/** 最小心跳间隔(毫秒) */
|
|
27
|
+
export var MIN_HEARTBEAT_INTERVAL = 1000;
|
|
28
|
+
|
|
29
|
+
/** 最小重连延迟(毫秒) */
|
|
30
|
+
export var MIN_RECONNECTION_DELAY = 500;
|
|
31
|
+
|
|
32
|
+
/** 连接状态码映射 */
|
|
33
|
+
export var WS_STATUS_MAP = {
|
|
34
|
+
0: "连接中",
|
|
35
|
+
1: "已连接",
|
|
36
|
+
2: "关闭中",
|
|
37
|
+
3: "已关闭",
|
|
38
|
+
4: "重连中"
|
|
39
|
+
};
|
|
@@ -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,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket标准事件类型
|
|
3
|
+
*/
|
|
4
|
+
export var SocketEvents = /*#__PURE__*/function (SocketEvents) {
|
|
5
|
+
SocketEvents["CONNECT"] = "connect";
|
|
6
|
+
SocketEvents["DISCONNECT"] = "disconnect";
|
|
7
|
+
SocketEvents["ERROR"] = "error";
|
|
8
|
+
SocketEvents["MESSAGE"] = "message";
|
|
9
|
+
SocketEvents["SEND"] = "send";
|
|
10
|
+
SocketEvents["RECONNECTING"] = "reconnecting";
|
|
11
|
+
SocketEvents["RECONNECT_ATTEMPT"] = "reconnect_attempt";
|
|
12
|
+
SocketEvents["RECONNECT"] = "reconnect";
|
|
13
|
+
SocketEvents["RECONNECT_ERROR"] = "reconnect_error";
|
|
14
|
+
SocketEvents["RECONNECT_FAILED"] = "reconnect_failed";
|
|
15
|
+
SocketEvents["HEARTBEAT"] = "heartbeat";
|
|
16
|
+
SocketEvents["HEARTBEAT_RESPONSE"] = "heartbeat_response";
|
|
17
|
+
SocketEvents["HEARTBEAT_TIMEOUT"] = "heartbeat_timeout";
|
|
18
|
+
return SocketEvents;
|
|
19
|
+
}({});
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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 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; }
|
|
3
|
+
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; }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
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); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
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; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
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); }
|
|
10
|
+
import { DEFAULT_HEARTBEAT_MESSAGE, MIN_HEARTBEAT_INTERVAL } from "./constants";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Socket心跳管理器
|
|
14
|
+
* 处理WebSocket连接的心跳检测
|
|
15
|
+
*/
|
|
16
|
+
export var HeartbeatManager = /*#__PURE__*/function () {
|
|
17
|
+
/**
|
|
18
|
+
* 创建心跳管理器
|
|
19
|
+
* @param options 心跳配置选项
|
|
20
|
+
* @param sendHeartbeat 发送心跳的回调函数
|
|
21
|
+
* @param callbacks 回调函数集合
|
|
22
|
+
*/
|
|
23
|
+
function HeartbeatManager(options, sendHeartbeat) {
|
|
24
|
+
var callbacks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
25
|
+
_classCallCheck(this, HeartbeatManager);
|
|
26
|
+
_defineProperty(this, "options", void 0);
|
|
27
|
+
_defineProperty(this, "intervalTimer", null);
|
|
28
|
+
_defineProperty(this, "timeoutTimer", null);
|
|
29
|
+
_defineProperty(this, "lastHeartbeatTime", 0);
|
|
30
|
+
_defineProperty(this, "lastHeartbeatResponse", 0);
|
|
31
|
+
_defineProperty(this, "active", false);
|
|
32
|
+
// 心跳回调函数
|
|
33
|
+
_defineProperty(this, "sendHeartbeat", void 0);
|
|
34
|
+
_defineProperty(this, "onTimeout", void 0);
|
|
35
|
+
_defineProperty(this, "onResponse", void 0);
|
|
36
|
+
this.options = _objectSpread(_objectSpread({}, options), {}, {
|
|
37
|
+
interval: Math.max(options.interval, MIN_HEARTBEAT_INTERVAL),
|
|
38
|
+
message: options.message || DEFAULT_HEARTBEAT_MESSAGE
|
|
39
|
+
});
|
|
40
|
+
this.sendHeartbeat = sendHeartbeat;
|
|
41
|
+
this.onTimeout = callbacks.onTimeout || function () {};
|
|
42
|
+
this.onResponse = callbacks.onResponse || function () {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 启动心跳检测
|
|
47
|
+
*/
|
|
48
|
+
_createClass(HeartbeatManager, [{
|
|
49
|
+
key: "start",
|
|
50
|
+
value: function start() {
|
|
51
|
+
if (this.active) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.active = true;
|
|
55
|
+
this.scheduleHeartbeat();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 停止心跳检测
|
|
60
|
+
*/
|
|
61
|
+
}, {
|
|
62
|
+
key: "stop",
|
|
63
|
+
value: function stop() {
|
|
64
|
+
this.active = false;
|
|
65
|
+
this.clearTimers();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 重启心跳检测
|
|
70
|
+
*/
|
|
71
|
+
}, {
|
|
72
|
+
key: "restart",
|
|
73
|
+
value: function restart() {
|
|
74
|
+
this.stop();
|
|
75
|
+
this.start();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 接收到心跳响应
|
|
80
|
+
*/
|
|
81
|
+
}, {
|
|
82
|
+
key: "receiveHeartbeatResponse",
|
|
83
|
+
value: function receiveHeartbeatResponse() {
|
|
84
|
+
this.lastHeartbeatResponse = Date.now();
|
|
85
|
+
|
|
86
|
+
// 清除超时计时器
|
|
87
|
+
if (this.timeoutTimer) {
|
|
88
|
+
clearTimeout(this.timeoutTimer);
|
|
89
|
+
this.timeoutTimer = null;
|
|
90
|
+
}
|
|
91
|
+
this.onResponse();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 获取上次心跳时间
|
|
96
|
+
*/
|
|
97
|
+
}, {
|
|
98
|
+
key: "getLastHeartbeatTime",
|
|
99
|
+
value: function getLastHeartbeatTime() {
|
|
100
|
+
return this.lastHeartbeatTime;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 获取上次心跳响应时间
|
|
105
|
+
*/
|
|
106
|
+
}, {
|
|
107
|
+
key: "getLastHeartbeatResponseTime",
|
|
108
|
+
value: function getLastHeartbeatResponseTime() {
|
|
109
|
+
return this.lastHeartbeatResponse;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 获取心跳是否活跃
|
|
114
|
+
*/
|
|
115
|
+
}, {
|
|
116
|
+
key: "isActive",
|
|
117
|
+
value: function isActive() {
|
|
118
|
+
return this.active;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 安排下一次心跳
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "scheduleHeartbeat",
|
|
126
|
+
value: function scheduleHeartbeat() {
|
|
127
|
+
var _this = this;
|
|
128
|
+
if (!this.active) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.clearTimers();
|
|
132
|
+
this.intervalTimer = setInterval(function () {
|
|
133
|
+
_this.sendHeartbeatMessage();
|
|
134
|
+
}, this.options.interval);
|
|
135
|
+
|
|
136
|
+
// 立即发送一次心跳
|
|
137
|
+
this.sendHeartbeatMessage();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 发送心跳消息
|
|
142
|
+
*/
|
|
143
|
+
}, {
|
|
144
|
+
key: "sendHeartbeatMessage",
|
|
145
|
+
value: function sendHeartbeatMessage() {
|
|
146
|
+
var _this2 = this;
|
|
147
|
+
if (!this.active) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.lastHeartbeatTime = Date.now();
|
|
151
|
+
if (this.timeoutTimer) {
|
|
152
|
+
clearTimeout(this.timeoutTimer);
|
|
153
|
+
this.timeoutTimer = null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 发送心跳
|
|
157
|
+
this.sendHeartbeat(this.options.message);
|
|
158
|
+
|
|
159
|
+
// 设置心跳超时
|
|
160
|
+
this.timeoutTimer = setTimeout(function () {
|
|
161
|
+
if (_this2.active) {
|
|
162
|
+
_this2.onTimeout();
|
|
163
|
+
}
|
|
164
|
+
}, this.options.timeout);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 清除所有计时器
|
|
169
|
+
*/
|
|
170
|
+
}, {
|
|
171
|
+
key: "clearTimers",
|
|
172
|
+
value: function clearTimers() {
|
|
173
|
+
if (this.intervalTimer) {
|
|
174
|
+
clearInterval(this.intervalTimer);
|
|
175
|
+
this.intervalTimer = null;
|
|
176
|
+
}
|
|
177
|
+
if (this.timeoutTimer) {
|
|
178
|
+
clearTimeout(this.timeoutTimer);
|
|
179
|
+
this.timeoutTimer = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}]);
|
|
183
|
+
return HeartbeatManager;
|
|
184
|
+
}();
|
|
@@ -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,246 @@
|
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
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 { Socket } from "./socket";
|
|
18
|
+
import { SocketStatus } from "./types";
|
|
19
|
+
import { SocketEvents } from "./events";
|
|
20
|
+
import { SocketMonitor } from "./monitor";
|
|
21
|
+
import * as components from "./components";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 创建Socket实例
|
|
25
|
+
* @param url WebSocket连接URL
|
|
26
|
+
* @param options Socket配置选项
|
|
27
|
+
*/
|
|
28
|
+
export function createSocket(url) {
|
|
29
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
+
return new Socket(_objectSpread({
|
|
31
|
+
url: url
|
|
32
|
+
}, options));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Socket工厂类
|
|
37
|
+
* 提供创建和管理Socket实例的方法
|
|
38
|
+
*/
|
|
39
|
+
var SocketFactory = /*#__PURE__*/function () {
|
|
40
|
+
function SocketFactory() {
|
|
41
|
+
_classCallCheck(this, SocketFactory);
|
|
42
|
+
_defineProperty(this, "sockets", new Map());
|
|
43
|
+
}
|
|
44
|
+
_createClass(SocketFactory, [{
|
|
45
|
+
key: "create",
|
|
46
|
+
value:
|
|
47
|
+
/**
|
|
48
|
+
* 创建新的Socket实例
|
|
49
|
+
* @param url WebSocket连接URL
|
|
50
|
+
* @param options Socket配置选项
|
|
51
|
+
* @param key 可选的标识键,用于后续获取该Socket实例
|
|
52
|
+
*/
|
|
53
|
+
function create(url) {
|
|
54
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
55
|
+
var key = arguments.length > 2 ? arguments[2] : undefined;
|
|
56
|
+
var socket = new Socket(_objectSpread({
|
|
57
|
+
url: url
|
|
58
|
+
}, options));
|
|
59
|
+
if (key) {
|
|
60
|
+
this.sockets.set(key, socket);
|
|
61
|
+
}
|
|
62
|
+
return socket;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 获取Socket实例
|
|
67
|
+
* @param key Socket标识键
|
|
68
|
+
*/
|
|
69
|
+
}, {
|
|
70
|
+
key: "get",
|
|
71
|
+
value: function get(key) {
|
|
72
|
+
return this.sockets.get(key);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 移除Socket实例
|
|
77
|
+
* @param key Socket标识键
|
|
78
|
+
*/
|
|
79
|
+
}, {
|
|
80
|
+
key: "remove",
|
|
81
|
+
value: function remove(key) {
|
|
82
|
+
var socket = this.sockets.get(key);
|
|
83
|
+
if (socket) {
|
|
84
|
+
socket.destroy();
|
|
85
|
+
return this.sockets.delete(key);
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 关闭并移除所有Socket实例
|
|
92
|
+
*/
|
|
93
|
+
}, {
|
|
94
|
+
key: "closeAll",
|
|
95
|
+
value: function closeAll() {
|
|
96
|
+
var _iterator = _createForOfIteratorHelper(this.sockets.values()),
|
|
97
|
+
_step;
|
|
98
|
+
try {
|
|
99
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
100
|
+
var socket = _step.value;
|
|
101
|
+
socket.destroy();
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
_iterator.e(err);
|
|
105
|
+
} finally {
|
|
106
|
+
_iterator.f();
|
|
107
|
+
}
|
|
108
|
+
this.sockets.clear();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 检查指定键的Socket是否存在
|
|
113
|
+
* @param key Socket标识键
|
|
114
|
+
*/
|
|
115
|
+
}, {
|
|
116
|
+
key: "has",
|
|
117
|
+
value: function has(key) {
|
|
118
|
+
return this.sockets.has(key);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 获取所有Socket实例的标识键
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "getKeys",
|
|
126
|
+
value: function getKeys() {
|
|
127
|
+
return Array.from(this.sockets.keys());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 获取所有Socket实例
|
|
132
|
+
*/
|
|
133
|
+
}, {
|
|
134
|
+
key: "getAllSockets",
|
|
135
|
+
value: function getAllSockets() {
|
|
136
|
+
return Array.from(this.sockets.values());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 为指定的Socket启用监控
|
|
141
|
+
* @param key Socket标识键
|
|
142
|
+
* @param options 监控配置选项
|
|
143
|
+
*/
|
|
144
|
+
}, {
|
|
145
|
+
key: "enableMonitoring",
|
|
146
|
+
value: function enableMonitoring(key, options) {
|
|
147
|
+
var socket = this.get(key);
|
|
148
|
+
if (socket) {
|
|
149
|
+
return socket.enableMonitoring(options);
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 获取指定Socket的监控器
|
|
156
|
+
* @param key Socket标识键
|
|
157
|
+
*/
|
|
158
|
+
}, {
|
|
159
|
+
key: "getMonitor",
|
|
160
|
+
value: function getMonitor(key) {
|
|
161
|
+
var socket = this.get(key);
|
|
162
|
+
if (socket) {
|
|
163
|
+
return socket.getMonitor();
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 获取所有Socket的监控信息
|
|
170
|
+
*/
|
|
171
|
+
}, {
|
|
172
|
+
key: "getAllMonitors",
|
|
173
|
+
value: function getAllMonitors() {
|
|
174
|
+
var result = new Map();
|
|
175
|
+
var _iterator2 = _createForOfIteratorHelper(this.sockets.entries()),
|
|
176
|
+
_step2;
|
|
177
|
+
try {
|
|
178
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
179
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
180
|
+
key = _step2$value[0],
|
|
181
|
+
socket = _step2$value[1];
|
|
182
|
+
result.set(key, socket.getMonitor());
|
|
183
|
+
}
|
|
184
|
+
} catch (err) {
|
|
185
|
+
_iterator2.e(err);
|
|
186
|
+
} finally {
|
|
187
|
+
_iterator2.f();
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
}]);
|
|
192
|
+
return SocketFactory;
|
|
193
|
+
}(); // 创建单例实例
|
|
194
|
+
var socketFactory = new SocketFactory();
|
|
195
|
+
|
|
196
|
+
// 默认导出
|
|
197
|
+
export default {
|
|
198
|
+
/**
|
|
199
|
+
* 创建新的Socket实例
|
|
200
|
+
*/
|
|
201
|
+
create: socketFactory.create.bind(socketFactory),
|
|
202
|
+
/**
|
|
203
|
+
* 获取指定键的Socket实例
|
|
204
|
+
*/
|
|
205
|
+
get: socketFactory.get.bind(socketFactory),
|
|
206
|
+
/**
|
|
207
|
+
* 移除Socket实例
|
|
208
|
+
*/
|
|
209
|
+
remove: socketFactory.remove.bind(socketFactory),
|
|
210
|
+
/**
|
|
211
|
+
* 关闭并移除所有Socket实例
|
|
212
|
+
*/
|
|
213
|
+
closeAll: socketFactory.closeAll.bind(socketFactory),
|
|
214
|
+
/**
|
|
215
|
+
* 检查指定键的Socket是否存在
|
|
216
|
+
*/
|
|
217
|
+
has: socketFactory.has.bind(socketFactory),
|
|
218
|
+
/**
|
|
219
|
+
* 获取所有Socket标识键
|
|
220
|
+
*/
|
|
221
|
+
getKeys: socketFactory.getKeys.bind(socketFactory),
|
|
222
|
+
/**
|
|
223
|
+
* 获取所有Socket实例
|
|
224
|
+
*/
|
|
225
|
+
getAllSockets: socketFactory.getAllSockets.bind(socketFactory),
|
|
226
|
+
/**
|
|
227
|
+
* 为指定的Socket启用监控
|
|
228
|
+
*/
|
|
229
|
+
enableMonitoring: socketFactory.enableMonitoring.bind(socketFactory),
|
|
230
|
+
/**
|
|
231
|
+
* 获取指定Socket的监控器
|
|
232
|
+
*/
|
|
233
|
+
getMonitor: socketFactory.getMonitor.bind(socketFactory),
|
|
234
|
+
/**
|
|
235
|
+
* 获取所有Socket的监控信息
|
|
236
|
+
*/
|
|
237
|
+
getAllMonitors: socketFactory.getAllMonitors.bind(socketFactory),
|
|
238
|
+
/**
|
|
239
|
+
* 监控组件
|
|
240
|
+
*/
|
|
241
|
+
components: components
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// 导出类型和常量
|
|
245
|
+
export { Socket, SocketMonitor };
|
|
246
|
+
export { SocketStatus, SocketEvents };
|