zmdms-utils 0.0.80 → 0.0.81

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.
Files changed (165) hide show
  1. package/declarations.d.ts +6 -0
  2. package/dist/es/_virtual/FastBufferList.js +7 -0
  3. package/dist/es/_virtual/_commonjs-dynamic-modules.js +5 -0
  4. package/dist/es/_virtual/browser.js +7 -0
  5. package/dist/es/_virtual/browser2.js +7 -0
  6. package/dist/es/_virtual/debug.js +7 -0
  7. package/dist/es/_virtual/event.js +7 -0
  8. package/dist/es/_virtual/http-parser.js +3 -0
  9. package/dist/es/_virtual/iframe.js +7 -0
  10. package/dist/es/_virtual/index.js +7 -0
  11. package/dist/es/_virtual/index2.js +7 -0
  12. package/dist/es/_virtual/index3.js +7 -0
  13. package/dist/es/_virtual/index4.js +7 -0
  14. package/dist/es/_virtual/index5.js +7 -0
  15. package/dist/es/_virtual/index6.js +7 -0
  16. package/dist/es/_virtual/index7.js +3 -0
  17. package/dist/es/_virtual/index8.js +7 -0
  18. package/dist/es/_virtual/index9.js +7 -0
  19. package/dist/es/_virtual/inherits.js +7 -0
  20. package/dist/es/_virtual/inherits_browser.js +7 -0
  21. package/dist/es/_virtual/json3.js +7 -0
  22. package/dist/es/_virtual/node.js +7 -0
  23. package/dist/es/_virtual/node2.js +7 -0
  24. package/dist/es/_virtual/stomp-node.js +3 -0
  25. package/dist/es/_virtual/stomp.js +3 -0
  26. package/dist/es/_virtual/streams.js +3 -0
  27. package/dist/es/_virtual/utils.js +3 -0
  28. package/dist/es/constants.d.ts +5 -1
  29. package/dist/es/constants.js +5 -1
  30. package/dist/es/node_modules/bufferutil/fallback.js +43 -0
  31. package/dist/es/node_modules/bufferutil/index.js +21 -0
  32. package/dist/es/node_modules/debug/src/browser.js +192 -0
  33. package/dist/es/node_modules/debug/src/common.js +259 -0
  34. package/dist/es/node_modules/debug/src/index.js +25 -0
  35. package/dist/es/node_modules/debug/src/node.js +192 -0
  36. package/dist/es/node_modules/eventsource/lib/eventsource.js +493 -0
  37. package/dist/es/node_modules/faye-websocket/lib/faye/eventsource.js +150 -0
  38. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event.js +31 -0
  39. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js +41 -0
  40. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api.js +205 -0
  41. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/client.js +107 -0
  42. package/dist/es/node_modules/faye-websocket/lib/faye/websocket.js +47 -0
  43. package/dist/es/node_modules/has-flag/index.js +17 -0
  44. package/dist/es/node_modules/http-parser-js/http-parser.js +471 -0
  45. package/dist/es/node_modules/inherits/inherits.js +14 -0
  46. package/dist/es/node_modules/inherits/inherits_browser.js +38 -0
  47. package/dist/es/node_modules/is-typedarray/index.js +51 -0
  48. package/dist/es/node_modules/json3/lib/json3.js +937 -0
  49. package/dist/es/node_modules/ms/index.js +172 -0
  50. package/dist/es/node_modules/node-gyp-build/index.js +21 -0
  51. package/dist/es/node_modules/node-gyp-build/node-gyp-build.js +222 -0
  52. package/dist/es/node_modules/querystringify/index.js +120 -0
  53. package/dist/es/node_modules/requires-port/index.js +38 -0
  54. package/dist/es/node_modules/safe-buffer/index.js +71 -0
  55. package/dist/es/node_modules/supports-color/index.js +143 -0
  56. package/dist/es/node_modules/typedarray-to-buffer/index.js +37 -0
  57. package/dist/es/node_modules/url-parse/index.js +594 -0
  58. package/dist/es/node_modules/utf-8-validate/fallback.js +71 -0
  59. package/dist/es/node_modules/utf-8-validate/index.js +21 -0
  60. package/dist/es/node_modules/websocket/index.js +15 -0
  61. package/dist/es/node_modules/websocket/lib/Deprecation.js +42 -0
  62. package/dist/es/node_modules/websocket/lib/W3CWebSocket.js +268 -0
  63. package/dist/es/node_modules/websocket/lib/WebSocketClient.js +380 -0
  64. package/dist/es/node_modules/websocket/lib/WebSocketConnection.js +914 -0
  65. package/dist/es/node_modules/websocket/lib/WebSocketFrame.js +293 -0
  66. package/dist/es/node_modules/websocket/lib/WebSocketRequest.js +543 -0
  67. package/dist/es/node_modules/websocket/lib/WebSocketRouter.js +172 -0
  68. package/dist/es/node_modules/websocket/lib/WebSocketRouterRequest.js +67 -0
  69. package/dist/es/node_modules/websocket/lib/WebSocketServer.js +272 -0
  70. package/dist/es/node_modules/websocket/lib/utils.js +80 -0
  71. package/dist/es/node_modules/websocket/lib/version.js +13 -0
  72. package/dist/es/node_modules/websocket/lib/websocket.js +31 -0
  73. package/dist/es/node_modules/websocket/node_modules/debug/src/browser.js +199 -0
  74. package/dist/es/node_modules/websocket/node_modules/debug/src/debug.js +215 -0
  75. package/dist/es/node_modules/websocket/node_modules/debug/src/index.js +25 -0
  76. package/dist/es/node_modules/websocket/node_modules/debug/src/node.js +266 -0
  77. package/dist/es/node_modules/websocket/node_modules/ms/index.js +162 -0
  78. package/dist/es/node_modules/websocket/package.json.js +77 -0
  79. package/dist/es/node_modules/websocket/vendor/FastBufferList.js +205 -0
  80. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/base.js +202 -0
  81. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/client.js +152 -0
  82. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft75.js +128 -0
  83. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft76.js +124 -0
  84. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/headers.js +44 -0
  85. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/frame.js +21 -0
  86. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/message.js +37 -0
  87. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi.js +492 -0
  88. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/proxy.js +108 -0
  89. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/server.js +119 -0
  90. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/stream_reader.js +72 -0
  91. package/dist/es/node_modules/websocket-driver/lib/websocket/driver.js +47 -0
  92. package/dist/es/node_modules/websocket-driver/lib/websocket/http_parser.js +140 -0
  93. package/dist/es/node_modules/websocket-driver/lib/websocket/streams.js +150 -0
  94. package/dist/es/node_modules/websocket-extensions/lib/parser.js +103 -0
  95. package/dist/es/node_modules/websocket-extensions/lib/pipeline/cell.js +56 -0
  96. package/dist/es/node_modules/websocket-extensions/lib/pipeline/functor.js +74 -0
  97. package/dist/es/node_modules/websocket-extensions/lib/pipeline/index.js +50 -0
  98. package/dist/es/node_modules/websocket-extensions/lib/pipeline/pledge.js +39 -0
  99. package/dist/es/node_modules/websocket-extensions/lib/pipeline/ring_buffer.js +66 -0
  100. package/dist/es/node_modules/websocket-extensions/lib/websocket_extensions.js +165 -0
  101. package/dist/es/node_modules/yaeti/index.js +17 -0
  102. package/dist/es/node_modules/yaeti/lib/Event.js +24 -0
  103. package/dist/es/node_modules/yaeti/lib/EventTarget.js +130 -0
  104. package/dist/es/node_modules/zt-sockjs-client/lib/entry.js +14 -0
  105. package/dist/es/node_modules/zt-sockjs-client/lib/event/close.js +21 -0
  106. package/dist/es/node_modules/zt-sockjs-client/lib/event/event.js +22 -0
  107. package/dist/es/node_modules/zt-sockjs-client/lib/event/eventtarget.js +62 -0
  108. package/dist/es/node_modules/zt-sockjs-client/lib/event/trans-message.js +19 -0
  109. package/dist/es/node_modules/zt-sockjs-client/lib/facade.js +40 -0
  110. package/dist/es/node_modules/zt-sockjs-client/lib/iframe-bootstrap.js +122 -0
  111. package/dist/es/node_modules/zt-sockjs-client/lib/info-ajax.js +57 -0
  112. package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe-receiver.js +50 -0
  113. package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe.js +81 -0
  114. package/dist/es/node_modules/zt-sockjs-client/lib/info-receiver.js +101 -0
  115. package/dist/es/node_modules/zt-sockjs-client/lib/location.js +12 -0
  116. package/dist/es/node_modules/zt-sockjs-client/lib/main.js +413 -0
  117. package/dist/es/node_modules/zt-sockjs-client/lib/shims.js +449 -0
  118. package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/websocket.js +5 -0
  119. package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/xhr.js +80 -0
  120. package/dist/es/node_modules/zt-sockjs-client/lib/transport/eventsource.js +34 -0
  121. package/dist/es/node_modules/zt-sockjs-client/lib/transport/htmlfile.js +31 -0
  122. package/dist/es/node_modules/zt-sockjs-client/lib/transport/iframe.js +154 -0
  123. package/dist/es/node_modules/zt-sockjs-client/lib/transport/jsonp-polling.js +41 -0
  124. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/ajax-based.js +55 -0
  125. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/buffered-sender.js +92 -0
  126. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/iframe-wrap.js +39 -0
  127. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/polling.js +65 -0
  128. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/sender-receiver.js +52 -0
  129. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/eventsource.js +69 -0
  130. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/htmlfile.js +96 -0
  131. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/jsonp.js +193 -0
  132. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/xhr.js +75 -0
  133. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/jsonp.js +104 -0
  134. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xdr.js +113 -0
  135. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-cors.js +19 -0
  136. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-fake.js +28 -0
  137. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-local.js +21 -0
  138. package/dist/es/node_modules/zt-sockjs-client/lib/transport/websocket.js +108 -0
  139. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-polling.js +30 -0
  140. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-streaming.js +38 -0
  141. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-polling.js +40 -0
  142. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-streaming.js +50 -0
  143. package/dist/es/node_modules/zt-sockjs-client/lib/transport-list.js +28 -0
  144. package/dist/es/node_modules/zt-sockjs-client/lib/utils/browser.js +29 -0
  145. package/dist/es/node_modules/zt-sockjs-client/lib/utils/escape.js +53 -0
  146. package/dist/es/node_modules/zt-sockjs-client/lib/utils/event.js +78 -0
  147. package/dist/es/node_modules/zt-sockjs-client/lib/utils/iframe.js +205 -0
  148. package/dist/es/node_modules/zt-sockjs-client/lib/utils/log.js +20 -0
  149. package/dist/es/node_modules/zt-sockjs-client/lib/utils/object.js +24 -0
  150. package/dist/es/node_modules/zt-sockjs-client/lib/utils/random.js +30 -0
  151. package/dist/es/node_modules/zt-sockjs-client/lib/utils/transport.js +52 -0
  152. package/dist/es/node_modules/zt-sockjs-client/lib/utils/url.js +54 -0
  153. package/dist/es/node_modules/zt-sockjs-client/lib/version.js +11 -0
  154. package/dist/es/node_modules/zt-stompjs/index.js +23 -0
  155. package/dist/es/node_modules/zt-stompjs/lib/stomp-node.js +117 -0
  156. package/dist/es/node_modules/zt-stompjs/lib/stomp.js +536 -0
  157. package/dist/es/stompClient.d.ts +55 -0
  158. package/dist/es/stompClient.js +379 -0
  159. package/dist/index.d.ts +2 -1
  160. package/dist/index.js +2 -1
  161. package/package.json +6 -2
  162. package/src/constants.ts +5 -0
  163. package/src/index.ts +4 -0
  164. package/src/stompClient.ts +449 -0
  165. package/tsconfig.json +1 -1
@@ -0,0 +1,379 @@
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 };
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { validatePassword } from './es/passwordValidate.js';
11
11
  export { emailValidate, idCardValidate, isChineseValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
12
12
  export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile } from './es/file.js';
13
13
  export { calculateAge, parseTime } from './es/parseTime.js';
14
- export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, TOKEN_KEY } from './es/constants.js';
14
+ export { BASIC_KEY, CLIENT_TYPE, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, TOKEN_KEY } from './es/constants.js';
15
15
  export { convert, html, match, pinyin } from 'pinyin-pro';
16
16
  export { domToCanvas } from './es/canvas.js';
17
17
  export { imgToPdf } from './es/pdf.js';
@@ -21,6 +21,7 @@ export { createWater, getDefaultContent, mergeWaterConfig } from './es/water.js'
21
21
  export { initLocale } from './es/locales/i18n.js';
22
22
  export { useTranslation } from './es/locales/use-translation.js';
23
23
  export { safeT } from './es/locales/t-in-non-react.js';
24
+ export { default as StompClient } from './es/stompClient.js';
24
25
  export { Base64 } from 'js-base64';
25
26
  export { default as i18n } from 'i18next';
26
27
  export { Trans } from 'react-i18next';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export { validatePassword } from './es/passwordValidate.js';
11
11
  export { emailValidate, idCardValidate, isChineseValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
12
12
  export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile } from './es/file.js';
13
13
  export { calculateAge, parseTime } from './es/parseTime.js';
14
- export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, TOKEN_KEY } from './es/constants.js';
14
+ export { BASIC_KEY, CLIENT_TYPE, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, TOKEN_KEY } from './es/constants.js';
15
15
  export { convert, html, match, pinyin } from './es/node_modules/pinyin-pro/dist/index.js';
16
16
  export { domToCanvas } from './es/canvas.js';
17
17
  export { imgToPdf } from './es/pdf.js';
@@ -21,6 +21,7 @@ export { createWater, getDefaultContent, mergeWaterConfig } from './es/water.js'
21
21
  export { initLocale } from './es/src/locales/i18n.js';
22
22
  export { useTranslation } from './es/src/locales/use-translation.js';
23
23
  export { safeT } from './es/src/locales/t-in-non-react.js';
24
+ export { default as StompClient } from './es/stompClient.js';
24
25
  export { Base64 } from './es/node_modules/js-base64/base64.js';
25
26
  export { default as i18n } from './es/node_modules/i18next/dist/esm/i18next.js';
26
27
  export { Trans } from './es/node_modules/react-i18next/dist/es/Trans.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -25,7 +25,11 @@
25
25
  "decimal.js": "^10.4.3",
26
26
  "jwt-decode": "3.1.2",
27
27
  "mitt": "^3.0.0",
28
- "pinyin-pro": "^3.18.2"
28
+ "pinyin-pro": "^3.18.2",
29
+ "sockjs-client": "^1.5.1",
30
+ "stompjs": "^2.3.3",
31
+ "zt-sockjs-client": "^0.0.2",
32
+ "zt-stompjs": "^1.1.2"
29
33
  },
30
34
  "devDependencies": {
31
35
  "@rollup/plugin-commonjs": "^24.0.1",
package/src/constants.ts CHANGED
@@ -24,6 +24,11 @@ export const EMITTER_TYPE = {
24
24
  treeSearchSet: "treeSearchSet", // 父应用传递搜索树的值
25
25
  };
26
26
 
27
+ export const CLIENT_TYPE = {
28
+ web: 1,
29
+ mobile: 2,
30
+ };
31
+
27
32
  // token key 值
28
33
  // export const TOKEN_KEY = "Zmdms-Auth";
29
34
  export const TOKEN_KEY = (window as any).__TOKEN_KEY__ || "Cicoms-Auth";
package/src/index.ts CHANGED
@@ -57,6 +57,7 @@ export {
57
57
  EMITTER_TYPE,
58
58
  TOKEN_KEY,
59
59
  BASIC_KEY,
60
+ CLIENT_TYPE,
60
61
  } from "./constants";
61
62
 
62
63
  /**
@@ -81,3 +82,6 @@ export { createWater, mergeWaterConfig, getDefaultContent } from "./water";
81
82
 
82
83
  // 多语言相关
83
84
  export { initLocale, i18n, useTranslation, Trans, safeT } from "./locales";
85
+
86
+ // 长连接
87
+ export { default as StompClient } from "./stompClient";