ztxkutils 2.7.10 → 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.
@@ -17,6 +17,8 @@ declare class StompClient {
17
17
  client: any;
18
18
  isClient: any;
19
19
  clearIsClient: any;
20
+ clearIsClientNo: any;
21
+ clearIsClientYes: any;
20
22
  subscriptions: any;
21
23
  subscriptionsFn: any;
22
24
  successCallbacks: any;
@@ -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 = {}; // 连接成功执行的回调存储对象
@@ -30,31 +32,29 @@ var StompClient = /** @class */ (function () {
30
32
  clearTimeout(this.clearIsClient);
31
33
  this.clearIsClient = null;
32
34
  }
33
- if (!this.clearIsClient) {
34
- this.clearIsClient = setTimeout(function () {
35
- _this.clearIsClient = null;
36
- if (!_this.isClient) {
37
- 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!");
38
- try {
39
- _this.client.disconnect(function () {
40
- // const timeInterval =
41
- // Math.ceil(this.reconnectionNum / 5) *
42
- // (this.connectWsConfig.reconnectionTime ?? 3000);
43
- });
44
- }
45
- catch (err) {
46
- console.log('---关闭出错---', err);
47
- }
48
- _this.client = null;
49
- _this.reconnectionNum++;
50
- var timeInterval = 3000;
51
- console.log("\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
52
- setTimeout(function () {
53
- _this.init();
54
- }, timeInterval > 10000 ? 10000 : timeInterval);
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 {
40
+ _this.client.disconnect(function () {
41
+ // const timeInterval =
42
+ // Math.ceil(this.reconnectionNum / 5) *
43
+ // (this.connectWsConfig.reconnectionTime ?? 3000);
44
+ });
55
45
  }
56
- }, 20000);
57
- }
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);
58
58
  // 拦截输出的一大堆垃圾信息
59
59
  this.client.debug = function (str) {
60
60
  if (_this.connectWsConfig.debug) {
@@ -143,18 +143,26 @@ var StompClient = /** @class */ (function () {
143
143
  }
144
144
  // 重连逻辑, 默认3秒后重连
145
145
  // 重连间隔,每隔5秒递增,超过最大间隔时间后,取最大间隔时间重连
146
- _this.client.disconnect(function () {
147
- _this.client = null;
148
- _this.reconnectionNum++;
149
- // const timeInterval =
150
- // Math.ceil(this.reconnectionNum / 5) *
151
- // (this.connectWsConfig.reconnectionTime ?? 3000);
152
- var timeInterval = 3000;
153
- console.log("\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
154
- setTimeout(function () {
155
- _this.init();
156
- }, timeInterval);
157
- });
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);
158
166
  });
159
167
  };
160
168
  // 订阅连接成功回调
@@ -214,11 +222,17 @@ var StompClient = /** @class */ (function () {
214
222
  var _this = this;
215
223
  this.isInit = false;
216
224
  return new Promise(function (resolve, reject) {
217
- _this.client.disconnect(function () {
218
- _this.client = null;
225
+ try {
226
+ _this.client.disconnect(function () {
227
+ _this.client = null;
228
+ callback && callback();
229
+ resolve(null);
230
+ });
231
+ }
232
+ catch (err) {
219
233
  callback && callback();
220
234
  resolve(null);
221
- });
235
+ }
222
236
  });
223
237
  };
224
238
  // 发送消息
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.7.10",
3
+ "version": "2.7.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",