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,536 @@
1
+ import { commonjsGlobal } from '../../../_virtual/_commonjsHelpers.js';
2
+ import { __exports as stomp } from '../../../_virtual/stomp.js';
3
+
4
+ (function (exports) {
5
+ // Generated by CoffeeScript 1.7.1
6
+
7
+ /*
8
+ Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0
9
+
10
+ Copyright (C) 2010-2013 [Jeff Mesnil](http://jmesnil.net/)
11
+ Copyright (C) 2012 [FuseSource, Inc.](http://fusesource.com)
12
+ */
13
+
14
+ (function() {
15
+ var Byte, Client, Frame, Stomp,
16
+ __hasProp = {}.hasOwnProperty,
17
+ __slice = [].slice;
18
+
19
+ Byte = {
20
+ LF: '\x0A',
21
+ NULL: '\x00'
22
+ };
23
+
24
+ Frame = (function() {
25
+ var unmarshallSingle;
26
+
27
+ function Frame(command, headers, body) {
28
+ this.command = command;
29
+ this.headers = headers != null ? headers : {};
30
+ this.body = body != null ? body : '';
31
+ }
32
+
33
+ Frame.prototype.toString = function() {
34
+ var lines, name, skipContentLength, value, _ref;
35
+ lines = [this.command];
36
+ skipContentLength = this.headers['content-length'] === false ? true : false;
37
+ if (skipContentLength) {
38
+ delete this.headers['content-length'];
39
+ }
40
+ _ref = this.headers;
41
+ for (name in _ref) {
42
+ if (!__hasProp.call(_ref, name)) continue;
43
+ value = _ref[name];
44
+ lines.push("" + name + ":" + value);
45
+ }
46
+ if (this.body && !skipContentLength) {
47
+ lines.push("content-length:" + (Frame.sizeOfUTF8(this.body)));
48
+ }
49
+ lines.push(Byte.LF + this.body);
50
+ return lines.join(Byte.LF);
51
+ };
52
+
53
+ Frame.sizeOfUTF8 = function(s) {
54
+ if (s) {
55
+ return encodeURI(s).match(/%..|./g).length;
56
+ } else {
57
+ return 0;
58
+ }
59
+ };
60
+
61
+ unmarshallSingle = function(data) {
62
+ var body, chr, command, divider, headerLines, headers, i, idx, len, line, start, trim, _i, _j, _len, _ref, _ref1;
63
+ divider = data.search(RegExp("" + Byte.LF + Byte.LF));
64
+ headerLines = data.substring(0, divider).split(Byte.LF);
65
+ command = headerLines.shift();
66
+ headers = {};
67
+ trim = function(str) {
68
+ return str.replace(/^\s+|\s+$/g, '');
69
+ };
70
+ _ref = headerLines.reverse();
71
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
72
+ line = _ref[_i];
73
+ idx = line.indexOf(':');
74
+ headers[trim(line.substring(0, idx))] = trim(line.substring(idx + 1));
75
+ }
76
+ body = '';
77
+ start = divider + 2;
78
+ if (headers['content-length']) {
79
+ len = parseInt(headers['content-length']);
80
+ body = ('' + data).substring(start, start + len);
81
+ } else {
82
+ chr = null;
83
+ for (i = _j = start, _ref1 = data.length; start <= _ref1 ? _j < _ref1 : _j > _ref1; i = start <= _ref1 ? ++_j : --_j) {
84
+ chr = data.charAt(i);
85
+ if (chr === Byte.NULL) {
86
+ break;
87
+ }
88
+ body += chr;
89
+ }
90
+ }
91
+ return new Frame(command, headers, body);
92
+ };
93
+
94
+ Frame.unmarshall = function(datas) {
95
+ var frame, frames, last_frame, r;
96
+ frames = datas.split(RegExp("" + Byte.NULL + Byte.LF + "*"));
97
+ r = {
98
+ frames: [],
99
+ partial: ''
100
+ };
101
+ r.frames = (function() {
102
+ var _i, _len, _ref, _results;
103
+ _ref = frames.slice(0, -1);
104
+ _results = [];
105
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
106
+ frame = _ref[_i];
107
+ _results.push(unmarshallSingle(frame));
108
+ }
109
+ return _results;
110
+ })();
111
+ last_frame = frames.slice(-1)[0];
112
+ if (last_frame === Byte.LF || (last_frame.search(RegExp("" + Byte.NULL + Byte.LF + "*$"))) !== -1) {
113
+ r.frames.push(unmarshallSingle(last_frame));
114
+ } else {
115
+ r.partial = last_frame;
116
+ }
117
+ return r;
118
+ };
119
+
120
+ Frame.marshall = function(command, headers, body) {
121
+ var frame;
122
+ frame = new Frame(command, headers, body);
123
+ return frame.toString() + Byte.NULL;
124
+ };
125
+
126
+ return Frame;
127
+
128
+ })();
129
+
130
+ Client = (function() {
131
+ var now;
132
+
133
+ function Client(ws) {
134
+ this.ws = ws;
135
+ this.ws.binaryType = "arraybuffer";
136
+ this.counter = 0;
137
+ this.connected = false;
138
+ this.heartbeat = {
139
+ outgoing: 10000,
140
+ incoming: 10000
141
+ };
142
+ this.maxWebSocketFrameSize = 16 * 1024;
143
+ this.subscriptions = {};
144
+ this.partialData = '';
145
+ }
146
+
147
+ Client.prototype.__my__timeout__ = null;
148
+
149
+ Client.prototype.debug = function(message) {
150
+ var _ref;
151
+ return typeof window !== "undefined" && window !== null ? (_ref = window.console) != null ? _ref.log(message) : void 0 : void 0;
152
+ };
153
+
154
+ now = function() {
155
+ if (Date.now) {
156
+ return Date.now();
157
+ } else {
158
+ return new Date().valueOf;
159
+ }
160
+ };
161
+
162
+ Client.prototype._transmit = function(command, headers, body) {
163
+ var out;
164
+ out = Frame.marshall(command, headers, body);
165
+ if (typeof this.debug === "function") {
166
+ this.debug(">>> " + out);
167
+ }
168
+ while (true) {
169
+ if (out.length > this.maxWebSocketFrameSize) {
170
+ this.ws.send(out.substring(0, this.maxWebSocketFrameSize));
171
+ out = out.substring(this.maxWebSocketFrameSize);
172
+ if (typeof this.debug === "function") {
173
+ this.debug("remaining = " + out.length);
174
+ }
175
+ } else {
176
+ return this.ws.send(out);
177
+ }
178
+ }
179
+ };
180
+
181
+ Client.prototype._setupHeartbeat = function(headers) {
182
+ var serverOutgoing, ttl, v, _ref, _ref1;
183
+ if ((_ref = headers.version) !== Stomp.VERSIONS.V1_1 && _ref !== Stomp.VERSIONS.V1_2) {
184
+ return;
185
+ }
186
+ _ref1 = (function() {
187
+ var _i, _len, _ref1, _results;
188
+ _ref1 = headers['heart-beat'].split(",");
189
+ _results = [];
190
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
191
+ v = _ref1[_i];
192
+ _results.push(parseInt(v));
193
+ }
194
+ return _results;
195
+ })(), serverOutgoing = _ref1[0], _ref1[1];
196
+ // 每隔 客户端或者服务端设置的 发送 接收最大时间 发送心跳,这里把逻辑注释掉,改为手动发送心跳
197
+ // if (!(this.heartbeat.outgoing === 0 || serverIncoming === 0)) {
198
+ // ttl = Math.max(this.heartbeat.outgoing, serverIncoming);
199
+ // if (typeof this.debug === "function") {
200
+ // this.debug("send PING every " + ttl + "ms");
201
+ // }
202
+ // this.pinger = Stomp.setInterval(ttl, (function(_this) {
203
+ // return function() {
204
+ // _this.ws.send(Byte.LF);
205
+ // return typeof _this.debug === "function" ? _this.debug(">>> PING") : void 0;
206
+ // };
207
+ // })(this));
208
+ // }
209
+ if (!(this.heartbeat.incoming === 0 || serverOutgoing === 0)) {
210
+ ttl = Math.max(this.heartbeat.incoming, serverOutgoing);
211
+ if (typeof this.debug === "function") {
212
+ this.debug("check PONG every " + ttl + "ms");
213
+ }
214
+ // 修改逻辑:每隔 客户端或者服务端设置的接收 发送最大时间的两倍 判断是否有收到服务端的消息
215
+ // 如果没收到 则判断掉线 断开连接
216
+ return this.ponger = Stomp.setInterval(ttl, (function(_this) {
217
+ return function() {
218
+ var delta;
219
+ delta = now() - _this.serverActivity;
220
+ // if (typeof _this.debug === "function") {
221
+ // console.log('-------test--------', delta, ttl * 2)
222
+ // }
223
+ if (delta > ttl * 2) {
224
+ if (typeof _this.debug === "function") {
225
+ _this.debug("did not receive server activity for the last " + delta + "ms");
226
+ }
227
+ return _this.ws.close();
228
+ }
229
+ };
230
+ })(this));
231
+ }
232
+ };
233
+
234
+ Client.prototype._parseConnect = function() {
235
+ var args, connectCallback, errorCallback, headers;
236
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
237
+ headers = {};
238
+ switch (args.length) {
239
+ case 2:
240
+ headers = args[0], connectCallback = args[1];
241
+ break;
242
+ case 3:
243
+ if (args[1] instanceof Function) {
244
+ headers = args[0], connectCallback = args[1], errorCallback = args[2];
245
+ } else {
246
+ headers.login = args[0], headers.passcode = args[1], connectCallback = args[2];
247
+ }
248
+ break;
249
+ case 4:
250
+ headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3];
251
+ break;
252
+ default:
253
+ headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3], headers.host = args[4];
254
+ }
255
+ return [headers, connectCallback, errorCallback];
256
+ };
257
+
258
+ Client.prototype.connect = function() {
259
+ var args, errorCallback, headers, out;
260
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
261
+ out = this._parseConnect.apply(this, args);
262
+ headers = out[0], this.connectCallback = out[1], errorCallback = out[2];
263
+ if (typeof this.debug === "function") {
264
+ this.debug("Opening Web Socket...");
265
+ }
266
+ this.ws.onmessage = (function(_this) {
267
+ return function(evt) {
268
+ var arr, c, client, data, frame, messageID, onreceive, subscription, unmarshalledData, _i, _len, _ref, _results;
269
+ data = typeof ArrayBuffer !== 'undefined' && evt.data instanceof ArrayBuffer ? (arr = new Uint8Array(evt.data), typeof _this.debug === "function" ? _this.debug("--- got data length: " + arr.length) : void 0, ((function() {
270
+ var _i, _len, _results;
271
+ _results = [];
272
+ for (_i = 0, _len = arr.length; _i < _len; _i++) {
273
+ c = arr[_i];
274
+ _results.push(String.fromCharCode(c));
275
+ }
276
+ return _results;
277
+ })()).join('')) : evt.data;
278
+ _this.serverActivity = now();
279
+ if (data === Byte.LF) {
280
+ if (typeof _this.debug === "function") {
281
+ _this.debug("<<< PONG", data);
282
+ }
283
+ /**
284
+ * 修改逻辑:监听到服务端发送的PONG消息,回发一个PING消息
285
+ */
286
+ _this.ws.send(Byte.LF);
287
+ return;
288
+ }
289
+ if (typeof _this.debug === "function") {
290
+ _this.debug("<<< " + data);
291
+ }
292
+ unmarshalledData = Frame.unmarshall(_this.partialData + data);
293
+ _this.partialData = unmarshalledData.partial;
294
+ _ref = unmarshalledData.frames;
295
+ _results = [];
296
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
297
+ frame = _ref[_i];
298
+ switch (frame.command) {
299
+ case "CONNECTED":
300
+ if (typeof _this.debug === "function") {
301
+ _this.debug("connected to server " + frame.headers.server);
302
+ }
303
+ /**
304
+ * 修改逻辑:如果5秒内,连接建立成功了,那么清除掉关闭消息的逻辑
305
+ */
306
+ console.log(`5秒内收到了服务端返回的连接信息,清空掉定时器!(这段逻辑暂时注释,看下执行效果!)`);
307
+ if (_this.__my__timeout__) {
308
+ clearTimeout(_this.__my__timeout__);
309
+ _this.__my__timeout__ = null;
310
+ }
311
+ _this.connected = true;
312
+ _this._setupHeartbeat(frame.headers);
313
+ _results.push(typeof _this.connectCallback === "function" ? _this.connectCallback(frame) : void 0);
314
+ break;
315
+ case "MESSAGE":
316
+ subscription = frame.headers.subscription;
317
+ onreceive = _this.subscriptions[subscription] || _this.onreceive;
318
+ if (onreceive) {
319
+ client = _this;
320
+ messageID = frame.headers["message-id"];
321
+ frame.ack = function(headers) {
322
+ if (headers == null) {
323
+ headers = {};
324
+ }
325
+ return client.ack(messageID, subscription, headers);
326
+ };
327
+ frame.nack = function(headers) {
328
+ if (headers == null) {
329
+ headers = {};
330
+ }
331
+ return client.nack(messageID, subscription, headers);
332
+ };
333
+ _results.push(onreceive(frame));
334
+ } else {
335
+ _results.push(typeof _this.debug === "function" ? _this.debug("Unhandled received MESSAGE: " + frame) : void 0);
336
+ }
337
+ break;
338
+ case "RECEIPT":
339
+ _results.push(typeof _this.onreceipt === "function" ? _this.onreceipt(frame) : void 0);
340
+ break;
341
+ case "ERROR":
342
+ _results.push(typeof errorCallback === "function" ? errorCallback(frame) : void 0);
343
+ break;
344
+ default:
345
+ _results.push(typeof _this.debug === "function" ? _this.debug("Unhandled frame: " + frame) : void 0);
346
+ }
347
+ }
348
+ return _results;
349
+ };
350
+ })(this);
351
+ this.ws.onclose = (function(_this) {
352
+ return function() {
353
+ var msg;
354
+ msg = "Whoops! Lost connection to " + _this.ws.url;
355
+ if (typeof _this.debug === "function") {
356
+ _this.debug(msg);
357
+ }
358
+ _this._cleanUp();
359
+ return typeof errorCallback === "function" ? errorCallback(msg) : void 0;
360
+ };
361
+ })(this);
362
+ return this.ws.onopen = (function(_this) {
363
+ return function() {
364
+ if (typeof _this.debug === "function") {
365
+ _this.debug('Web Socket Opened...');
366
+ }
367
+ headers["accept-version"] = Stomp.VERSIONS.supportedVersions();
368
+ headers["heart-beat"] = [_this.heartbeat.outgoing, _this.heartbeat.incoming].join(',');
369
+ /**
370
+ * 修改逻辑:开始建立连接;这里添加逻辑 如果客户端发送的连接消息
371
+ * 在5秒内,没收到服务端的回复,那么关闭连接
372
+ */
373
+ _this.__my__timeout__ = setTimeout(() => {
374
+ console.log(`客户端已发送了连接信息,但是5秒后未收到服务端信息,断开连接!(这段逻辑暂时注释,看下执行逻辑!)`);
375
+ // _this.disconnect()
376
+ }, 5000);
377
+ return _this._transmit("CONNECT", headers);
378
+ };
379
+ })(this);
380
+ };
381
+
382
+ Client.prototype.disconnect = function(disconnectCallback, headers) {
383
+ if (headers == null) {
384
+ headers = {};
385
+ }
386
+ this._transmit("DISCONNECT", headers);
387
+ this.ws.onclose = null;
388
+ this.ws.close();
389
+ this._cleanUp();
390
+ return typeof disconnectCallback === "function" ? disconnectCallback() : void 0;
391
+ };
392
+
393
+ Client.prototype._cleanUp = function() {
394
+ this.connected = false;
395
+ if (this.pinger) {
396
+ Stomp.clearInterval(this.pinger);
397
+ }
398
+ if (this.ponger) {
399
+ return Stomp.clearInterval(this.ponger);
400
+ }
401
+ };
402
+
403
+ Client.prototype.send = function(destination, headers, body) {
404
+ if (headers == null) {
405
+ headers = {};
406
+ }
407
+ if (body == null) {
408
+ body = '';
409
+ }
410
+ headers.destination = destination;
411
+ return this._transmit("SEND", headers, body);
412
+ };
413
+
414
+ Client.prototype.subscribe = function(destination, callback, headers) {
415
+ var client;
416
+ if (headers == null) {
417
+ headers = {};
418
+ }
419
+ if (!headers.id) {
420
+ headers.id = "sub-" + this.counter++;
421
+ }
422
+ headers.destination = destination;
423
+ this.subscriptions[headers.id] = callback;
424
+ this._transmit("SUBSCRIBE", headers);
425
+ client = this;
426
+ return {
427
+ id: headers.id,
428
+ unsubscribe: function() {
429
+ return client.unsubscribe(headers.id);
430
+ }
431
+ };
432
+ };
433
+
434
+ Client.prototype.unsubscribe = function(id) {
435
+ delete this.subscriptions[id];
436
+ return this._transmit("UNSUBSCRIBE", {
437
+ id: id
438
+ });
439
+ };
440
+
441
+ Client.prototype.begin = function(transaction) {
442
+ var client, txid;
443
+ txid = transaction || "tx-" + this.counter++;
444
+ this._transmit("BEGIN", {
445
+ transaction: txid
446
+ });
447
+ client = this;
448
+ return {
449
+ id: txid,
450
+ commit: function() {
451
+ return client.commit(txid);
452
+ },
453
+ abort: function() {
454
+ return client.abort(txid);
455
+ }
456
+ };
457
+ };
458
+
459
+ Client.prototype.commit = function(transaction) {
460
+ return this._transmit("COMMIT", {
461
+ transaction: transaction
462
+ });
463
+ };
464
+
465
+ Client.prototype.abort = function(transaction) {
466
+ return this._transmit("ABORT", {
467
+ transaction: transaction
468
+ });
469
+ };
470
+
471
+ Client.prototype.ack = function(messageID, subscription, headers) {
472
+ if (headers == null) {
473
+ headers = {};
474
+ }
475
+ headers["message-id"] = messageID;
476
+ headers.subscription = subscription;
477
+ return this._transmit("ACK", headers);
478
+ };
479
+
480
+ Client.prototype.nack = function(messageID, subscription, headers) {
481
+ if (headers == null) {
482
+ headers = {};
483
+ }
484
+ headers["message-id"] = messageID;
485
+ headers.subscription = subscription;
486
+ return this._transmit("NACK", headers);
487
+ };
488
+
489
+ return Client;
490
+
491
+ })();
492
+
493
+ Stomp = {
494
+ VERSIONS: {
495
+ V1_0: '1.0',
496
+ V1_1: '1.1',
497
+ V1_2: '1.2',
498
+ supportedVersions: function() {
499
+ return '1.1,1.0';
500
+ }
501
+ },
502
+ client: function(url, protocols) {
503
+ var klass, ws;
504
+ if (protocols == null) {
505
+ protocols = ['v10.stomp', 'v11.stomp'];
506
+ }
507
+ klass = Stomp.WebSocketClass || WebSocket;
508
+ ws = new klass(url, protocols);
509
+ return new Client(ws);
510
+ },
511
+ over: function(ws) {
512
+ return new Client(ws);
513
+ },
514
+ Frame: Frame
515
+ };
516
+
517
+ if (exports !== null) {
518
+ exports.Stomp = Stomp;
519
+ }
520
+
521
+ if (typeof window !== "undefined" && window !== null) {
522
+ Stomp.setInterval = function(interval, f) {
523
+ return window.setInterval(f, interval);
524
+ };
525
+ Stomp.clearInterval = function(id) {
526
+ return window.clearInterval(id);
527
+ };
528
+ window.Stomp = Stomp;
529
+ } else if (!exports) {
530
+ self.Stomp = Stomp;
531
+ }
532
+
533
+ }).call(commonjsGlobal);
534
+ } (stomp));
535
+
536
+ export { stomp as default };
@@ -0,0 +1,55 @@
1
+ interface IConnectWsConfig {
2
+ baseUrl: string;
3
+ userId: string;
4
+ clientType: string | number;
5
+ systemType?: string;
6
+ token?: string;
7
+ debug?: boolean;
8
+ heartbeat?: {
9
+ outgoing?: number;
10
+ incoming?: number;
11
+ };
12
+ reconnectionTime?: number;
13
+ }
14
+ declare class StompClient {
15
+ static getInstance: (connectWsConfig?: IConnectWsConfig) => StompClient;
16
+ connectWsConfig: IConnectWsConfig;
17
+ client: any;
18
+ isClient: any;
19
+ clearIsClient: any;
20
+ clearIsClientNo: any;
21
+ clearIsClientYes: any;
22
+ subscriptions: any;
23
+ subscriptionsFn: any;
24
+ successCallbacks: any;
25
+ errorCallbacks: any;
26
+ reconnectionNum: number;
27
+ reconnectiontime: number;
28
+ maxReconnectiontime: number;
29
+ userClose: boolean;
30
+ isInit: boolean;
31
+ constructor(connectWsConfig: IConnectWsConfig);
32
+ init(): void;
33
+ /**
34
+ * 连接失败后,将所有注册过的订阅、回调执行状态置为未执行状态。
35
+ * @param isExecute 连接通道、回调的执行状态
36
+ */
37
+ setExecuteFail(): void;
38
+ /**
39
+ * 连接成功后,需要将当前已注册的,未执行的连接通道重新执行连接
40
+ * 还有成功回调
41
+ * 失败回调的执行状态重置为未执行状态
42
+ * @returns 执行订阅相关回调
43
+ */
44
+ executeSubscribe(): void;
45
+ getReconnectionTime(): number;
46
+ subscribeSuccessCall(subscribeId: string, callback: () => void): void;
47
+ subscribeErrorCall(subscribeId: string, callback: () => void): void;
48
+ subscribe(subscribeId: string, pipe: string, callback?: (response: any) => void, headers?: any): void;
49
+ getSubscriptions(key: any): any;
50
+ disconnect(callback: () => void): Promise<unknown>;
51
+ reconnect(): Promise<unknown>;
52
+ send(pipe: string, headers: object, message: string): void;
53
+ }
54
+
55
+ export { StompClient as default };