Skip to content

Commit 346bd25

Browse files
author
Deepak Kumar
committed
Refined STOMP.js documentation: clarified Node.js and browser support, updated examples for ES modules and UMD, and adjusted terminology for consistency.
1 parent 3925ecb commit 346bd25

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

_posts/2018-09-08-upgrading-stompjs.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ redirect_from:
1212

1313
## Upgrading from version 3/4
1414

15-
_Important: For NodeJS and React Native, please check [Polyfills]._
15+
_Important: For Node.js and React Native, please check [Polyfills]._
1616

1717
### Basic changes
1818

@@ -24,10 +24,12 @@ The following is for convenience, — to keep the code change to the minimum.
2424
```javascript
2525
// Depending on your JS version you may have to use var instead of const
2626

27-
// To use compatibility mode
27+
// To use compatibility mode (UMD build via <script>)
2828
const Stomp = StompJs.Stomp;
2929
```
3030

31+
CommonJS `require` is not supported; use ES module imports in Node.js or bundlers.
32+
3133
### For the lazy: use the compatibility mode
3234

3335
With the changes above, your code should now work. If you face issues, please
@@ -72,7 +74,7 @@ client.connect('user', 'password', function () {
7274
});
7375
```
7476

75-
**Updated**
77+
**Updated (UMD via <script>)**
7678

7779
```javascript
7880
const client = new StompJs.Client({
@@ -96,10 +98,40 @@ client.onConnect = function (frame) {
9698
client.activate();
9799
```
98100

101+
**Updated (ES modules)**
102+
103+
```javascript
104+
import { Client } from '@stomp/stompjs';
105+
106+
const client = new Client({
107+
brokerURL: 'ws://localhost:15674/ws',
108+
connectHeaders: {
109+
login: 'user',
110+
passcode: 'password',
111+
},
112+
debug: (str) => console.log(str),
113+
reconnectDelay: 5000,
114+
heartbeatIncoming: 4000,
115+
heartbeatOutgoing: 4000,
116+
});
117+
118+
client.onConnect = () => {
119+
// Do something
120+
};
121+
122+
client.activate();
123+
```
124+
125+
To disconnect and stop reconnection attempts, call [Client#deactivate](/api-docs/latest/classes/Client.html#deactivate). This method is asynchronous; prefer awaiting it to avoid races:
126+
127+
```javascript
128+
await client.deactivate();
129+
```
130+
99131
Please see [StompConfig](/api-docs/latest/classes/StompConfig.html) for all possible options.
100132
These options can be set onto [client](/api-docs/latest/classes/Client.html).
101133
Alternatively, these can be passed
102-
as options to the [Client constructor](/api-docs/latest/classes/Client.html#constructor) constructor,
134+
as options to the [Client constructor](/api-docs/latest/classes/Client.html#constructor),
103135
the [Client#activate](/api-docs/latest/classes/Client.html#activate)
104136
or the [Client#deactivate](/api-docs/latest/classes/Client.html#deactivate) calls.
105137
If you want to set options in bulk, you can use [Client#configure](/api-docs/latest/classes/Client.html#configure).
@@ -123,7 +155,7 @@ client.send('/topic/general', { priority: '9' }, 'Hello world');
123155
```javascript
124156
client.publish({ destination: '/topic/general', body: 'Hello world' });
125157

126-
// There is an option to skip content length header
158+
// There is an option to skip content-length header
127159
client.publish({
128160
destination: '/topic/general',
129161
body: 'Hello world',
@@ -190,7 +222,7 @@ Please note:
190222
Additional notes:
191223

192224
- `Stomp.overWS` is same as `Stomp.client`. Follow the instructions for `Stomp.client` above.
193-
- `NodeJS` is supported at same level as browser. Test suits are executed for both NodJS and browser.
225+
- `Node.js` is supported at same level as browser. Test suites are executed for both Node.js and browser.
194226
Follow the instructions as above.
195227
- `Stomp.overTCP` is no longer supported by this library. However, you can use [TCP Wrapper](https://github.com/stomp-js/tcp-wrapper).
196228
- If you are using `SockJS` please also see [SockJS support]

0 commit comments

Comments
 (0)