@stomp/stompjs 6.1.2 → 7.0.0-beta2

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 (59) hide show
  1. package/bundles/stomp.umd.js +1724 -2023
  2. package/bundles/stomp.umd.js.map +1 -1
  3. package/bundles/stomp.umd.min.js +1 -2
  4. package/esm6/augment-websocket.d.ts +1 -1
  5. package/esm6/augment-websocket.js +4 -3
  6. package/esm6/augment-websocket.js.map +1 -1
  7. package/esm6/client.d.ts +35 -19
  8. package/esm6/client.js +176 -132
  9. package/esm6/client.js.map +1 -1
  10. package/esm6/compatibility/compat-client.d.ts +29 -23
  11. package/esm6/compatibility/compat-client.js +2 -2
  12. package/esm6/compatibility/compat-client.js.map +1 -1
  13. package/esm6/compatibility/heartbeat-info.d.ts +5 -3
  14. package/esm6/compatibility/stomp.d.ts +1 -1
  15. package/esm6/compatibility/stomp.js +2 -2
  16. package/esm6/compatibility/stomp.js.map +1 -1
  17. package/esm6/frame-impl.d.ts +5 -5
  18. package/esm6/frame-impl.js +3 -2
  19. package/esm6/frame-impl.js.map +1 -1
  20. package/esm6/i-frame.d.ts +1 -1
  21. package/esm6/i-frame.js +1 -0
  22. package/esm6/i-message.d.ts +2 -2
  23. package/esm6/i-message.js +1 -0
  24. package/esm6/i-transaction.js +1 -0
  25. package/esm6/index.d.ts +13 -13
  26. package/esm6/index.js +13 -10
  27. package/esm6/index.js.map +1 -1
  28. package/esm6/parser.d.ts +1 -1
  29. package/esm6/parser.js +10 -2
  30. package/esm6/parser.js.map +1 -1
  31. package/esm6/stomp-config.d.ts +3 -3
  32. package/esm6/stomp-handler.d.ts +10 -13
  33. package/esm6/stomp-handler.js +35 -17
  34. package/esm6/stomp-handler.js.map +1 -1
  35. package/esm6/stomp-subscription.d.ts +2 -2
  36. package/esm6/stomp-subscription.js +1 -7
  37. package/esm6/stomp-subscription.js.map +1 -1
  38. package/esm6/types.d.ts +31 -5
  39. package/esm6/types.js +2 -2
  40. package/esm6/types.js.map +1 -1
  41. package/esm6/versions.js +2 -2
  42. package/index.d.ts +1 -1
  43. package/package.json +28 -25
  44. package/src/augment-websocket.ts +5 -4
  45. package/src/client.ts +81 -35
  46. package/src/compatibility/compat-client.ts +4 -4
  47. package/src/compatibility/heartbeat-info.ts +1 -1
  48. package/src/compatibility/stomp.ts +3 -3
  49. package/src/frame-impl.ts +14 -10
  50. package/src/i-frame.ts +1 -1
  51. package/src/i-message.ts +2 -2
  52. package/src/index.ts +13 -13
  53. package/src/parser.ts +18 -6
  54. package/src/stomp-config.ts +3 -3
  55. package/src/stomp-handler.ts +47 -31
  56. package/src/stomp-subscription.ts +4 -4
  57. package/src/types.ts +32 -5
  58. package/src/versions.ts +2 -2
  59. package/bundles/stomp.umd.min.js.map +0 -1
@@ -1,8 +1,2 @@
1
- /**
2
- * Call [Client#subscribe]{@link Client#subscribe} to create a StompSubscription.
3
- *
4
- * Part of `@stomp/stompjs`.
5
- */
6
- export class StompSubscription {
7
- }
1
+ export {};
8
2
  //# sourceMappingURL=stomp-subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stomp-subscription.js","sourceRoot":"","sources":["../src/stomp-subscription.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;CAU7B"}
1
+ {"version":3,"file":"stomp-subscription.js","sourceRoot":"","sources":["../src/stomp-subscription.ts"],"names":[],"mappings":""}
package/esm6/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { IFrame } from './i-frame';
2
- import { IMessage } from './i-message';
3
- import { StompHeaders } from './stomp-headers';
1
+ import { IFrame } from './i-frame.js';
2
+ import { IMessage } from './i-message.js';
3
+ import { StompHeaders } from './stomp-headers.js';
4
+ import { Versions } from './versions.js';
4
5
  /**
5
6
  * This callback will receive a `string` as parameter.
6
7
  *
@@ -82,9 +83,9 @@ export declare type RawHeaderType = [string, string];
82
83
  * @internal
83
84
  */
84
85
  export interface IRawFrameType {
85
- command: string;
86
+ command: string | undefined;
86
87
  headers: RawHeaderType[];
87
- binaryBody: Uint8Array;
88
+ binaryBody: Uint8Array | undefined;
88
89
  }
89
90
  /**
90
91
  * @internal
@@ -138,3 +139,28 @@ export declare enum ActivationState {
138
139
  DEACTIVATING = 1,
139
140
  INACTIVE = 2
140
141
  }
142
+ /**
143
+ * @internal
144
+ */
145
+ export interface IStomptHandlerConfig {
146
+ debug: debugFnType;
147
+ stompVersions: Versions;
148
+ connectHeaders: StompHeaders;
149
+ disconnectHeaders: StompHeaders;
150
+ heartbeatIncoming: number;
151
+ heartbeatOutgoing: number;
152
+ splitLargeFrames: boolean;
153
+ maxWebSocketChunkSize: number;
154
+ forceBinaryWSFrames: boolean;
155
+ logRawCommunication: boolean;
156
+ appendMissingNULLonIncoming: boolean;
157
+ discardWebsocketOnCommFailure: boolean;
158
+ onConnect: frameCallbackType;
159
+ onDisconnect: frameCallbackType;
160
+ onStompError: frameCallbackType;
161
+ onWebSocketClose: closeEventCallbackType;
162
+ onWebSocketError: wsErrorCallbackType;
163
+ onUnhandledMessage: messageCallbackType;
164
+ onUnhandledReceipt: frameCallbackType;
165
+ onUnhandledFrame: frameCallbackType;
166
+ }
package/esm6/types.js CHANGED
@@ -7,7 +7,7 @@ export var StompSocketState;
7
7
  StompSocketState[StompSocketState["OPEN"] = 1] = "OPEN";
8
8
  StompSocketState[StompSocketState["CLOSING"] = 2] = "CLOSING";
9
9
  StompSocketState[StompSocketState["CLOSED"] = 3] = "CLOSED";
10
- })(StompSocketState || (StompSocketState = {}));
10
+ })(StompSocketState = StompSocketState || (StompSocketState = {}));
11
11
  /**
12
12
  * Possible activation state
13
13
  */
@@ -16,5 +16,5 @@ export var ActivationState;
16
16
  ActivationState[ActivationState["ACTIVE"] = 0] = "ACTIVE";
17
17
  ActivationState[ActivationState["DEACTIVATING"] = 1] = "DEACTIVATING";
18
18
  ActivationState[ActivationState["INACTIVE"] = 2] = "INACTIVE";
19
- })(ActivationState || (ActivationState = {}));
19
+ })(ActivationState = ActivationState || (ActivationState = {}));
20
20
  //# sourceMappingURL=types.js.map
package/esm6/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA0IA;;GAEG;AACH,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,mEAAU,CAAA;IACV,uDAAI,CAAA;IACJ,6DAAO,CAAA;IACP,2DAAM,CAAA;AACR,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,yDAAM,CAAA;IACN,qEAAY,CAAA;IACZ,6DAAQ,CAAA;AACV,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2IA;;GAEG;AACH,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,mEAAU,CAAA;IACV,uDAAI,CAAA;IACJ,6DAAO,CAAA;IACP,2DAAM,CAAA;AACR,CAAC,EALW,gBAAgB,GAAhB,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,yDAAM,CAAA;IACN,qEAAY,CAAA;IACZ,6DAAQ,CAAA;AACV,CAAC,EAJW,eAAe,GAAf,eAAe,KAAf,eAAe,QAI1B"}
package/esm6/versions.js CHANGED
@@ -42,8 +42,8 @@ Versions.V1_2 = '1.2';
42
42
  * @internal
43
43
  */
44
44
  Versions.default = new Versions([
45
- Versions.V1_0,
46
- Versions.V1_1,
47
45
  Versions.V1_2,
46
+ Versions.V1_1,
47
+ Versions.V1_0,
48
48
  ]);
49
49
  //# sourceMappingURL=versions.js.map
package/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './esm6/';
1
+ export * from './esm6/index.js';
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@stomp/stompjs",
3
- "version": "6.1.2",
3
+ "version": "7.0.0-beta2",
4
4
  "description": "STOMP client for Javascript and Typescript",
5
5
  "scripts": {
6
6
  "clean": "rm -rf bundles esm6",
7
- "build-webpack": "webpack && webpack --mode=production --output-filename=stomp.umd.min.js",
8
- "build": "npm run clean && npx tsc && npm run build-webpack",
9
- "test": "jasmine",
10
- "karma": "karma start --single-run",
7
+ "rollup": "rollup -c && rm -rf bundles/*.d.ts bundles/compatibility/",
8
+ "build": "npm run clean && npx tsc && npm run rollup",
9
+ "test": "cp bundles/stomp.umd.js spec/dist && jasmine",
10
+ "karma": "karma start spec/karma.conf.js --single-run",
11
11
  "lint": "tslint 'src/**/*.ts'",
12
12
  "prettier": "prettier --write .",
13
+ "test-helpers": "tsc -p spec/helpers-src/tsconfig.json",
13
14
  "prepublishOnly": "npm run lint && npm run build && npm run karma && npm run test"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
17
- "url": "git+https://github.com/stomp-js/stompjs.git"
18
+ "url": "https://github.com/stomp-js/stompjs.git"
18
19
  },
19
20
  "keywords": [
20
21
  "STOMP",
@@ -32,27 +33,29 @@
32
33
  },
33
34
  "homepage": "https://github.com/stomp-js/stompjs#readme",
34
35
  "devDependencies": {
35
- "@chiragrupani/karma-chromium-edge-launcher": "^2.0.0",
36
- "awesome-typescript-loader": "^5.2.0",
37
- "jasmine": "^3.1.0",
38
- "karma": "^5.0.3",
39
- "karma-chrome-launcher": "^3.0.0",
40
- "karma-firefox-launcher": "^2.0.0",
41
- "karma-jasmine": "^4.0.0",
42
- "karma-safari-launcher": "git://github.com/RLovelett/karma-safari-launcher.git#safari-webdriver",
43
- "karma-summary-reporter": "^2.0.2",
44
- "prettier": "^2.1.2",
36
+ "@chiragrupani/karma-chromium-edge-launcher": "^2.2.2",
37
+ "@rollup/plugin-terser": "^0.2.1",
38
+ "@rollup/plugin-typescript": "^10.0.1",
39
+ "jasmine": "^4.3.0",
40
+ "karma": "^6.4.0",
41
+ "karma-chrome-launcher": "^3.1.1",
42
+ "karma-firefox-launcher": "^2.1.2",
43
+ "karma-jasmine": "^5.1.0",
44
+ "karma-safari-launcher": "https://github.com/RLovelett/karma-safari-launcher.git#safari-webdriver",
45
+ "karma-summary-reporter": "^3.1.1",
46
+ "onchange": "^7.1.0",
47
+ "prettier": "^2.7.1",
48
+ "rollup": "^3.9.1",
45
49
  "text-encoding": "^0.7.0",
46
- "tslint": "^6.0.0",
50
+ "ts-loader": "^9.3.1",
51
+ "tslint": "^6.1.3",
47
52
  "tslint-config-prettier": "^1.18.0",
48
- "typescript": "=3.6.4",
49
- "webpack": "^4.33.0",
50
- "webpack-cli": "^3.3.2",
51
- "ws": "^8.2.0"
53
+ "typescript": "^4.8.2",
54
+ "ws": "^8.8.1"
52
55
  },
53
- "module": "./esm6/index.js",
54
- "main": "bundles/stomp.umd.js",
56
+ "type": "module",
57
+ "exports": "./esm6/index.js",
58
+ "browser": "./bundles/stomp.umd.js",
55
59
  "typings": "index.d.ts",
56
- "sideEffects": false,
57
- "dependencies": {}
60
+ "sideEffects": false
58
61
  }
@@ -1,4 +1,4 @@
1
- import { IStompSocket } from './types';
1
+ import { IStompSocket } from './types.js';
2
2
 
3
3
  /**
4
4
  * @internal
@@ -16,6 +16,7 @@ export function augmentWebsocket(
16
16
  this.onopen = noOp;
17
17
 
18
18
  const ts = new Date();
19
+ const id = Math.random().toString().substring(2, 8); // A simulated id
19
20
 
20
21
  const origOnClose = this.onclose;
21
22
 
@@ -23,15 +24,15 @@ export function augmentWebsocket(
23
24
  this.onclose = closeEvent => {
24
25
  const delay = new Date().getTime() - ts.getTime();
25
26
  debug(
26
- `Discarded socket closed after ${delay}ms, with code/reason: ${closeEvent.code}/${closeEvent.reason}`
27
+ `Discarded socket (#${id}) closed after ${delay}ms, with code/reason: ${closeEvent.code}/${closeEvent.reason}`
27
28
  );
28
29
  };
29
30
 
30
31
  this.close();
31
32
 
32
- origOnClose.call(this, {
33
+ origOnClose?.call(webSocket, {
33
34
  code: 4001,
34
- reason: 'Heartbeat failure, discarding the socket',
35
+ reason: `Quick discarding socket (#${id}) without waiting for the shutdown sequence.`,
35
36
  wasClean: false,
36
37
  });
37
38
  };
package/src/client.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ITransaction } from './i-transaction';
2
- import { StompConfig } from './stomp-config';
3
- import { StompHandler } from './stomp-handler';
4
- import { StompHeaders } from './stomp-headers';
5
- import { StompSubscription } from './stomp-subscription';
1
+ import { ITransaction } from './i-transaction.js';
2
+ import { StompConfig } from './stomp-config.js';
3
+ import { StompHandler } from './stomp-handler.js';
4
+ import { StompHeaders } from './stomp-headers.js';
5
+ import { StompSubscription } from './stomp-subscription.js';
6
6
  import {
7
7
  ActivationState,
8
8
  closeEventCallbackType,
@@ -13,8 +13,8 @@ import {
13
13
  messageCallbackType,
14
14
  StompSocketState,
15
15
  wsErrorCallbackType,
16
- } from './types';
17
- import { Versions } from './versions';
16
+ } from './types.js';
17
+ import { Versions } from './versions.js';
18
18
 
19
19
  /**
20
20
  * @internal
@@ -40,7 +40,7 @@ export class Client {
40
40
  * If your environment does not support WebSockets natively, please refer to
41
41
  * [Polyfills]{@link https://stomp-js.github.io/guide/stompjs/rx-stomp/ng2-stompjs/pollyfils-for-stompjs-v5.html}.
42
42
  */
43
- public brokerURL: string;
43
+ public brokerURL: string | undefined;
44
44
 
45
45
  /**
46
46
  * STOMP versions to attempt during STOMP handshake. By default versions `1.0`, `1.1`, and `1.2` are attempted.
@@ -74,7 +74,7 @@ export class Client {
74
74
  * };
75
75
  * ```
76
76
  */
77
- public webSocketFactory: () => IStompSocket;
77
+ public webSocketFactory: (() => IStompSocket) | undefined;
78
78
 
79
79
  /**
80
80
  * Will retry if Stomp connection is not established in specified milliseconds.
@@ -82,7 +82,8 @@ export class Client {
82
82
  */
83
83
  public connectionTimeout: number = 0;
84
84
 
85
- private _connectionWatcher: number; // Timer
85
+ // As per https://stackoverflow.com/questions/45802988/typescript-use-correct-version-of-settimeout-node-vs-window/56239226#56239226
86
+ private _connectionWatcher: ReturnType<typeof setTimeout> | undefined; // Timer
86
87
 
87
88
  /**
88
89
  * automatically reconnect with delay in milliseconds, set to 0 to disable.
@@ -145,8 +146,8 @@ export class Client {
145
146
  /**
146
147
  * Underlying WebSocket instance, READONLY.
147
148
  */
148
- get webSocket(): IStompSocket {
149
- return this._stompHandler ? this._stompHandler._webSocket : undefined;
149
+ get webSocket(): IStompSocket | undefined {
150
+ return this._stompHandler?._webSocket;
150
151
  }
151
152
 
152
153
  /**
@@ -298,16 +299,16 @@ export class Client {
298
299
  * In case of incoming heartbeat failure, this experimental flag instructs the library
299
300
  * to discard the socket immediately (even before it is actually closed).
300
301
  */
301
- public discardWebsocketOnCommFailure: boolean;
302
+ public discardWebsocketOnCommFailure: boolean = false;
302
303
 
303
304
  /**
304
305
  * version of STOMP protocol negotiated with the server, READONLY
305
306
  */
306
- get connectedVersion(): string {
307
+ get connectedVersion(): string | undefined {
307
308
  return this._stompHandler ? this._stompHandler.connectedVersion : undefined;
308
309
  }
309
310
 
310
- private _stompHandler: StompHandler;
311
+ private _stompHandler: StompHandler | undefined;
311
312
 
312
313
  /**
313
314
  * if the client is active (connected or going to reconnect)
@@ -328,9 +329,6 @@ export class Client {
328
329
  this.onChangeState(state);
329
330
  }
330
331
 
331
- // This will mark deactivate to complete, to be called after Websocket is closed
332
- private _resolveSocketClose: (value?: PromiseLike<void> | void) => void;
333
-
334
332
  /**
335
333
  * Activation state.
336
334
  *
@@ -481,14 +479,13 @@ export class Client {
481
479
 
482
480
  if (this.state === ActivationState.DEACTIVATING) {
483
481
  // Mark deactivation complete
484
- this._resolveSocketClose();
485
- this._resolveSocketClose = undefined;
486
482
  this._changeState(ActivationState.INACTIVE);
487
483
  }
488
484
 
489
- this.onWebSocketClose(evt);
490
485
  // The callback is called before attempting to reconnect, this would allow the client
491
486
  // to be `deactivated` in the callback.
487
+ this.onWebSocketClose(evt);
488
+
492
489
  if (this.active) {
493
490
  this._schedule_reconnect();
494
491
  }
@@ -515,11 +512,13 @@ export class Client {
515
512
 
516
513
  if (this.webSocketFactory) {
517
514
  webSocket = this.webSocketFactory();
518
- } else {
515
+ } else if (this.brokerURL) {
519
516
  webSocket = new WebSocket(
520
517
  this.brokerURL,
521
518
  this.stompVersions.protocolVersions()
522
519
  );
520
+ } else {
521
+ throw new Error('Either brokerURL or webSocketFactory must be provided');
523
522
  }
524
523
  webSocket.binaryType = 'arraybuffer';
525
524
  return webSocket;
@@ -537,20 +536,33 @@ export class Client {
537
536
 
538
537
  /**
539
538
  * Disconnect if connected and stop auto reconnect loop.
540
- * Appropriate callbacks will be invoked if underlying STOMP connection was connected.
539
+ * Appropriate callbacks will be invoked if there is an underlying STOMP connection.
540
+ *
541
+ * This call is async. It will resolve immediately if there is no underlying active websocket,
542
+ * otherwise, it will resolve after the underlying websocket is properly disposed of.
543
+ *
544
+ * It is not an error to invoke this method more than once.
545
+ * Each of those would resolve on completion of deactivation.
541
546
  *
542
- * This call is async, it will resolve immediately if there is no underlying active websocket,
543
- * otherwise, it will resolve after underlying websocket is properly disposed.
547
+ * To reactivate, you can call [Client#activate]{@link Client#activate}.
544
548
  *
545
- * To reactivate you can call [Client#activate]{@link Client#activate}.
549
+ * Experimental: pass `force: true` to immediately discard the underlying connection.
550
+ * This mode will skip both the STOMP and the Websocket shutdown sequences.
551
+ * In some cases, browsers take a long time in the Websocket shutdown if the underlying connection had gone stale.
552
+ * Using this mode can speed up.
553
+ * When this mode is used, the actual Websocket may linger for a while
554
+ * and the broker may not realize that the connection is no longer in use.
555
+ *
556
+ * It is possible to invoke this method initially without the `force` option
557
+ * and subsequently, say after a wait, with the `force` option.
546
558
  */
547
- public async deactivate(): Promise<void> {
559
+ public async deactivate(options: { force?: boolean } = {}): Promise<void> {
560
+ const force: boolean = options.force || false;
561
+ const needToDispose = this.active;
548
562
  let retPromise: Promise<void>;
549
563
 
550
- if (this.state !== ActivationState.ACTIVE) {
551
- this.debug(
552
- `Already ${ActivationState[this.state]}, ignoring call to deactivate`
553
- );
564
+ if (this.state === ActivationState.INACTIVE) {
565
+ this.debug(`Already INACTIVE, nothing more to do`);
554
566
  return Promise.resolve();
555
567
  }
556
568
 
@@ -559,15 +571,22 @@ export class Client {
559
571
  // Clear if a reconnection was scheduled
560
572
  if (this._reconnector) {
561
573
  clearTimeout(this._reconnector);
574
+ this._reconnector = undefined;
562
575
  }
563
576
 
564
577
  if (
565
578
  this._stompHandler &&
579
+ // @ts-ignore - if there is a _stompHandler, there is the webSocket
566
580
  this.webSocket.readyState !== StompSocketState.CLOSED
567
581
  ) {
568
- // we need to wait for underlying websocket to close
582
+ const origOnWebSocketClose = this._stompHandler.onWebSocketClose;
583
+ // we need to wait for the underlying websocket to close
569
584
  retPromise = new Promise<void>((resolve, reject) => {
570
- this._resolveSocketClose = resolve;
585
+ // @ts-ignore - there is a _stompHandler
586
+ this._stompHandler.onWebSocketClose = evt => {
587
+ origOnWebSocketClose(evt);
588
+ resolve();
589
+ };
571
590
  });
572
591
  } else {
573
592
  // indicate that auto reconnect loop should terminate
@@ -575,7 +594,11 @@ export class Client {
575
594
  return Promise.resolve();
576
595
  }
577
596
 
578
- this._disposeStompHandler();
597
+ if (force) {
598
+ this._stompHandler?.discardWebsocket();
599
+ } else if (needToDispose) {
600
+ this._disposeStompHandler();
601
+ }
579
602
 
580
603
  return retPromise;
581
604
  }
@@ -596,7 +619,6 @@ export class Client {
596
619
  // Dispose STOMP Handler
597
620
  if (this._stompHandler) {
598
621
  this._stompHandler.dispose();
599
- this._stompHandler = null;
600
622
  }
601
623
  }
602
624
 
@@ -637,9 +659,17 @@ export class Client {
637
659
  * ```
638
660
  */
639
661
  public publish(params: IPublishParams) {
662
+ this._checkConnection();
663
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
640
664
  this._stompHandler.publish(params);
641
665
  }
642
666
 
667
+ private _checkConnection() {
668
+ if (!this.connected) {
669
+ throw new TypeError('There is no underlying STOMP connection');
670
+ }
671
+ }
672
+
643
673
  /**
644
674
  * STOMP brokers may carry out operation asynchronously and allow requesting for acknowledgement.
645
675
  * To request an acknowledgement, a `receipt` header needs to be sent with the actual request.
@@ -676,6 +706,8 @@ export class Client {
676
706
  * ```
677
707
  */
678
708
  public watchForReceipt(receiptId: string, callback: frameCallbackType): void {
709
+ this._checkConnection();
710
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
679
711
  this._stompHandler.watchForReceipt(receiptId, callback);
680
712
  }
681
713
 
@@ -708,6 +740,8 @@ export class Client {
708
740
  callback: messageCallbackType,
709
741
  headers: StompHeaders = {}
710
742
  ): StompSubscription {
743
+ this._checkConnection();
744
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
711
745
  return this._stompHandler.subscribe(destination, callback, headers);
712
746
  }
713
747
 
@@ -724,6 +758,8 @@ export class Client {
724
758
  * See: http://stomp.github.com/stomp-specification-1.2.html#UNSUBSCRIBE UNSUBSCRIBE Frame
725
759
  */
726
760
  public unsubscribe(id: string, headers: StompHeaders = {}): void {
761
+ this._checkConnection();
762
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
727
763
  this._stompHandler.unsubscribe(id, headers);
728
764
  }
729
765
 
@@ -734,6 +770,8 @@ export class Client {
734
770
  * `transactionId` is optional, if not passed the library will generate it internally.
735
771
  */
736
772
  public begin(transactionId?: string): ITransaction {
773
+ this._checkConnection();
774
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
737
775
  return this._stompHandler.begin(transactionId);
738
776
  }
739
777
 
@@ -750,6 +788,8 @@ export class Client {
750
788
  * ```
751
789
  */
752
790
  public commit(transactionId: string): void {
791
+ this._checkConnection();
792
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
753
793
  this._stompHandler.commit(transactionId);
754
794
  }
755
795
 
@@ -765,6 +805,8 @@ export class Client {
765
805
  * ```
766
806
  */
767
807
  public abort(transactionId: string): void {
808
+ this._checkConnection();
809
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
768
810
  this._stompHandler.abort(transactionId);
769
811
  }
770
812
 
@@ -786,6 +828,8 @@ export class Client {
786
828
  subscriptionId: string,
787
829
  headers: StompHeaders = {}
788
830
  ): void {
831
+ this._checkConnection();
832
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
789
833
  this._stompHandler.ack(messageId, subscriptionId, headers);
790
834
  }
791
835
 
@@ -807,6 +851,8 @@ export class Client {
807
851
  subscriptionId: string,
808
852
  headers: StompHeaders = {}
809
853
  ): void {
854
+ this._checkConnection();
855
+ // @ts-ignore - we already checked that there is a _stompHandler, and it is connected
810
856
  this._stompHandler.nack(messageId, subscriptionId, headers);
811
857
  }
812
858
  }
@@ -1,7 +1,7 @@
1
- import { Client } from '../client';
2
- import { StompHeaders } from '../stomp-headers';
3
- import { frameCallbackType, messageCallbackType } from '../types';
4
- import { HeartbeatInfo } from './heartbeat-info';
1
+ import { Client } from '../client.js';
2
+ import { StompHeaders } from '../stomp-headers.js';
3
+ import { frameCallbackType, messageCallbackType } from '../types.js';
4
+ import { HeartbeatInfo } from './heartbeat-info.js';
5
5
 
6
6
  /**
7
7
  * Available for backward compatibility, please shift to using {@link Client}.
@@ -1,4 +1,4 @@
1
- import { CompatClient } from './compat-client';
1
+ import { CompatClient } from './compat-client.js';
2
2
 
3
3
  /**
4
4
  * Part of `@stomp/stompjs`.
@@ -1,6 +1,6 @@
1
- import { Versions } from '../versions';
2
- import { CompatClient } from './compat-client';
3
- import { IStompSocket } from '../types';
1
+ import { Versions } from '../versions.js';
2
+ import { CompatClient } from './compat-client.js';
3
+ import { IStompSocket } from '../types.js';
4
4
 
5
5
  /**
6
6
  * @internal
package/src/frame-impl.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { BYTE } from './byte';
2
- import { IFrame } from './i-frame';
3
- import { StompHeaders } from './stomp-headers';
4
- import { IRawFrameType } from './types';
1
+ import { BYTE } from './byte.js';
2
+ import { IFrame } from './i-frame.js';
3
+ import { StompHeaders } from './stomp-headers.js';
4
+ import { IRawFrameType } from './types.js';
5
5
 
6
6
  /**
7
7
  * Frame class represents a STOMP frame.
@@ -31,9 +31,9 @@ export class FrameImpl implements IFrame {
31
31
  if (!this._body && this.isBinaryBody) {
32
32
  this._body = new TextDecoder().decode(this._binaryBody);
33
33
  }
34
- return this._body;
34
+ return this._body || '';
35
35
  }
36
- private _body: string;
36
+ private _body: string | undefined;
37
37
 
38
38
  /**
39
39
  * body as Uint8Array
@@ -42,9 +42,10 @@ export class FrameImpl implements IFrame {
42
42
  if (!this._binaryBody && !this.isBinaryBody) {
43
43
  this._binaryBody = new TextEncoder().encode(this._body);
44
44
  }
45
- return this._binaryBody;
45
+ // At this stage it will definitely have a valid value
46
+ return this._binaryBody as Uint8Array;
46
47
  }
47
- private _binaryBody: Uint8Array;
48
+ private _binaryBody: Uint8Array | undefined;
48
49
 
49
50
  private escapeHeaderValues: boolean;
50
51
  private skipContentLengthHeader: boolean;
@@ -115,7 +116,7 @@ export class FrameImpl implements IFrame {
115
116
  }
116
117
 
117
118
  return new FrameImpl({
118
- command: rawFrame.command,
119
+ command: rawFrame.command as string,
119
120
  headers,
120
121
  binaryBody: rawFrame.binaryBody,
121
122
  escapeHeaderValues,
@@ -140,7 +141,10 @@ export class FrameImpl implements IFrame {
140
141
  const cmdAndHeaders = this.serializeCmdAndHeaders();
141
142
 
142
143
  if (this.isBinaryBody) {
143
- return FrameImpl.toUnit8Array(cmdAndHeaders, this._binaryBody).buffer;
144
+ return FrameImpl.toUnit8Array(
145
+ cmdAndHeaders,
146
+ this._binaryBody as Uint8Array
147
+ ).buffer;
144
148
  } else {
145
149
  return cmdAndHeaders + this._body + BYTE.NULL;
146
150
  }
package/src/i-frame.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StompHeaders } from './stomp-headers';
1
+ import { StompHeaders } from './stomp-headers.js';
2
2
 
3
3
  /**
4
4
  * It represents a STOMP frame. Many of the callbacks pass an IFrame received from
package/src/i-message.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IFrame } from './i-frame';
2
- import { StompHeaders } from './stomp-headers';
1
+ import { IFrame } from './i-frame.js';
2
+ import { StompHeaders } from './stomp-headers.js';
3
3
 
4
4
  /**
5
5
  * Instance of Message will be passed to [subscription callback]{@link Client#subscribe}
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- export * from './client';
2
- export * from './frame-impl';
3
- export * from './i-frame';
4
- export * from './i-message';
5
- export * from './parser';
6
- export * from './stomp-config';
7
- export * from './stomp-headers';
8
- export * from './stomp-subscription';
9
- export * from './i-transaction';
10
- export * from './types';
11
- export * from './versions';
1
+ export * from './client.js';
2
+ export * from './frame-impl.js';
3
+ export * from './i-frame.js';
4
+ export * from './i-message.js';
5
+ export * from './parser.js';
6
+ export * from './stomp-config.js';
7
+ export * from './stomp-headers.js';
8
+ export * from './stomp-subscription.js';
9
+ export * from './i-transaction.js';
10
+ export * from './types.js';
11
+ export * from './versions.js';
12
12
 
13
13
  // Compatibility code
14
- export * from './compatibility/compat-client';
15
- export * from './compatibility/stomp';
14
+ export * from './compatibility/compat-client.js';
15
+ export * from './compatibility/stomp.js';