@stomp/stompjs 5.3.0 → 5.4.4

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.
package/README.md CHANGED
@@ -41,7 +41,7 @@ The API documentation is hosted as GitHub pages for entire StompJS family of lib
41
41
  You may head straight to the https://stomp-js.github.io/api-docs/latest/
42
42
 
43
43
  This library comes with detailed usage instructions. Please find it at
44
- [Usage instructions](https://stomp-js.github.io/guide/stompjs/2018/06/28/using-stompjs-v5.html).
44
+ [Usage instructions](https://stomp-js.github.io/guide/stompjs/2018/06/29/using-stompjs-v5.html).
45
45
  Check out other guides at https://stomp-js.github.io/.
46
46
 
47
47
  There are quite detailed API documentation,
@@ -80,7 +80,8 @@ If you want to understand the code, develop, or contribute. Please visit
80
80
  * [Dillon Sellars](https://github.com/dillon-sellars)
81
81
  * [Jimi Charalampidis](https://github.com/jimic)
82
82
  * [Raul](https://github.com/rulonder)
83
+ * [Dimitar Georgiev](https://github.com/iMitaka)
83
84
 
84
85
  ## License
85
86
 
86
- [License](LICENSE.md) - Apache v2 License
87
+ [License](LICENSE.md) - MIT License
@@ -133,10 +133,11 @@ exports.BYTE = {
133
133
  "use strict";
134
134
 
135
135
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
136
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
136
137
  return new (P || (P = Promise))(function (resolve, reject) {
137
138
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
138
139
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
139
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
140
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
140
141
  step((generator = generator.apply(thisArg, _arguments || [])).next());
141
142
  });
142
143
  };
@@ -170,6 +171,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
170
171
  Object.defineProperty(exports, "__esModule", { value: true });
171
172
  var stomp_handler_1 = __webpack_require__(/*! ./stomp-handler */ "./src/stomp-handler.ts");
172
173
  var versions_1 = __webpack_require__(/*! ./versions */ "./src/versions.ts");
174
+ var web_socket_state_1 = __webpack_require__(/*! ./web-socket-state */ "./src/web-socket-state.ts");
173
175
  /**
174
176
  * STOMP Client Class.
175
177
  *
@@ -235,14 +237,11 @@ var Client = /** @class */ (function () {
235
237
  * A bug in ReactNative chops a string on occurrence of a NULL.
236
238
  * See issue [https://github.com/stomp-js/stompjs/issues/89]{@link https://github.com/stomp-js/stompjs/issues/89}.
237
239
  * This makes incoming WebSocket messages invalid STOMP packets.
238
- * Seeting this flag attempts to reverse the damage by appending a NULL.
240
+ * Setting this flag attempts to reverse the damage by appending a NULL.
239
241
  * If the broker splits a large message into multiple WebSocket messages,
240
242
  * this flag will cause data loss and abnormal termination of connection.
241
243
  *
242
244
  * This is not an ideal solution, but a stop gap until the underlying issue is fixed at ReactNative library.
243
- *
244
- * This flag only impacts handling of text frames.
245
- * Binary frames are not impacted by the underlying issue.
246
245
  */
247
246
  this.appendMissingNULLonIncoming = false;
248
247
  this._active = false;
@@ -370,6 +369,7 @@ var Client = /** @class */ (function () {
370
369
  maxWebSocketChunkSize: this.maxWebSocketChunkSize,
371
370
  forceBinaryWSFrames: this.forceBinaryWSFrames,
372
371
  logRawCommunication: this.logRawCommunication,
372
+ appendMissingNULLonIncoming: this.appendMissingNULLonIncoming,
373
373
  onConnect: function (frame) {
374
374
  if (!_this._active) {
375
375
  _this.debug('STOMP got connected while deactivate was issued, will disconnect now');
@@ -454,8 +454,9 @@ var Client = /** @class */ (function () {
454
454
  */
455
455
  Client.prototype.forceDisconnect = function () {
456
456
  if (this._webSocket) {
457
- if (this._webSocket.readyState === WebSocket.CONNECTING || this._webSocket.readyState === WebSocket.OPEN) {
458
- this._webSocket.close();
457
+ if (this._webSocket.readyState === web_socket_state_1.WebSocketState.CONNECTING
458
+ || this._webSocket.readyState === web_socket_state_1.WebSocketState.OPEN) {
459
+ this._stompHandler._closeWebsocket();
459
460
  }
460
461
  }
461
462
  };
@@ -1091,7 +1092,15 @@ var Stomp = /** @class */ (function () {
1091
1092
  * using [Client#webSocketFactory]{@link Client#webSocketFactory}.
1092
1093
  */
1093
1094
  Stomp.over = function (ws) {
1094
- var wsFn = typeof (ws) === 'function' ? ws : function () { return ws; };
1095
+ var wsFn;
1096
+ if (typeof (ws) === 'function') {
1097
+ wsFn = ws;
1098
+ }
1099
+ else {
1100
+ console.warn('Stomp.over did not receive a factory, auto reconnect will not work. ' +
1101
+ 'Please see https://stomp-js.github.io/api-docs/latest/classes/Stomp.html#over');
1102
+ wsFn = function () { return ws; };
1103
+ }
1095
1104
  return new compat_client_1.CompatClient(wsFn);
1096
1105
  };
1097
1106
  /**
@@ -1322,6 +1331,7 @@ __export(__webpack_require__(/*! ./stomp-config */ "./src/stomp-config.ts"));
1322
1331
  __export(__webpack_require__(/*! ./stomp-headers */ "./src/stomp-headers.ts"));
1323
1332
  __export(__webpack_require__(/*! ./stomp-subscription */ "./src/stomp-subscription.ts"));
1324
1333
  __export(__webpack_require__(/*! ./versions */ "./src/versions.ts"));
1334
+ __export(__webpack_require__(/*! ./web-socket-state */ "./src/web-socket-state.ts"));
1325
1335
  // Compatibility code
1326
1336
  __export(__webpack_require__(/*! ./compatibility/compat-client */ "./src/compatibility/compat-client.ts"));
1327
1337
  __export(__webpack_require__(/*! ./compatibility/stomp */ "./src/compatibility/stomp.ts"));
@@ -1406,7 +1416,8 @@ var Parser = /** @class */ (function () {
1406
1416
  this._token = [];
1407
1417
  this._initState();
1408
1418
  }
1409
- Parser.prototype.parseChunk = function (segment) {
1419
+ Parser.prototype.parseChunk = function (segment, appendMissingNULLonIncoming) {
1420
+ if (appendMissingNULLonIncoming === void 0) { appendMissingNULLonIncoming = false; }
1410
1421
  var chunk;
1411
1422
  if ((segment instanceof ArrayBuffer)) {
1412
1423
  chunk = new Uint8Array(segment);
@@ -1414,6 +1425,16 @@ var Parser = /** @class */ (function () {
1414
1425
  else {
1415
1426
  chunk = this._encoder.encode(segment);
1416
1427
  }
1428
+ // See https://github.com/stomp-js/stompjs/issues/89
1429
+ // Remove when underlying issue is fixed.
1430
+ //
1431
+ // Send a NULL byte, if the last byte of a Text frame was not NULL.F
1432
+ if (appendMissingNULLonIncoming && chunk[chunk.length - 1] !== 0) {
1433
+ var chunkWithNull = new Uint8Array(chunk.length + 1);
1434
+ chunkWithNull.set(chunk, 0);
1435
+ chunkWithNull[chunk.length] = 0;
1436
+ chunk = chunkWithNull;
1437
+ }
1417
1438
  // tslint:disable-next-line:prefer-for-of
1418
1439
  for (var i = 0; i < chunk.length; i++) {
1419
1440
  var byte = chunk[i];
@@ -1583,6 +1604,7 @@ var byte_1 = __webpack_require__(/*! ./byte */ "./src/byte.ts");
1583
1604
  var frame_impl_1 = __webpack_require__(/*! ./frame-impl */ "./src/frame-impl.ts");
1584
1605
  var parser_1 = __webpack_require__(/*! ./parser */ "./src/parser.ts");
1585
1606
  var versions_1 = __webpack_require__(/*! ./versions */ "./src/versions.ts");
1607
+ var web_socket_state_1 = __webpack_require__(/*! ./web-socket-state */ "./src/web-socket-state.ts");
1586
1608
  /**
1587
1609
  * The STOMP protocol handler
1588
1610
  *
@@ -1592,8 +1614,8 @@ var versions_1 = __webpack_require__(/*! ./versions */ "./src/versions.ts");
1592
1614
  */
1593
1615
  var StompHandler = /** @class */ (function () {
1594
1616
  function StompHandler(_client, _webSocket, config) {
1595
- if (config === void 0) { config = {}; }
1596
1617
  var _this = this;
1618
+ if (config === void 0) { config = {}; }
1597
1619
  this._client = _client;
1598
1620
  this._webSocket = _webSocket;
1599
1621
  this._serverFrameHandlers = {
@@ -1706,17 +1728,7 @@ var StompHandler = /** @class */ (function () {
1706
1728
  var rawChunkAsString = (evt.data instanceof ArrayBuffer) ? new TextDecoder().decode(evt.data) : evt.data;
1707
1729
  _this.debug("<<< " + rawChunkAsString);
1708
1730
  }
1709
- parser.parseChunk(evt.data);
1710
- // See https://github.com/stomp-js/stompjs/issues/89
1711
- // Remove when underlying issue is fixed.
1712
- //
1713
- // Send a NULL byte, if the last byte of a Text frame was not NULL.
1714
- if (_this.appendMissingNULLonIncoming && !(evt.data instanceof ArrayBuffer)) {
1715
- if (evt.data[evt.data.length - 1] !== 0) {
1716
- var bufferWithNull = (new Uint8Array([0])).buffer;
1717
- parser.parseChunk(bufferWithNull);
1718
- }
1719
- }
1731
+ parser.parseChunk(evt.data, _this.appendMissingNULLonIncoming);
1720
1732
  };
1721
1733
  this._webSocket.onclose = function (closeEvent) {
1722
1734
  _this.debug("Connection closed to " + _this._webSocket.url);
@@ -1740,6 +1752,11 @@ var StompHandler = /** @class */ (function () {
1740
1752
  if ((headers.version !== versions_1.Versions.V1_1 && headers.version !== versions_1.Versions.V1_2)) {
1741
1753
  return;
1742
1754
  }
1755
+ // It is valid for the server to not send this header
1756
+ // https://stomp.github.io/stomp-specification-1.2.html#Heart-beating
1757
+ if (!headers['heart-beat']) {
1758
+ return;
1759
+ }
1743
1760
  // heart-beat header received from the server looks like:
1744
1761
  //
1745
1762
  // heart-beat: sx, sy
@@ -1748,7 +1765,7 @@ var StompHandler = /** @class */ (function () {
1748
1765
  var ttl = Math.max(this.heartbeatOutgoing, serverIncoming);
1749
1766
  this.debug("send PING every " + ttl + "ms");
1750
1767
  this._pinger = setInterval(function () {
1751
- if (_this._webSocket.readyState === WebSocket.OPEN) {
1768
+ if (_this._webSocket.readyState === web_socket_state_1.WebSocketState.OPEN) {
1752
1769
  _this._webSocket.send(byte_1.BYTE.LF);
1753
1770
  _this.debug('>>> PING');
1754
1771
  }
@@ -1762,11 +1779,15 @@ var StompHandler = /** @class */ (function () {
1762
1779
  // We wait twice the TTL to be flexible on window's setInterval calls
1763
1780
  if (delta > (ttl_1 * 2)) {
1764
1781
  _this.debug("did not receive server activity for the last " + delta + "ms");
1765
- _this._webSocket.close();
1782
+ _this._closeWebsocket();
1766
1783
  }
1767
1784
  }, ttl_1);
1768
1785
  }
1769
1786
  };
1787
+ StompHandler.prototype._closeWebsocket = function () {
1788
+ this._webSocket.onmessage = function () { }; // ignore messages
1789
+ this._webSocket.close();
1790
+ };
1770
1791
  StompHandler.prototype._transmit = function (params) {
1771
1792
  var command = params.command, headers = params.headers, body = params.body, binaryBody = params.binaryBody, skipContentLengthHeader = params.skipContentLengthHeader;
1772
1793
  var frame = new frame_impl_1.FrameImpl({
@@ -1810,7 +1831,7 @@ var StompHandler = /** @class */ (function () {
1810
1831
  disconnectHeaders.receipt = "close-" + this._counter++;
1811
1832
  }
1812
1833
  this.watchForReceipt(disconnectHeaders.receipt, function (frame) {
1813
- _this._webSocket.close();
1834
+ _this._closeWebsocket();
1814
1835
  _this._cleanUp();
1815
1836
  _this.onDisconnect(frame);
1816
1837
  });
@@ -1821,8 +1842,9 @@ var StompHandler = /** @class */ (function () {
1821
1842
  }
1822
1843
  }
1823
1844
  else {
1824
- if (this._webSocket.readyState === WebSocket.CONNECTING || this._webSocket.readyState === WebSocket.OPEN) {
1825
- this._webSocket.close();
1845
+ if (this._webSocket.readyState === web_socket_state_1.WebSocketState.CONNECTING
1846
+ || this._webSocket.readyState === web_socket_state_1.WebSocketState.OPEN) {
1847
+ this._closeWebsocket();
1826
1848
  }
1827
1849
  }
1828
1850
  };
@@ -2048,6 +2070,34 @@ var Versions = /** @class */ (function () {
2048
2070
  exports.Versions = Versions;
2049
2071
 
2050
2072
 
2073
+ /***/ }),
2074
+
2075
+ /***/ "./src/web-socket-state.ts":
2076
+ /*!*********************************!*\
2077
+ !*** ./src/web-socket-state.ts ***!
2078
+ \*********************************/
2079
+ /*! no static exports found */
2080
+ /***/ (function(module, exports, __webpack_require__) {
2081
+
2082
+ "use strict";
2083
+
2084
+ Object.defineProperty(exports, "__esModule", { value: true });
2085
+ /**
2086
+ * Possible states for the WebSocket, copied here to avoid dependency on WebSocket class
2087
+ *
2088
+ * Part of `@stomp/rx-stomp`
2089
+ *
2090
+ * @internal
2091
+ */
2092
+ var WebSocketState;
2093
+ (function (WebSocketState) {
2094
+ WebSocketState[WebSocketState["CONNECTING"] = 0] = "CONNECTING";
2095
+ WebSocketState[WebSocketState["OPEN"] = 1] = "OPEN";
2096
+ WebSocketState[WebSocketState["CLOSING"] = 2] = "CLOSING";
2097
+ WebSocketState[WebSocketState["CLOSED"] = 3] = "CLOSED";
2098
+ })(WebSocketState = exports.WebSocketState || (exports.WebSocketState = {}));
2099
+
2100
+
2051
2101
  /***/ }),
2052
2102
 
2053
2103
  /***/ 0: