ztxkutils 2.7.8 → 2.7.11
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/stompClient.d.ts +2 -0
- package/dist/stompClient.js +50 -27
- package/package.json +1 -1
package/dist/stompClient.d.ts
CHANGED
package/dist/stompClient.js
CHANGED
@@ -6,6 +6,8 @@ var StompClient = /** @class */ (function () {
|
|
6
6
|
function StompClient(connectWsConfig) {
|
7
7
|
this.isClient = false; // 是否连接上了
|
8
8
|
this.clearIsClient = null;
|
9
|
+
this.clearIsClientNo = null; // 连接10秒内未建立,重新连接
|
10
|
+
this.clearIsClientYes = null; // 连接已建立重新连接
|
9
11
|
this.subscriptions = {}; // 连接通道的返回值存储对象
|
10
12
|
this.subscriptionsFn = {}; // 连接通道的函数存储对象
|
11
13
|
this.successCallbacks = {}; // 连接成功执行的回调存储对象
|
@@ -25,27 +27,34 @@ var StompClient = /** @class */ (function () {
|
|
25
27
|
// 获取 STOMP 子协议的客户端对象
|
26
28
|
this.client = Stomp.over(socket);
|
27
29
|
this.isClient = false;
|
30
|
+
// 如果存在 证明已经初始化过,直接删除
|
28
31
|
if (this.clearIsClient) {
|
29
32
|
clearTimeout(this.clearIsClient);
|
30
33
|
this.clearIsClient = null;
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
}
|
35
|
+
this.clearIsClient = setTimeout(function () {
|
36
|
+
_this.clearIsClient = null;
|
37
|
+
if (!_this.isClient) {
|
38
|
+
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!");
|
39
|
+
try {
|
34
40
|
_this.client.disconnect(function () {
|
35
41
|
// const timeInterval =
|
36
42
|
// Math.ceil(this.reconnectionNum / 5) *
|
37
43
|
// (this.connectWsConfig.reconnectionTime ?? 3000);
|
38
44
|
});
|
39
|
-
_this.client = null;
|
40
|
-
_this.reconnectionNum++;
|
41
|
-
var timeInterval = 3000;
|
42
|
-
console.log("\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
|
43
|
-
setTimeout(function () {
|
44
|
-
_this.init();
|
45
|
-
}, timeInterval > 10000 ? 10000 : timeInterval);
|
46
45
|
}
|
47
|
-
|
48
|
-
|
46
|
+
catch (err) {
|
47
|
+
console.log('---连接未建立的关闭出错---', err);
|
48
|
+
}
|
49
|
+
_this.client = null;
|
50
|
+
_this.reconnectionNum++;
|
51
|
+
var timeInterval = 3000;
|
52
|
+
console.log("---\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01---");
|
53
|
+
setTimeout(function () {
|
54
|
+
_this.init();
|
55
|
+
}, timeInterval > 10000 ? 10000 : timeInterval);
|
56
|
+
}
|
57
|
+
}, 10000);
|
49
58
|
// 拦截输出的一大堆垃圾信息
|
50
59
|
this.client.debug = function (str) {
|
51
60
|
if (_this.connectWsConfig.debug) {
|
@@ -134,18 +143,26 @@ var StompClient = /** @class */ (function () {
|
|
134
143
|
}
|
135
144
|
// 重连逻辑, 默认3秒后重连
|
136
145
|
// 重连间隔,每隔5秒递增,超过最大间隔时间后,取最大间隔时间重连
|
137
|
-
|
138
|
-
_this.client
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
try {
|
147
|
+
_this.client.disconnect(function () {
|
148
|
+
// const timeInterval =
|
149
|
+
// Math.ceil(this.reconnectionNum / 5) *
|
150
|
+
// (this.connectWsConfig.reconnectionTime ?? 3000);
|
151
|
+
});
|
152
|
+
}
|
153
|
+
catch (err) {
|
154
|
+
console.log('---连接已建立的关闭出错---', err);
|
155
|
+
}
|
156
|
+
_this.client = null;
|
157
|
+
_this.reconnectionNum++;
|
158
|
+
// const timeInterval =
|
159
|
+
// Math.ceil(this.reconnectionNum / 5) *
|
160
|
+
// (this.connectWsConfig.reconnectionTime ?? 3000);
|
161
|
+
var timeInterval = 3000;
|
162
|
+
console.log("---\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
|
163
|
+
setTimeout(function () {
|
164
|
+
_this.init();
|
165
|
+
}, timeInterval);
|
149
166
|
});
|
150
167
|
};
|
151
168
|
// 订阅连接成功回调
|
@@ -205,11 +222,17 @@ var StompClient = /** @class */ (function () {
|
|
205
222
|
var _this = this;
|
206
223
|
this.isInit = false;
|
207
224
|
return new Promise(function (resolve, reject) {
|
208
|
-
|
209
|
-
_this.client
|
225
|
+
try {
|
226
|
+
_this.client.disconnect(function () {
|
227
|
+
_this.client = null;
|
228
|
+
callback && callback();
|
229
|
+
resolve(null);
|
230
|
+
});
|
231
|
+
}
|
232
|
+
catch (err) {
|
210
233
|
callback && callback();
|
211
234
|
resolve(null);
|
212
|
-
}
|
235
|
+
}
|
213
236
|
});
|
214
237
|
};
|
215
238
|
// 发送消息
|