Skip to content

Commit e1aa949

Browse files
author
Yoseph Maguire
authored
chore: var to let/const and audit dev dependencies (mqttjs#1374)
* fix: audit dev dependencies * add changes * timeout * add timeout * remove aftereach * fixes
1 parent 2679952 commit e1aa949

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1173
-1134
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ npm install mqtt --save
8383
For the sake of simplicity, let's put the subscriber and the publisher in the same file:
8484

8585
```js
86-
var mqtt = require('mqtt')
87-
var client = mqtt.connect('mqtt://test.mosquitto.org')
86+
const mqtt = require('mqtt')
87+
const client = mqtt.connect('mqtt://test.mosquitto.org')
8888

8989
client.on('connect', function () {
9090
client.subscribe('presence', function (err) {
@@ -121,8 +121,8 @@ to use MQTT.js in the browser see the [browserify](#browserify) section
121121
## Import styles
122122
### CommonJS (Require)
123123
```js
124-
var mqtt = require('mqtt') // require mqtt
125-
var client = mqtt.connect('est.mosquitto.org') // create a client
124+
const mqtt = require('mqtt') // require mqtt
125+
const client = mqtt.connect('est.mosquitto.org') // create a client
126126
```
127127
### ES6 Modules (Import)
128128
#### Aliased wildcard import
@@ -695,7 +695,7 @@ gzip <browserMqtt.js | wc -c
695695
<a name="webpack"></a>
696696
### Webpack
697697

698-
Just like browserify, export MQTT.js as library. The exported module would be `var mqtt = xxx` and it will add an object in the global space. You could also export module in other [formats (AMD/CommonJS/others)](http://webpack.github.io/docs/configuration.html#output-librarytarget) by setting **output.libraryTarget** in webpack configuration.
698+
Just like browserify, export MQTT.js as library. The exported module would be `const mqtt = xxx` and it will add an object in the global space. You could also export module in other [formats (AMD/CommonJS/others)](http://webpack.github.io/docs/configuration.html#output-librarytarget) by setting **output.libraryTarget** in webpack configuration.
699699

700700
```javascript
701701
npm install -g webpack // install webpack
@@ -715,7 +715,7 @@ you can then use mqtt.js in the browser with the same api than node's one.
715715
<body>
716716
<script src="./browserMqtt.js"></script>
717717
<script>
718-
var client = mqtt.connect() // you add a ws:// url here
718+
const client = mqtt.connect() // you add a ws:// url here
719719
client.subscribe("mqtt/demo")
720720
721721
client.on("message", function (topic, payload) {
@@ -803,17 +803,17 @@ let client : mqtt.MqttClient = mqtt.connect('mqtt://test.mosquitto.org')
803803
Supports [WeChat Mini Program](https://mp.weixin.qq.com/). Use the `wxs` protocol. See [the WeChat docs](https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-socket.html).
804804
805805
```js
806-
var mqtt = require('mqtt')
807-
var client = mqtt.connect('wxs://test.mosquitto.org')
806+
const mqtt = require('mqtt')
807+
const client = mqtt.connect('wxs://test.mosquitto.org')
808808
```
809809
810810
### Ali Mini Program
811811
Supports [Ali Mini Program](https://open.alipay.com/channel/miniIndex.htm). Use the `alis` protocol. See [the Alipay docs](https://docs.alipay.com/mini/developer/getting-started).
812812
<a name="example"></a>
813813
814814
```js
815-
var mqtt = require('mqtt')
816-
var client = mqtt.connect('alis://test.mosquitto.org')
815+
const mqtt = require('mqtt')
816+
const client = mqtt.connect('alis://test.mosquitto.org')
817817
```
818818
819819
<a name="contributing"></a>

benchmarks/bombing.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/env node
22

3-
var mqtt = require('../')
4-
var client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, keepalive: 0 })
3+
const mqtt = require('../')
4+
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, keepalive: 0 })
55

6-
var sent = 0
7-
var interval = 5000
6+
let sent = 0
7+
const interval = 5000
88

99
function count () {
1010
console.log('sent/s', sent / interval * 1000)

benchmarks/throughputCounter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/env node
22

3-
var mqtt = require('../')
3+
const mqtt = require('../')
44

5-
var client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, encoding: 'binary', keepalive: 0 })
6-
var counter = 0
7-
var interval = 5000
5+
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, encoding: 'binary', keepalive: 0 })
6+
let counter = 0
7+
const interval = 5000
88

99
function count () {
1010
console.log('received/s', counter / interval * 1000)

bin/mqtt.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* See LICENSE for more information
99
*/
10-
var path = require('path')
11-
var commist = require('commist')()
12-
var helpMe = require('help-me')({
10+
const path = require('path')
11+
const commist = require('commist')()
12+
const helpMe = require('help-me')({
1313
dir: path.join(path.dirname(require.main.filename), '/../doc'),
1414
ext: '.txt'
1515
})

bin/pub.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
'use strict'
44

5-
var mqtt = require('../')
6-
var pump = require('pump')
7-
var path = require('path')
8-
var fs = require('fs')
9-
var concat = require('concat-stream')
10-
var Writable = require('readable-stream').Writable
11-
var helpMe = require('help-me')({
5+
const mqtt = require('../')
6+
const pump = require('pump')
7+
const path = require('path')
8+
const fs = require('fs')
9+
const concat = require('concat-stream')
10+
const Writable = require('readable-stream').Writable
11+
const helpMe = require('help-me')({
1212
dir: path.join(__dirname, '..', 'doc')
1313
})
14-
var minimist = require('minimist')
15-
var split2 = require('split2')
14+
const minimist = require('minimist')
15+
const split2 = require('split2')
1616

1717
function send (args) {
18-
var client = mqtt.connect(args)
18+
const client = mqtt.connect(args)
1919
client.on('connect', function () {
2020
client.publish(args.topic, args.message, args, function (err) {
2121
if (err) {
@@ -31,8 +31,8 @@ function send (args) {
3131
}
3232

3333
function multisend (args) {
34-
var client = mqtt.connect(args)
35-
var sender = new Writable({
34+
const client = mqtt.connect(args)
35+
const sender = new Writable({
3636
objectMode: true
3737
})
3838
sender._write = function (line, enc, cb) {

bin/sub.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
22

3-
var mqtt = require('../')
4-
var path = require('path')
5-
var fs = require('fs')
6-
var helpMe = require('help-me')({
3+
const mqtt = require('../')
4+
const path = require('path')
5+
const fs = require('fs')
6+
const helpMe = require('help-me')({
77
dir: path.join(__dirname, '..', 'doc')
88
})
9-
var minimist = require('minimist')
9+
const minimist = require('minimist')
1010

1111
function start (args) {
1212
args = minimist(args, {
@@ -84,7 +84,7 @@ function start (args) {
8484

8585
args.keepAlive = args['keep-alive']
8686

87-
var client = mqtt.connect(args)
87+
const client = mqtt.connect(args)
8888

8989
client.on('connect', function () {
9090
client.subscribe(args.topic, { qos: args.qos }, function (err, result) {

example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var mqtt = require('./')
2-
var client = mqtt.connect('mqtt://test.mosquitto.org')
1+
const mqtt = require('./')
2+
const client = mqtt.connect('mqtt://test.mosquitto.org')
33

44
client.subscribe('presence')
55
client.publish('presence', 'Hello mqtt')

examples/client/secure-client.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
'use strict'
22

3-
var mqtt = require('../..')
4-
var path = require('path')
5-
var fs = require('fs')
6-
var KEY = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-key.pem'))
7-
var CERT = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-cert.pem'))
3+
const mqtt = require('../..')
4+
const path = require('path')
5+
const fs = require('fs')
6+
const KEY = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-key.pem'))
7+
const CERT = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-cert.pem'))
88

9-
var PORT = 8443
9+
const PORT = 8443
1010

11-
var options = {
11+
const options = {
1212
port: PORT,
1313
key: KEY,
1414
cert: CERT,
1515
rejectUnauthorized: false
1616
}
1717

18-
var client = mqtt.connect(options)
18+
const client = mqtt.connect(options)
1919

2020
client.subscribe('messages')
2121
client.publish('messages', 'Current time is: ' + new Date())

examples/client/simple-both.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
var mqtt = require('../..')
4-
var client = mqtt.connect()
3+
const mqtt = require('../..')
4+
const client = mqtt.connect()
55

6-
// or var client = mqtt.connect({ port: 1883, host: '192.168.1.100', keepalive: 10000});
6+
// or const client = mqtt.connect({ port: 1883, host: '192.168.1.100', keepalive: 10000});
77

88
client.subscribe('presence')
99
client.publish('presence', 'bin hier')

examples/client/simple-publish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
var mqtt = require('../..')
4-
var client = mqtt.connect()
3+
const mqtt = require('../..')
4+
const client = mqtt.connect()
55

66
client.publish('presence', 'hello!')
77
client.end()

examples/client/simple-subscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
var mqtt = require('../..')
4-
var client = mqtt.connect()
3+
const mqtt = require('../..')
4+
const client = mqtt.connect()
55

66
client.subscribe('presence')
77
client.on('message', function (topic, message) {

examples/tls client/mqttclient.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
<the ip address of the server> stark
1515
*******************************************************************************/
1616

17-
var mqtt = require('mqtt')
18-
var fs = require('fs')
19-
var path = require('path')
20-
var KEY = fs.readFileSync(path.join(__dirname, '/tls-key.pem'))
21-
var CERT = fs.readFileSync(path.join(__dirname, '/tls-cert.pem'))
22-
var TRUSTED_CA_LIST = fs.readFileSync(path.join(__dirname, '/crt.ca.cg.pem'))
17+
const mqtt = require('mqtt')
18+
const fs = require('fs')
19+
const path = require('path')
20+
const KEY = fs.readFileSync(path.join(__dirname, '/tls-key.pem'))
21+
const CERT = fs.readFileSync(path.join(__dirname, '/tls-cert.pem'))
22+
const TRUSTED_CA_LIST = fs.readFileSync(path.join(__dirname, '/crt.ca.cg.pem'))
2323

24-
var PORT = 1883
25-
var HOST = 'stark'
24+
const PORT = 1883
25+
const HOST = 'stark'
2626

27-
var options = {
27+
const options = {
2828
port: PORT,
2929
host: HOST,
3030
key: KEY,
@@ -35,7 +35,7 @@ var options = {
3535
protocol: 'mqtts'
3636
}
3737

38-
var client = mqtt.connect(options)
38+
const client = mqtt.connect(options)
3939

4040
client.subscribe('messages')
4141
client.publish('messages', 'Current time is: ' + new Date())

examples/ws/client.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
var mqtt = require('../../')
3+
const mqtt = require('../../')
44

5-
var clientId = 'mqttjs_' + Math.random().toString(16).substr(2, 8)
5+
const clientId = 'mqttjs_' + Math.random().toString(16).substr(2, 8)
66

77
// This sample should be run in tandem with the aedes_server.js file.
88
// Simply run it:
@@ -11,9 +11,9 @@ var clientId = 'mqttjs_' + Math.random().toString(16).substr(2, 8)
1111
// Then run this file in a separate console:
1212
// $ node websocket_sample.js
1313
//
14-
var host = 'ws://localhost:8080'
14+
const host = 'ws://localhost:8080'
1515

16-
var options = {
16+
const options = {
1717
keepalive: 30,
1818
clientId: clientId,
1919
protocolId: 'MQTT',
@@ -31,7 +31,7 @@ var options = {
3131
}
3232

3333
console.log('connecting mqtt client')
34-
var client = mqtt.connect(host, options)
34+
const client = mqtt.connect(host, options)
3535

3636
client.on('error', function (err) {
3737
console.log(err)

examples/wss/client_with_proxy.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
'use strict'
22

3-
var mqtt = require('mqtt')
4-
var url = require('url')
5-
var HttpsProxyAgent = require('https-proxy-agent')
3+
const mqtt = require('mqtt')
4+
const url = require('url')
5+
const HttpsProxyAgent = require('https-proxy-agent')
66
/*
77
host: host of the endpoint you want to connect e.g. my.mqqt.host.com
88
path: path to you endpoint e.g. '/foo/bar/mqtt'
99
*/
10-
var endpoint = 'wss://<host><path>'
10+
const endpoint = 'wss://<host><path>'
1111
/* create proxy agent
1212
proxy: your proxy e.g. proxy.foo.bar.com
1313
port: http proxy port e.g. 8080
1414
*/
15-
var proxy = process.env.http_proxy || 'http://<proxy>:<port>'
16-
var parsed = url.parse(endpoint)
17-
var proxyOpts = url.parse(proxy)
15+
const proxy = process.env.http_proxy || 'http://<proxy>:<port>'
16+
// eslint-disable-next-line
17+
const parsed = url.parse(endpoint)
18+
// eslint-disable-next-line
19+
const proxyOpts = url.parse(proxy)
1820
// true for wss
1921
proxyOpts.secureEndpoint = parsed.protocol ? parsed.protocol === 'wss:' : true
20-
var agent = new HttpsProxyAgent(proxyOpts)
21-
var wsOptions = {
22+
const agent = new HttpsProxyAgent(proxyOpts)
23+
const wsOptions = {
2224
agent: agent
2325
// other wsOptions
2426
// foo:'bar'
2527
}
26-
var mqttOptions = {
28+
const mqttOptions = {
2729
keepalive: 60,
2830
reschedulePings: true,
2931
protocolId: 'MQTT',
@@ -35,7 +37,7 @@ var mqttOptions = {
3537
wsOptions: wsOptions
3638
}
3739

38-
var client = mqtt.connect(parsed, mqttOptions)
40+
const client = mqtt.connect(parsed, mqttOptions)
3941

4042
client.on('connect', function () {
4143
console.log('connected')

0 commit comments

Comments
 (0)