You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refined STOMP.js documentation: clarified Node.js and browser support, updated examples for ES modules and UMD, and adjusted terminology for consistency.
Copy file name to clipboardExpand all lines: _posts/2018-09-08-upgrading-stompjs.md
+38-6Lines changed: 38 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ redirect_from:
12
12
13
13
## Upgrading from version 3/4
14
14
15
-
_Important: For NodeJS and React Native, please check [Polyfills]._
15
+
_Important: For Node.js and React Native, please check [Polyfills]._
16
16
17
17
### Basic changes
18
18
@@ -24,10 +24,12 @@ The following is for convenience, — to keep the code change to the minimum.
24
24
```javascript
25
25
// Depending on your JS version you may have to use var instead of const
26
26
27
-
// To use compatibility mode
27
+
// To use compatibility mode (UMD build via <script>)
28
28
constStomp=StompJs.Stomp;
29
29
```
30
30
31
+
CommonJS `require` is not supported; use ES module imports in Node.js or bundlers.
32
+
31
33
### For the lazy: use the compatibility mode
32
34
33
35
With the changes above, your code should now work. If you face issues, please
@@ -72,7 +74,7 @@ client.connect('user', 'password', function () {
72
74
});
73
75
```
74
76
75
-
**Updated**
77
+
**Updated (UMD via <script>)**
76
78
77
79
```javascript
78
80
constclient=newStompJs.Client({
@@ -96,10 +98,40 @@ client.onConnect = function (frame) {
96
98
client.activate();
97
99
```
98
100
101
+
**Updated (ES modules)**
102
+
103
+
```javascript
104
+
import { Client } from'@stomp/stompjs';
105
+
106
+
constclient=newClient({
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
+
awaitclient.deactivate();
129
+
```
130
+
99
131
Please see [StompConfig](/api-docs/latest/classes/StompConfig.html) for all possible options.
100
132
These options can be set onto [client](/api-docs/latest/classes/Client.html).
101
133
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),
103
135
the [Client#activate](/api-docs/latest/classes/Client.html#activate)
104
136
or the [Client#deactivate](/api-docs/latest/classes/Client.html#deactivate) calls.
105
137
If you want to set options in bulk, you can use [Client#configure](/api-docs/latest/classes/Client.html#configure).
0 commit comments