ztxkutils 2.7.9 → 2.7.12

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,26 +32,41 @@ 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!");
35
+ if (this.clearIsClientNo) {
36
+ clearTimeout(this.clearIsClientNo);
37
+ this.clearIsClientNo = null;
38
+ }
39
+ if (this.clearIsClientYes) {
40
+ clearTimeout(this.clearIsClientYes);
41
+ this.clearIsClientYes = null;
42
+ }
43
+ this.clearIsClient = setTimeout(function () {
44
+ _this.clearIsClient = null;
45
+ if (!_this.isClient) {
46
+ 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!");
47
+ try {
38
48
  _this.client.disconnect(function () {
39
49
  // const timeInterval =
40
50
  // Math.ceil(this.reconnectionNum / 5) *
41
51
  // (this.connectWsConfig.reconnectionTime ?? 3000);
42
52
  });
43
- _this.client = null;
44
- _this.reconnectionNum++;
45
- var timeInterval = 3000;
46
- console.log("\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
47
- setTimeout(function () {
48
- _this.init();
49
- }, timeInterval > 10000 ? 10000 : timeInterval);
50
53
  }
51
- }, 20000);
52
- }
54
+ catch (err) {
55
+ console.log('---连接未建立的关闭出错---', err);
56
+ }
57
+ _this.client = null;
58
+ _this.reconnectionNum++;
59
+ var timeInterval = 3000;
60
+ console.log("---\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01---");
61
+ if (_this.clearIsClientNo) {
62
+ clearTimeout(_this.clearIsClientNo);
63
+ _this.clearIsClientNo = null;
64
+ }
65
+ _this.clearIsClientNo = setTimeout(function () {
66
+ _this.init();
67
+ }, timeInterval > 10000 ? 10000 : timeInterval);
68
+ }
69
+ }, 10000);
53
70
  // 拦截输出的一大堆垃圾信息
54
71
  this.client.debug = function (str) {
55
72
  if (_this.connectWsConfig.debug) {
@@ -69,6 +86,14 @@ var StompClient = /** @class */ (function () {
69
86
  clearTimeout(_this.clearIsClient);
70
87
  _this.clearIsClient = null;
71
88
  }
89
+ if (_this.clearIsClientNo) {
90
+ clearTimeout(_this.clearIsClientNo);
91
+ _this.clearIsClientNo = null;
92
+ }
93
+ if (_this.clearIsClientYes) {
94
+ clearTimeout(_this.clearIsClientYes);
95
+ _this.clearIsClientYes = null;
96
+ }
72
97
  _this.reconnectionNum = 0;
73
98
  console.log('---------连接成功--------');
74
99
  // 连接成功后,将当前已注册的,未执行的 连接通道 连接
@@ -110,6 +135,14 @@ var StompClient = /** @class */ (function () {
110
135
  clearTimeout(_this.clearIsClient);
111
136
  _this.clearIsClient = null;
112
137
  }
138
+ if (_this.clearIsClientNo) {
139
+ clearTimeout(_this.clearIsClientNo);
140
+ _this.clearIsClientNo = null;
141
+ }
142
+ if (_this.clearIsClientYes) {
143
+ clearTimeout(_this.clearIsClientYes);
144
+ _this.clearIsClientYes = null;
145
+ }
113
146
  // this.errorCallback(err);
114
147
  // 连接失败后,将当前已注册的 连接通道 全部置为未执行状态
115
148
  var subscriptionsFnKeys = Object.keys(_this.subscriptionsFn);
@@ -138,18 +171,26 @@ var StompClient = /** @class */ (function () {
138
171
  }
139
172
  // 重连逻辑, 默认3秒后重连
140
173
  // 重连间隔,每隔5秒递增,超过最大间隔时间后,取最大间隔时间重连
141
- _this.client.disconnect(function () {
142
- _this.client = null;
143
- _this.reconnectionNum++;
144
- // const timeInterval =
145
- // Math.ceil(this.reconnectionNum / 5) *
146
- // (this.connectWsConfig.reconnectionTime ?? 3000);
147
- var timeInterval = 3000;
148
- console.log("\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
149
- setTimeout(function () {
150
- _this.init();
151
- }, timeInterval);
152
- });
174
+ try {
175
+ _this.client.disconnect(function () {
176
+ // const timeInterval =
177
+ // Math.ceil(this.reconnectionNum / 5) *
178
+ // (this.connectWsConfig.reconnectionTime ?? 3000);
179
+ });
180
+ }
181
+ catch (err) {
182
+ console.log('---连接已建立的关闭出错---', err);
183
+ }
184
+ _this.client = null;
185
+ _this.reconnectionNum++;
186
+ // const timeInterval =
187
+ // Math.ceil(this.reconnectionNum / 5) *
188
+ // (this.connectWsConfig.reconnectionTime ?? 3000);
189
+ var timeInterval = 3000;
190
+ console.log("---\u7B2C" + _this.reconnectionNum + "\u6B21\u91CD\u8FDE\uFF01");
191
+ _this.clearIsClientYes = setTimeout(function () {
192
+ _this.init();
193
+ }, timeInterval);
153
194
  });
154
195
  };
155
196
  // 订阅连接成功回调
@@ -209,11 +250,17 @@ var StompClient = /** @class */ (function () {
209
250
  var _this = this;
210
251
  this.isInit = false;
211
252
  return new Promise(function (resolve, reject) {
212
- _this.client.disconnect(function () {
213
- _this.client = null;
253
+ try {
254
+ _this.client.disconnect(function () {
255
+ _this.client = null;
256
+ callback && callback();
257
+ resolve(null);
258
+ });
259
+ }
260
+ catch (err) {
214
261
  callback && callback();
215
262
  resolve(null);
216
- });
263
+ }
217
264
  });
218
265
  };
219
266
  // 发送消息
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.7.9",
3
+ "version": "2.7.12",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",