zmdms-utils 0.0.81 → 0.0.83
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/dist/es/validate.js +168 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +2 -6
- package/src/index.ts +0 -3
- package/src/validate.ts +198 -0
- package/dist/es/_virtual/FastBufferList.js +0 -7
- package/dist/es/_virtual/_commonjs-dynamic-modules.js +0 -5
- package/dist/es/_virtual/browser.js +0 -7
- package/dist/es/_virtual/browser2.js +0 -7
- package/dist/es/_virtual/debug.js +0 -7
- package/dist/es/_virtual/event.js +0 -7
- package/dist/es/_virtual/http-parser.js +0 -3
- package/dist/es/_virtual/iframe.js +0 -7
- package/dist/es/_virtual/index.js +0 -7
- package/dist/es/_virtual/index2.js +0 -7
- package/dist/es/_virtual/index3.js +0 -7
- package/dist/es/_virtual/index4.js +0 -7
- package/dist/es/_virtual/index5.js +0 -7
- package/dist/es/_virtual/index6.js +0 -7
- package/dist/es/_virtual/index7.js +0 -3
- package/dist/es/_virtual/index8.js +0 -7
- package/dist/es/_virtual/index9.js +0 -7
- package/dist/es/_virtual/inherits.js +0 -7
- package/dist/es/_virtual/inherits_browser.js +0 -7
- package/dist/es/_virtual/json3.js +0 -7
- package/dist/es/_virtual/node.js +0 -7
- package/dist/es/_virtual/node2.js +0 -7
- package/dist/es/_virtual/stomp-node.js +0 -3
- package/dist/es/_virtual/stomp.js +0 -3
- package/dist/es/_virtual/streams.js +0 -3
- package/dist/es/_virtual/utils.js +0 -3
- package/dist/es/node_modules/bufferutil/fallback.js +0 -43
- package/dist/es/node_modules/bufferutil/index.js +0 -21
- package/dist/es/node_modules/debug/src/browser.js +0 -192
- package/dist/es/node_modules/debug/src/common.js +0 -259
- package/dist/es/node_modules/debug/src/index.js +0 -25
- package/dist/es/node_modules/debug/src/node.js +0 -192
- package/dist/es/node_modules/eventsource/lib/eventsource.js +0 -493
- package/dist/es/node_modules/faye-websocket/lib/faye/eventsource.js +0 -150
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event.js +0 -31
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js +0 -41
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api.js +0 -205
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/client.js +0 -107
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket.js +0 -47
- package/dist/es/node_modules/has-flag/index.js +0 -17
- package/dist/es/node_modules/http-parser-js/http-parser.js +0 -471
- package/dist/es/node_modules/inherits/inherits.js +0 -14
- package/dist/es/node_modules/inherits/inherits_browser.js +0 -38
- package/dist/es/node_modules/is-typedarray/index.js +0 -51
- package/dist/es/node_modules/json3/lib/json3.js +0 -937
- package/dist/es/node_modules/ms/index.js +0 -172
- package/dist/es/node_modules/node-gyp-build/index.js +0 -21
- package/dist/es/node_modules/node-gyp-build/node-gyp-build.js +0 -222
- package/dist/es/node_modules/querystringify/index.js +0 -120
- package/dist/es/node_modules/requires-port/index.js +0 -38
- package/dist/es/node_modules/safe-buffer/index.js +0 -71
- package/dist/es/node_modules/supports-color/index.js +0 -143
- package/dist/es/node_modules/typedarray-to-buffer/index.js +0 -37
- package/dist/es/node_modules/url-parse/index.js +0 -594
- package/dist/es/node_modules/utf-8-validate/fallback.js +0 -71
- package/dist/es/node_modules/utf-8-validate/index.js +0 -21
- package/dist/es/node_modules/websocket/index.js +0 -15
- package/dist/es/node_modules/websocket/lib/Deprecation.js +0 -42
- package/dist/es/node_modules/websocket/lib/W3CWebSocket.js +0 -268
- package/dist/es/node_modules/websocket/lib/WebSocketClient.js +0 -380
- package/dist/es/node_modules/websocket/lib/WebSocketConnection.js +0 -914
- package/dist/es/node_modules/websocket/lib/WebSocketFrame.js +0 -293
- package/dist/es/node_modules/websocket/lib/WebSocketRequest.js +0 -543
- package/dist/es/node_modules/websocket/lib/WebSocketRouter.js +0 -172
- package/dist/es/node_modules/websocket/lib/WebSocketRouterRequest.js +0 -67
- package/dist/es/node_modules/websocket/lib/WebSocketServer.js +0 -272
- package/dist/es/node_modules/websocket/lib/utils.js +0 -80
- package/dist/es/node_modules/websocket/lib/version.js +0 -13
- package/dist/es/node_modules/websocket/lib/websocket.js +0 -31
- package/dist/es/node_modules/websocket/node_modules/debug/src/browser.js +0 -199
- package/dist/es/node_modules/websocket/node_modules/debug/src/debug.js +0 -215
- package/dist/es/node_modules/websocket/node_modules/debug/src/index.js +0 -25
- package/dist/es/node_modules/websocket/node_modules/debug/src/node.js +0 -266
- package/dist/es/node_modules/websocket/node_modules/ms/index.js +0 -162
- package/dist/es/node_modules/websocket/package.json.js +0 -77
- package/dist/es/node_modules/websocket/vendor/FastBufferList.js +0 -205
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/base.js +0 -202
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/client.js +0 -152
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft75.js +0 -128
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft76.js +0 -124
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/headers.js +0 -44
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/frame.js +0 -21
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/message.js +0 -37
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi.js +0 -492
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/proxy.js +0 -108
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/server.js +0 -119
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/stream_reader.js +0 -72
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver.js +0 -47
- package/dist/es/node_modules/websocket-driver/lib/websocket/http_parser.js +0 -140
- package/dist/es/node_modules/websocket-driver/lib/websocket/streams.js +0 -150
- package/dist/es/node_modules/websocket-extensions/lib/parser.js +0 -103
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/cell.js +0 -56
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/functor.js +0 -74
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/index.js +0 -50
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/pledge.js +0 -39
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/ring_buffer.js +0 -66
- package/dist/es/node_modules/websocket-extensions/lib/websocket_extensions.js +0 -165
- package/dist/es/node_modules/yaeti/index.js +0 -17
- package/dist/es/node_modules/yaeti/lib/Event.js +0 -24
- package/dist/es/node_modules/yaeti/lib/EventTarget.js +0 -130
- package/dist/es/node_modules/zt-sockjs-client/lib/entry.js +0 -14
- package/dist/es/node_modules/zt-sockjs-client/lib/event/close.js +0 -21
- package/dist/es/node_modules/zt-sockjs-client/lib/event/event.js +0 -22
- package/dist/es/node_modules/zt-sockjs-client/lib/event/eventtarget.js +0 -62
- package/dist/es/node_modules/zt-sockjs-client/lib/event/trans-message.js +0 -19
- package/dist/es/node_modules/zt-sockjs-client/lib/facade.js +0 -40
- package/dist/es/node_modules/zt-sockjs-client/lib/iframe-bootstrap.js +0 -122
- package/dist/es/node_modules/zt-sockjs-client/lib/info-ajax.js +0 -57
- package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe-receiver.js +0 -50
- package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe.js +0 -81
- package/dist/es/node_modules/zt-sockjs-client/lib/info-receiver.js +0 -101
- package/dist/es/node_modules/zt-sockjs-client/lib/location.js +0 -12
- package/dist/es/node_modules/zt-sockjs-client/lib/main.js +0 -413
- package/dist/es/node_modules/zt-sockjs-client/lib/shims.js +0 -449
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/websocket.js +0 -5
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/xhr.js +0 -80
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/eventsource.js +0 -34
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/htmlfile.js +0 -31
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/iframe.js +0 -154
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/jsonp-polling.js +0 -41
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/ajax-based.js +0 -55
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/buffered-sender.js +0 -92
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/iframe-wrap.js +0 -39
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/polling.js +0 -65
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/sender-receiver.js +0 -52
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/eventsource.js +0 -69
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/htmlfile.js +0 -96
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/jsonp.js +0 -193
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/xhr.js +0 -75
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/jsonp.js +0 -104
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xdr.js +0 -113
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-cors.js +0 -19
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-fake.js +0 -28
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-local.js +0 -21
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/websocket.js +0 -108
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-polling.js +0 -30
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-streaming.js +0 -38
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-polling.js +0 -40
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-streaming.js +0 -50
- package/dist/es/node_modules/zt-sockjs-client/lib/transport-list.js +0 -28
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/browser.js +0 -29
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/escape.js +0 -53
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/event.js +0 -78
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/iframe.js +0 -205
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/log.js +0 -20
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/object.js +0 -24
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/random.js +0 -30
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/transport.js +0 -52
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/url.js +0 -54
- package/dist/es/node_modules/zt-sockjs-client/lib/version.js +0 -11
- package/dist/es/node_modules/zt-stompjs/index.js +0 -23
- package/dist/es/node_modules/zt-stompjs/lib/stomp-node.js +0 -117
- package/dist/es/node_modules/zt-stompjs/lib/stomp.js +0 -536
- package/dist/es/stompClient.d.ts +0 -55
- package/dist/es/stompClient.js +0 -379
- package/src/stompClient.ts +0 -449
package/dist/es/stompClient.js
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import './node_modules/zt-stompjs/index.js';
|
|
2
|
-
import entry from './node_modules/zt-sockjs-client/lib/entry.js';
|
|
3
|
-
import { getToken } from './auth.js';
|
|
4
|
-
import { exports as ztStompjsExports } from './_virtual/index.js';
|
|
5
|
-
|
|
6
|
-
var StompClient = /** @class */ (function () {
|
|
7
|
-
function StompClient(connectWsConfig) {
|
|
8
|
-
this.isClient = false; // 是否连接上了
|
|
9
|
-
this.clearIsClient = null;
|
|
10
|
-
this.clearIsClientNo = null; // 连接10秒内未建立,重新连接
|
|
11
|
-
this.clearIsClientYes = null; // 连接已建立重新连接
|
|
12
|
-
this.subscriptions = {}; // 连接通道的返回值存储对象
|
|
13
|
-
this.subscriptionsFn = {}; // 连接通道的函数存储对象
|
|
14
|
-
this.successCallbacks = {}; // 连接成功执行的回调存储对象
|
|
15
|
-
this.errorCallbacks = {}; // 连接失败执行的回调存储对象
|
|
16
|
-
this.reconnectionNum = 0; // 重连次数
|
|
17
|
-
this.reconnectiontime = 5000; // 重连时间
|
|
18
|
-
this.maxReconnectiontime = 60000; // 最大重连时间 60s
|
|
19
|
-
this.userClose = false; // 是否用户主动关闭
|
|
20
|
-
this.isInit = false;
|
|
21
|
-
this.connectWsConfig = connectWsConfig;
|
|
22
|
-
}
|
|
23
|
-
// 连接初始化
|
|
24
|
-
StompClient.prototype.init = function () {
|
|
25
|
-
var _this = this;
|
|
26
|
-
var _a, _b, _c, _d;
|
|
27
|
-
this.isInit = true;
|
|
28
|
-
var token = this.connectWsConfig.token || getToken();
|
|
29
|
-
// 建立连接对象,还未发起连接
|
|
30
|
-
var socket = new entry("".concat(this.connectWsConfig.baseUrl, "/api/zmdms-csc-ztim/ws?token=").concat(token, "&system=").concat(this.connectWsConfig.systemType, "&clientType=").concat(this.connectWsConfig.clientType));
|
|
31
|
-
// 获取 STOMP 子协议的客户端对象
|
|
32
|
-
this.client = ztStompjsExports.over(socket);
|
|
33
|
-
this.isClient = false;
|
|
34
|
-
if (!this.subscriptions) {
|
|
35
|
-
this.subscriptions = {};
|
|
36
|
-
}
|
|
37
|
-
if (!this.subscriptionsFn) {
|
|
38
|
-
this.subscriptionsFn = {};
|
|
39
|
-
}
|
|
40
|
-
if (!this.successCallbacks) {
|
|
41
|
-
this.successCallbacks = {};
|
|
42
|
-
}
|
|
43
|
-
if (!this.errorCallbacks) {
|
|
44
|
-
this.errorCallbacks = {};
|
|
45
|
-
}
|
|
46
|
-
// 如果存在 证明已经初始化过,直接删除
|
|
47
|
-
if (this.clearIsClient) {
|
|
48
|
-
clearTimeout(this.clearIsClient);
|
|
49
|
-
this.clearIsClient = null;
|
|
50
|
-
}
|
|
51
|
-
if (this.clearIsClientNo) {
|
|
52
|
-
clearTimeout(this.clearIsClientNo);
|
|
53
|
-
this.clearIsClientNo = null;
|
|
54
|
-
}
|
|
55
|
-
if (this.clearIsClientYes) {
|
|
56
|
-
clearTimeout(this.clearIsClientYes);
|
|
57
|
-
this.clearIsClientYes = null;
|
|
58
|
-
}
|
|
59
|
-
this.clearIsClient = setTimeout(function () {
|
|
60
|
-
_this.clearIsClient = null;
|
|
61
|
-
if (!_this.isClient) {
|
|
62
|
-
console.log("\u8FDE\u63A5\u5DF2\u53D1\u8D77\uFF0C\u4F46\u662F10\u79D2\u540E\u672A\u6210\u529F\u5EFA\u7ACB\u8FDE\u63A5\uFF0C\u624B\u52A8\u65AD\u5F00\u91CD\u8FDE!system=".concat(_this.connectWsConfig.systemType));
|
|
63
|
-
try {
|
|
64
|
-
_this.client.disconnect(function () {
|
|
65
|
-
_this.client = null;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
console.log("---连接未建立的关闭出错---", err);
|
|
70
|
-
}
|
|
71
|
-
_this.reconnectionNum++;
|
|
72
|
-
var timeInterval = _this.getReconnectionTime();
|
|
73
|
-
console.log("---\u7B2C".concat(_this.reconnectionNum, "\u6B21\u91CD\u8FDE\uFF01time=").concat(Date.now(), "system=").concat(_this.connectWsConfig.systemType, "---"));
|
|
74
|
-
if (_this.clearIsClientNo) {
|
|
75
|
-
clearTimeout(_this.clearIsClientNo);
|
|
76
|
-
_this.clearIsClientNo = null;
|
|
77
|
-
}
|
|
78
|
-
_this.clearIsClientNo = setTimeout(function () {
|
|
79
|
-
_this.init();
|
|
80
|
-
}, timeInterval > _this.maxReconnectiontime
|
|
81
|
-
? _this.maxReconnectiontime
|
|
82
|
-
: timeInterval);
|
|
83
|
-
}
|
|
84
|
-
}, 10000);
|
|
85
|
-
// 拦截输出的一大堆垃圾信息
|
|
86
|
-
this.client.debug = null;
|
|
87
|
-
// if (this.connectWsConfig.debug) {
|
|
88
|
-
// this.client.debug = (str: string) => {
|
|
89
|
-
// if (this.connectWsConfig.debug) {
|
|
90
|
-
// console.log(str);
|
|
91
|
-
// }
|
|
92
|
-
// };
|
|
93
|
-
// }
|
|
94
|
-
// 心跳检测 stompjs 底层使用window.setInterval() 定期发送心跳检测
|
|
95
|
-
this.client.heartbeat.outgoing =
|
|
96
|
-
(_b = (_a = this.connectWsConfig.heartbeat) === null || _a === void 0 ? void 0 : _a.outgoing) !== null && _b !== void 0 ? _b : 2000; // 客户端将每2000ms发送一次心跳
|
|
97
|
-
this.client.heartbeat.incoming =
|
|
98
|
-
(_d = (_c = this.connectWsConfig.heartbeat) === null || _c === void 0 ? void 0 : _c.incoming) !== null && _d !== void 0 ? _d : 2000; // 客户端不希望从服务器接收心跳
|
|
99
|
-
this.client.connect({},
|
|
100
|
-
// 连接成功回调
|
|
101
|
-
function () {
|
|
102
|
-
_this.isClient = true;
|
|
103
|
-
if (_this.clearIsClient) {
|
|
104
|
-
clearTimeout(_this.clearIsClient);
|
|
105
|
-
_this.clearIsClient = null;
|
|
106
|
-
}
|
|
107
|
-
if (_this.clearIsClientNo) {
|
|
108
|
-
clearTimeout(_this.clearIsClientNo);
|
|
109
|
-
_this.clearIsClientNo = null;
|
|
110
|
-
}
|
|
111
|
-
if (_this.clearIsClientYes) {
|
|
112
|
-
clearTimeout(_this.clearIsClientYes);
|
|
113
|
-
_this.clearIsClientYes = null;
|
|
114
|
-
}
|
|
115
|
-
_this.reconnectionNum = 0;
|
|
116
|
-
console.log("---------\u8FDE\u63A5\u6210\u529F time=".concat(Date.now(), " system=").concat(_this.connectWsConfig.systemType, " time=").concat(Date.now(), "--------"));
|
|
117
|
-
_this.executeSubscribe();
|
|
118
|
-
},
|
|
119
|
-
// 连接失败回调
|
|
120
|
-
function (err) {
|
|
121
|
-
console.log("---------\u8FDE\u63A5\u5931\u8D25 system=".concat(_this.connectWsConfig.systemType, " time=").concat(Date.now(), "--------"));
|
|
122
|
-
console.log(err);
|
|
123
|
-
if (_this.userClose) {
|
|
124
|
-
_this.userClose = false; // 重新初始化 重新计算
|
|
125
|
-
if (_this.clearIsClient) {
|
|
126
|
-
clearTimeout(_this.clearIsClient);
|
|
127
|
-
_this.clearIsClient = null;
|
|
128
|
-
}
|
|
129
|
-
if (_this.clearIsClientNo) {
|
|
130
|
-
clearTimeout(_this.clearIsClientNo);
|
|
131
|
-
_this.clearIsClientNo = null;
|
|
132
|
-
}
|
|
133
|
-
if (_this.clearIsClientYes) {
|
|
134
|
-
clearTimeout(_this.clearIsClientYes);
|
|
135
|
-
_this.clearIsClientYes = null;
|
|
136
|
-
}
|
|
137
|
-
// 连接失败后,将所有注册过的订阅、回调执行状态置为未执行状态。
|
|
138
|
-
_this.setExecuteFail();
|
|
139
|
-
console.log("用户主动关闭");
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
_this.isClient = true;
|
|
143
|
-
if (_this.clearIsClient) {
|
|
144
|
-
clearTimeout(_this.clearIsClient);
|
|
145
|
-
_this.clearIsClient = null;
|
|
146
|
-
}
|
|
147
|
-
if (_this.clearIsClientNo) {
|
|
148
|
-
clearTimeout(_this.clearIsClientNo);
|
|
149
|
-
_this.clearIsClientNo = null;
|
|
150
|
-
}
|
|
151
|
-
if (_this.clearIsClientYes) {
|
|
152
|
-
clearTimeout(_this.clearIsClientYes);
|
|
153
|
-
_this.clearIsClientYes = null;
|
|
154
|
-
}
|
|
155
|
-
// 连接失败后,将所有注册过的订阅、回调执行状态置为未执行状态。
|
|
156
|
-
_this.setExecuteFail();
|
|
157
|
-
// 重连逻辑, 默认3秒后重连
|
|
158
|
-
// 重连间隔,每隔5秒递增,超过最大间隔时间后,取最大间隔时间重连
|
|
159
|
-
try {
|
|
160
|
-
_this.client.disconnect(function () {
|
|
161
|
-
_this.client = null;
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
console.log("---\u8FDE\u63A5\u5DF2\u5EFA\u7ACB\u7684\u5173\u95ED\u51FA\u9519 time=".concat(Date.now(), "system=").concat(_this.connectWsConfig.systemType, "---"), err);
|
|
166
|
-
}
|
|
167
|
-
_this.reconnectionNum++;
|
|
168
|
-
var timeInterval = _this.getReconnectionTime();
|
|
169
|
-
console.log("---\u7B2C".concat(_this.reconnectionNum, "\u6B21\u91CD\u8FDE\uFF01time=").concat(Date.now(), "system=").concat(_this.connectWsConfig.systemType));
|
|
170
|
-
_this.clearIsClientYes = setTimeout(function () {
|
|
171
|
-
_this.init();
|
|
172
|
-
}, timeInterval > _this.maxReconnectiontime
|
|
173
|
-
? _this.maxReconnectiontime
|
|
174
|
-
: timeInterval);
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* 连接失败后,将所有注册过的订阅、回调执行状态置为未执行状态。
|
|
179
|
-
* @param isExecute 连接通道、回调的执行状态
|
|
180
|
-
*/
|
|
181
|
-
StompClient.prototype.setExecuteFail = function () {
|
|
182
|
-
var _this = this;
|
|
183
|
-
// 连接失败后,将当前已注册的 连接通道 全部置为未执行状态
|
|
184
|
-
var subscriptionsFnKeys = Object.keys(this.subscriptionsFn);
|
|
185
|
-
if (Array.isArray(subscriptionsFnKeys)) {
|
|
186
|
-
subscriptionsFnKeys.forEach(function (key) {
|
|
187
|
-
_this.subscriptionsFn[key].isExecute = false;
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
// 连接失败后,统一执行连接失败函数
|
|
191
|
-
var errorCallbackKeys = Object.keys(this.errorCallbacks);
|
|
192
|
-
if (Array.isArray(errorCallbackKeys)) {
|
|
193
|
-
errorCallbackKeys.forEach(function (key) {
|
|
194
|
-
var _a = _this.errorCallbacks[key], isExecute = _a.isExecute, callback = _a.callback;
|
|
195
|
-
if (!isExecute) {
|
|
196
|
-
callback && callback();
|
|
197
|
-
}
|
|
198
|
-
_this.errorCallbacks[key].isExecute = true;
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
// 将成功回调 的执行状态 重置为未执行状态
|
|
202
|
-
var successCallbackKeys = Object.keys(this.successCallbacks);
|
|
203
|
-
if (Array.isArray(successCallbackKeys)) {
|
|
204
|
-
successCallbackKeys.forEach(function (key) {
|
|
205
|
-
_this.successCallbacks[key].isExecute = false;
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* 连接成功后,需要将当前已注册的,未执行的连接通道重新执行连接
|
|
211
|
-
* 还有成功回调
|
|
212
|
-
* 失败回调的执行状态重置为未执行状态
|
|
213
|
-
* @returns 执行订阅相关回调
|
|
214
|
-
*/
|
|
215
|
-
StompClient.prototype.executeSubscribe = function () {
|
|
216
|
-
var _this = this;
|
|
217
|
-
// 连接成功后,将当前已注册的,未执行的 连接通道 连接
|
|
218
|
-
var subscriptionsFnKeys = Object.keys(this.subscriptionsFn);
|
|
219
|
-
if (Array.isArray(subscriptionsFnKeys)) {
|
|
220
|
-
subscriptionsFnKeys.forEach(function (key) {
|
|
221
|
-
var _a = _this.subscriptionsFn[key], isExecute = _a.isExecute, subscriptionsFn = _a.subscriptionsFn;
|
|
222
|
-
if (!isExecute) {
|
|
223
|
-
subscriptionsFn === null || subscriptionsFn === void 0 ? void 0 : subscriptionsFn();
|
|
224
|
-
_this.subscriptionsFn[key].isExecute = true;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
// 连接成功后,统一执行连接成功函数
|
|
229
|
-
var successCallbackKeys = Object.keys(this.successCallbacks);
|
|
230
|
-
if (Array.isArray(successCallbackKeys)) {
|
|
231
|
-
successCallbackKeys.forEach(function (key) {
|
|
232
|
-
var _a = _this.successCallbacks[key], isExecute = _a.isExecute, callback = _a.callback;
|
|
233
|
-
if (!isExecute) {
|
|
234
|
-
callback && callback();
|
|
235
|
-
}
|
|
236
|
-
_this.successCallbacks[key].isExecute = true;
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
// 将失败回调 的执行状态 重置为未执行状态
|
|
240
|
-
var errorCallbackKeys = Object.keys(this.errorCallbacks);
|
|
241
|
-
if (Array.isArray(errorCallbackKeys)) {
|
|
242
|
-
errorCallbackKeys.forEach(function (key) {
|
|
243
|
-
_this.errorCallbacks[key].isExecute = false;
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
// 重连时间计算
|
|
248
|
-
StompClient.prototype.getReconnectionTime = function () {
|
|
249
|
-
var _a;
|
|
250
|
-
var timeInterval = Math.ceil(this.reconnectionNum / 5) *
|
|
251
|
-
((_a = this.connectWsConfig.reconnectionTime) !== null && _a !== void 0 ? _a : this.reconnectiontime);
|
|
252
|
-
return timeInterval;
|
|
253
|
-
};
|
|
254
|
-
// 订阅连接成功回调
|
|
255
|
-
StompClient.prototype.subscribeSuccessCall = function (subscribeId, callback) {
|
|
256
|
-
this.successCallbacks[subscribeId] = {
|
|
257
|
-
isExecute: false,
|
|
258
|
-
callback: callback,
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
|
-
// 订阅连接失败回调
|
|
262
|
-
StompClient.prototype.subscribeErrorCall = function (subscribeId, callback) {
|
|
263
|
-
this.errorCallbacks[subscribeId] = {
|
|
264
|
-
isExecute: false,
|
|
265
|
-
callback: callback,
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
// 订阅通道逻辑
|
|
269
|
-
StompClient.prototype.subscribe = function (subscribeId, pipe, callback, headers) {
|
|
270
|
-
var _this = this;
|
|
271
|
-
var _a;
|
|
272
|
-
// 兼容不传callback 的方案
|
|
273
|
-
if (typeof callback !== "function") {
|
|
274
|
-
headers = callback;
|
|
275
|
-
callback = undefined;
|
|
276
|
-
}
|
|
277
|
-
var subscriptionsFn = function () {
|
|
278
|
-
if (_this.client) {
|
|
279
|
-
var subscription = _this.client.subscribe(pipe, function (response) {
|
|
280
|
-
callback && callback(response);
|
|
281
|
-
}, headers);
|
|
282
|
-
_this.subscriptions[subscribeId] = subscription;
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
if ((_a = this.client) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
286
|
-
// 如果是连接状态 正常执行函数
|
|
287
|
-
subscriptionsFn();
|
|
288
|
-
// 是否已执行
|
|
289
|
-
this.subscriptionsFn[subscribeId] = {
|
|
290
|
-
isExecute: true,
|
|
291
|
-
subscriptionsFn: subscriptionsFn,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
// 缓存连接函数
|
|
296
|
-
this.subscriptionsFn[subscribeId] = {
|
|
297
|
-
isExecute: false,
|
|
298
|
-
subscriptionsFn: subscriptionsFn,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
StompClient.prototype.getSubscriptions = function (key) {
|
|
303
|
-
var subscriptionKey = this.subscriptions[key];
|
|
304
|
-
Reflect.deleteProperty(this.subscriptions, key);
|
|
305
|
-
Reflect.deleteProperty(this.subscriptionsFn, key);
|
|
306
|
-
return subscriptionKey;
|
|
307
|
-
};
|
|
308
|
-
// 关闭连接逻辑
|
|
309
|
-
StompClient.prototype.disconnect = function (callback) {
|
|
310
|
-
var _this = this;
|
|
311
|
-
this.isInit = false;
|
|
312
|
-
this.userClose = true;
|
|
313
|
-
this.subscriptions = null;
|
|
314
|
-
this.subscriptionsFn = null;
|
|
315
|
-
this.successCallbacks = null;
|
|
316
|
-
this.errorCallbacks = null;
|
|
317
|
-
return new Promise(function (resolve, reject) {
|
|
318
|
-
try {
|
|
319
|
-
_this.client.disconnect(function () {
|
|
320
|
-
_this.client = null;
|
|
321
|
-
callback && callback();
|
|
322
|
-
resolve(null);
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
catch (err) {
|
|
326
|
-
callback && callback();
|
|
327
|
-
resolve(null);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
// 手动重新连接
|
|
332
|
-
StompClient.prototype.reconnect = function () {
|
|
333
|
-
var _this = this;
|
|
334
|
-
this.isInit = false;
|
|
335
|
-
this.userClose = true;
|
|
336
|
-
return new Promise(function (resolve, reject) {
|
|
337
|
-
try {
|
|
338
|
-
_this.setExecuteFail();
|
|
339
|
-
_this.client.disconnect(function () {
|
|
340
|
-
_this.client = null;
|
|
341
|
-
resolve(null);
|
|
342
|
-
});
|
|
343
|
-
setTimeout(function () {
|
|
344
|
-
_this.userClose = false;
|
|
345
|
-
_this.init();
|
|
346
|
-
}, 400);
|
|
347
|
-
}
|
|
348
|
-
catch (err) {
|
|
349
|
-
resolve(null);
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
};
|
|
353
|
-
// 发送消息
|
|
354
|
-
StompClient.prototype.send = function (pipe, headers, message) {
|
|
355
|
-
if (typeof headers === "string") {
|
|
356
|
-
message = headers;
|
|
357
|
-
headers = {};
|
|
358
|
-
}
|
|
359
|
-
this.client.send(pipe, headers, message);
|
|
360
|
-
};
|
|
361
|
-
return StompClient;
|
|
362
|
-
}());
|
|
363
|
-
StompClient.getInstance = (function () {
|
|
364
|
-
var instance;
|
|
365
|
-
return function (connectWsConfig) {
|
|
366
|
-
if (!instance && connectWsConfig) {
|
|
367
|
-
instance = new StompClient(connectWsConfig);
|
|
368
|
-
// ws 初始化
|
|
369
|
-
instance.init();
|
|
370
|
-
}
|
|
371
|
-
// 如果没有初始化,那么初始化一下
|
|
372
|
-
if (instance && !instance.isInit) {
|
|
373
|
-
instance.init();
|
|
374
|
-
}
|
|
375
|
-
return instance;
|
|
376
|
-
};
|
|
377
|
-
})();
|
|
378
|
-
|
|
379
|
-
export { StompClient as default };
|