ztxkutils 2.10.31 → 2.10.32

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.
@@ -24,6 +24,7 @@ declare class StompClient {
24
24
  successCallbacks: any;
25
25
  errorCallbacks: any;
26
26
  reconnectionNum: number;
27
+ userClose: boolean;
27
28
  isInit: boolean;
28
29
  constructor(connectWsConfig: IConnectWsConfig);
29
30
  init(): void;
@@ -13,6 +13,7 @@ var StompClient = /** @class */ (function () {
13
13
  this.successCallbacks = {}; // 连接成功执行的回调存储对象
14
14
  this.errorCallbacks = {}; // 连接失败执行的回调存储对象
15
15
  this.reconnectionNum = 0; // 重连次数
16
+ this.userClose = false; // 是否用户主动关闭
16
17
  this.isInit = false;
17
18
  this.connectWsConfig = connectWsConfig;
18
19
  }
@@ -27,6 +28,7 @@ var StompClient = /** @class */ (function () {
27
28
  // 获取 STOMP 子协议的客户端对象
28
29
  this.client = Stomp.over(socket);
29
30
  this.isClient = false;
31
+ this.userClose = false; // 重新初始化 重新计算
30
32
  // 如果存在 证明已经初始化过,直接删除
31
33
  if (this.clearIsClient) {
32
34
  clearTimeout(this.clearIsClient);
@@ -129,6 +131,22 @@ var StompClient = /** @class */ (function () {
129
131
  function (err) {
130
132
  console.log("---------\u8FDE\u63A5\u5931\u8D25 system=" + _this.connectWsConfig.systemType + " time=" + Date.now() + "--------");
131
133
  console.log(err);
134
+ if (_this.userClose) {
135
+ if (_this.clearIsClient) {
136
+ clearTimeout(_this.clearIsClient);
137
+ _this.clearIsClient = null;
138
+ }
139
+ if (_this.clearIsClientNo) {
140
+ clearTimeout(_this.clearIsClientNo);
141
+ _this.clearIsClientNo = null;
142
+ }
143
+ if (_this.clearIsClientYes) {
144
+ clearTimeout(_this.clearIsClientYes);
145
+ _this.clearIsClientYes = null;
146
+ }
147
+ console.log('用户主动关闭');
148
+ return;
149
+ }
132
150
  _this.isClient = true;
133
151
  if (_this.clearIsClient) {
134
152
  clearTimeout(_this.clearIsClient);
@@ -247,43 +265,28 @@ var StompClient = /** @class */ (function () {
247
265
  StompClient.prototype.disconnect = function (callback) {
248
266
  var _this = this;
249
267
  this.isInit = false;
268
+ this.userClose = true;
269
+ if (this.clearIsClient) {
270
+ clearTimeout(this.clearIsClient);
271
+ this.clearIsClient = null;
272
+ }
273
+ if (this.clearIsClientNo) {
274
+ clearTimeout(this.clearIsClientNo);
275
+ this.clearIsClientNo = null;
276
+ }
277
+ if (this.clearIsClientYes) {
278
+ clearTimeout(this.clearIsClientYes);
279
+ this.clearIsClientYes = null;
280
+ }
250
281
  return new Promise(function (resolve, reject) {
251
282
  try {
252
283
  _this.client.disconnect(function () {
253
284
  _this.client = null;
254
- setTimeout(function () {
255
- if (_this.clearIsClient) {
256
- clearTimeout(_this.clearIsClient);
257
- _this.clearIsClient = null;
258
- }
259
- if (_this.clearIsClientNo) {
260
- clearTimeout(_this.clearIsClientNo);
261
- _this.clearIsClientNo = null;
262
- }
263
- if (_this.clearIsClientYes) {
264
- clearTimeout(_this.clearIsClientYes);
265
- _this.clearIsClientYes = null;
266
- }
267
- }, 300);
268
285
  callback && callback();
269
286
  resolve(null);
270
287
  });
271
288
  }
272
289
  catch (err) {
273
- setTimeout(function () {
274
- if (_this.clearIsClient) {
275
- clearTimeout(_this.clearIsClient);
276
- _this.clearIsClient = null;
277
- }
278
- if (_this.clearIsClientNo) {
279
- clearTimeout(_this.clearIsClientNo);
280
- _this.clearIsClientNo = null;
281
- }
282
- if (_this.clearIsClientYes) {
283
- clearTimeout(_this.clearIsClientYes);
284
- _this.clearIsClientYes = null;
285
- }
286
- }, 300);
287
290
  callback && callback();
288
291
  resolve(null);
289
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.31",
3
+ "version": "2.10.32",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",