@@ -12,7 +12,7 @@ Encode and Decode MQTT 3.1.1, 5.0 packets the node way.
12
12
* <a href =" #contributing " >Contributing</a >
13
13
* <a href =" #license " >License & ; copyright</a >
14
14
15
- This library is tested with node v4, v6 and v7 . The last version to support
15
+ This library is tested with node v6, v8, v10, v12 and v14 . The last version to support
16
16
older versions of node was
[email protected] .
17
17
18
18
Installation
@@ -28,17 +28,17 @@ Examples
28
28
### Generating
29
29
30
30
``` js
31
- var mqtt = require (' mqtt-packet' )
32
- var object = {
31
+ const mqtt = require (' mqtt-packet' );
32
+ const object = {
33
33
cmd: ' publish' ,
34
34
retain: false ,
35
35
qos: 0 ,
36
36
dup: false ,
37
37
length: 10 ,
38
38
topic: ' test' ,
39
39
payload: ' test' // Can also be a Buffer
40
- }
41
- var opts = { protocolVersion: 4 } // default is 4. Usually, opts is a connect packet
40
+ };
41
+ const opts = { protocolVersion: 4 }; // default is 4. Usually, opts is a connect packet
42
42
43
43
console .log (mqtt .generate (object))
44
44
// Prints:
@@ -47,7 +47,7 @@ console.log(mqtt.generate(object))
47
47
//
48
48
// Which is the same as:
49
49
//
50
- // new Buffer([
50
+ // Buffer.from ([
51
51
// 48, 10, // Header (publish)
52
52
// 0, 4, // Topic length
53
53
// 116, 101, 115, 116, // Topic (test)
@@ -58,12 +58,12 @@ console.log(mqtt.generate(object))
58
58
### Parsing
59
59
60
60
``` js
61
- var mqtt = require (' mqtt-packet' )
62
- var opts = { protocolVersion: 4 } // default is 4. Usually, opts is a connect packet
63
- var parser = mqtt .parser (opts)
61
+ const mqtt = require (' mqtt-packet' );
62
+ const opts = { protocolVersion: 4 }; // default is 4. Usually, opts is a connect packet
63
+ const parser = mqtt .parser (opts);
64
64
65
65
// Synchronously emits all the parsed packets
66
- parser .on (' packet' , function ( packet ) {
66
+ parser .on (' packet' , packet => {
67
67
console .log (packet)
68
68
// Prints:
69
69
//
@@ -78,7 +78,7 @@ parser.on('packet', function(packet) {
78
78
// }
79
79
})
80
80
81
- parser .parse (new Buffer ([
81
+ parser .parse (Buffer . from ([
82
82
48 , 10 , // Header (publish)
83
83
0 , 4 , // Topic length
84
84
116 , 101 , 115 , 116 , // Topic (test)
@@ -154,10 +154,10 @@ and that you can input to `generate`.
154
154
clientId: ' my-device' ,
155
155
keepalive: 0 , // Seconds which can be any positive number, with 0 as the default setting
156
156
username: ' matteo' ,
157
- password: new Buffer (' collina' ), // Passwords are buffers
157
+ password: Buffer . from (' collina' ), // Passwords are buffers
158
158
will: {
159
159
topic: ' mydevice/status' ,
160
- payload: new Buffer (' dead' ), // Payloads are buffers
160
+ payload: Buffer . from (' dead' ), // Payloads are buffers
161
161
properties: { // MQTT 5.0
162
162
willDelayInterval: 1234 ,
163
163
payloadFormatIndicator: false ,
@@ -316,7 +316,7 @@ All properties are mandatory.
316
316
qos: 2 ,
317
317
dup: false ,
318
318
topic: ' test' ,
319
- payload: new Buffer (' test' ),
319
+ payload: Buffer . from (' test' ),
320
320
retain: false ,
321
321
properties: { // optional properties MQTT 5.0
322
322
payloadFormatIndicator: true ,
0 commit comments