Skip to content

Commit

Permalink
chore: var to let/const and audit dev dependencies (mqttjs#1374)
Browse files Browse the repository at this point in the history
* fix: audit dev dependencies

* add changes

* timeout

* add timeout

* remove aftereach

* fixes
  • Loading branch information
Yoseph Maguire authored Dec 21, 2021
1 parent 2679952 commit e1aa949
Show file tree
Hide file tree
Showing 47 changed files with 1,173 additions and 1,134 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ npm install mqtt --save
For the sake of simplicity, let's put the subscriber and the publisher in the same file:

```js
var mqtt = require('mqtt')
var client = mqtt.connect('mqtt://test.mosquitto.org')
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://test.mosquitto.org')

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

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.
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.

```javascript
npm install -g webpack // install webpack
Expand All @@ -715,7 +715,7 @@ you can then use mqtt.js in the browser with the same api than node's one.
<body>
<script src="./browserMqtt.js"></script>
<script>
var client = mqtt.connect() // you add a ws:// url here
const client = mqtt.connect() // you add a ws:// url here
client.subscribe("mqtt/demo")
client.on("message", function (topic, payload) {
Expand Down Expand Up @@ -803,17 +803,17 @@ let client : mqtt.MqttClient = mqtt.connect('mqtt://test.mosquitto.org')
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).
```js
var mqtt = require('mqtt')
var client = mqtt.connect('wxs://test.mosquitto.org')
const mqtt = require('mqtt')
const client = mqtt.connect('wxs://test.mosquitto.org')
```
### Ali Mini Program
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).
<a name="example"></a>
```js
var mqtt = require('mqtt')
var client = mqtt.connect('alis://test.mosquitto.org')
const mqtt = require('mqtt')
const client = mqtt.connect('alis://test.mosquitto.org')
```
<a name="contributing"></a>
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/bombing.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /usr/bin/env node

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

var sent = 0
var interval = 5000
let sent = 0
const interval = 5000

function count () {
console.log('sent/s', sent / interval * 1000)
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/throughputCounter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /usr/bin/env node

var mqtt = require('../')
const mqtt = require('../')

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

function count () {
console.log('received/s', counter / interval * 1000)
Expand Down
6 changes: 3 additions & 3 deletions bin/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* See LICENSE for more information
*/
var path = require('path')
var commist = require('commist')()
var helpMe = require('help-me')({
const path = require('path')
const commist = require('commist')()
const helpMe = require('help-me')({
dir: path.join(path.dirname(require.main.filename), '/../doc'),
ext: '.txt'
})
Expand Down
24 changes: 12 additions & 12 deletions bin/pub.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

'use strict'

var mqtt = require('../')
var pump = require('pump')
var path = require('path')
var fs = require('fs')
var concat = require('concat-stream')
var Writable = require('readable-stream').Writable
var helpMe = require('help-me')({
const mqtt = require('../')
const pump = require('pump')
const path = require('path')
const fs = require('fs')
const concat = require('concat-stream')
const Writable = require('readable-stream').Writable
const helpMe = require('help-me')({
dir: path.join(__dirname, '..', 'doc')
})
var minimist = require('minimist')
var split2 = require('split2')
const minimist = require('minimist')
const split2 = require('split2')

function send (args) {
var client = mqtt.connect(args)
const client = mqtt.connect(args)
client.on('connect', function () {
client.publish(args.topic, args.message, args, function (err) {
if (err) {
Expand All @@ -31,8 +31,8 @@ function send (args) {
}

function multisend (args) {
var client = mqtt.connect(args)
var sender = new Writable({
const client = mqtt.connect(args)
const sender = new Writable({
objectMode: true
})
sender._write = function (line, enc, cb) {
Expand Down
12 changes: 6 additions & 6 deletions bin/sub.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

var mqtt = require('../')
var path = require('path')
var fs = require('fs')
var helpMe = require('help-me')({
const mqtt = require('../')
const path = require('path')
const fs = require('fs')
const helpMe = require('help-me')({
dir: path.join(__dirname, '..', 'doc')
})
var minimist = require('minimist')
const minimist = require('minimist')

function start (args) {
args = minimist(args, {
Expand Down Expand Up @@ -84,7 +84,7 @@ function start (args) {

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

var client = mqtt.connect(args)
const client = mqtt.connect(args)

client.on('connect', function () {
client.subscribe(args.topic, { qos: args.qos }, function (err, result) {
Expand Down
4 changes: 2 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mqtt = require('./')
var client = mqtt.connect('mqtt://test.mosquitto.org')
const mqtt = require('./')
const client = mqtt.connect('mqtt://test.mosquitto.org')

client.subscribe('presence')
client.publish('presence', 'Hello mqtt')
Expand Down
16 changes: 8 additions & 8 deletions examples/client/secure-client.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict'

var mqtt = require('../..')
var path = require('path')
var fs = require('fs')
var KEY = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-key.pem'))
var CERT = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-cert.pem'))
const mqtt = require('../..')
const path = require('path')
const fs = require('fs')
const KEY = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-key.pem'))
const CERT = fs.readFileSync(path.join(__dirname, '..', '..', 'test', 'helpers', 'tls-cert.pem'))

var PORT = 8443
const PORT = 8443

var options = {
const options = {
port: PORT,
key: KEY,
cert: CERT,
rejectUnauthorized: false
}

var client = mqtt.connect(options)
const client = mqtt.connect(options)

client.subscribe('messages')
client.publish('messages', 'Current time is: ' + new Date())
Expand Down
6 changes: 3 additions & 3 deletions examples/client/simple-both.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

var mqtt = require('../..')
var client = mqtt.connect()
const mqtt = require('../..')
const client = mqtt.connect()

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

client.subscribe('presence')
client.publish('presence', 'bin hier')
Expand Down
4 changes: 2 additions & 2 deletions examples/client/simple-publish.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

var mqtt = require('../..')
var client = mqtt.connect()
const mqtt = require('../..')
const client = mqtt.connect()

client.publish('presence', 'hello!')
client.end()
4 changes: 2 additions & 2 deletions examples/client/simple-subscribe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

var mqtt = require('../..')
var client = mqtt.connect()
const mqtt = require('../..')
const client = mqtt.connect()

client.subscribe('presence')
client.on('message', function (topic, message) {
Expand Down
20 changes: 10 additions & 10 deletions examples/tls client/mqttclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
<the ip address of the server> stark
*******************************************************************************/

var mqtt = require('mqtt')
var fs = require('fs')
var path = require('path')
var KEY = fs.readFileSync(path.join(__dirname, '/tls-key.pem'))
var CERT = fs.readFileSync(path.join(__dirname, '/tls-cert.pem'))
var TRUSTED_CA_LIST = fs.readFileSync(path.join(__dirname, '/crt.ca.cg.pem'))
const mqtt = require('mqtt')
const fs = require('fs')
const path = require('path')
const KEY = fs.readFileSync(path.join(__dirname, '/tls-key.pem'))
const CERT = fs.readFileSync(path.join(__dirname, '/tls-cert.pem'))
const TRUSTED_CA_LIST = fs.readFileSync(path.join(__dirname, '/crt.ca.cg.pem'))

var PORT = 1883
var HOST = 'stark'
const PORT = 1883
const HOST = 'stark'

var options = {
const options = {
port: PORT,
host: HOST,
key: KEY,
Expand All @@ -35,7 +35,7 @@ var options = {
protocol: 'mqtts'
}

var client = mqtt.connect(options)
const client = mqtt.connect(options)

client.subscribe('messages')
client.publish('messages', 'Current time is: ' + new Date())
Expand Down
10 changes: 5 additions & 5 deletions examples/ws/client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

var mqtt = require('../../')
const mqtt = require('../../')

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

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

var options = {
const options = {
keepalive: 30,
clientId: clientId,
protocolId: 'MQTT',
Expand All @@ -31,7 +31,7 @@ var options = {
}

console.log('connecting mqtt client')
var client = mqtt.connect(host, options)
const client = mqtt.connect(host, options)

client.on('error', function (err) {
console.log(err)
Expand Down
24 changes: 13 additions & 11 deletions examples/wss/client_with_proxy.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
'use strict'

var mqtt = require('mqtt')
var url = require('url')
var HttpsProxyAgent = require('https-proxy-agent')
const mqtt = require('mqtt')
const url = require('url')
const HttpsProxyAgent = require('https-proxy-agent')
/*
host: host of the endpoint you want to connect e.g. my.mqqt.host.com
path: path to you endpoint e.g. '/foo/bar/mqtt'
*/
var endpoint = 'wss://<host><path>'
const endpoint = 'wss://<host><path>'
/* create proxy agent
proxy: your proxy e.g. proxy.foo.bar.com
port: http proxy port e.g. 8080
*/
var proxy = process.env.http_proxy || 'http://<proxy>:<port>'
var parsed = url.parse(endpoint)
var proxyOpts = url.parse(proxy)
const proxy = process.env.http_proxy || 'http://<proxy>:<port>'
// eslint-disable-next-line
const parsed = url.parse(endpoint)
// eslint-disable-next-line
const proxyOpts = url.parse(proxy)
// true for wss
proxyOpts.secureEndpoint = parsed.protocol ? parsed.protocol === 'wss:' : true
var agent = new HttpsProxyAgent(proxyOpts)
var wsOptions = {
const agent = new HttpsProxyAgent(proxyOpts)
const wsOptions = {
agent: agent
// other wsOptions
// foo:'bar'
}
var mqttOptions = {
const mqttOptions = {
keepalive: 60,
reschedulePings: true,
protocolId: 'MQTT',
Expand All @@ -35,7 +37,7 @@ var mqttOptions = {
wsOptions: wsOptions
}

var client = mqtt.connect(parsed, mqttOptions)
const client = mqtt.connect(parsed, mqttOptions)

client.on('connect', function () {
console.log('connected')
Expand Down
Loading

0 comments on commit e1aa949

Please sign in to comment.