mqtt 4.2.7 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/mqtt.js CHANGED
@@ -1,27 +1,27 @@
1
- #!/usr/bin/env node
2
- 'use strict'
3
-
4
- /*
5
- * Copyright (c) 2015-2015 MQTT.js contributors.
6
- * Copyright (c) 2011-2014 Adam Rudd.
7
- *
8
- * See LICENSE for more information
9
- */
10
- var path = require('path')
11
- var commist = require('commist')()
12
- var helpMe = require('help-me')({
13
- dir: path.join(path.dirname(require.main.filename), '/../doc'),
14
- ext: '.txt'
15
- })
16
-
17
- commist.register('publish', require('./pub'))
18
- commist.register('subscribe', require('./sub'))
19
- commist.register('version', function () {
20
- console.log('MQTT.js version:', require('./../package.json').version)
21
- })
22
- commist.register('help', helpMe.toStdout)
23
-
24
- if (commist.parse(process.argv.slice(2)) !== null) {
25
- console.log('No such command:', process.argv[2], '\n')
26
- helpMe.toStdout()
27
- }
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+
4
+ /*
5
+ * Copyright (c) 2015-2015 MQTT.js contributors.
6
+ * Copyright (c) 2011-2014 Adam Rudd.
7
+ *
8
+ * See LICENSE for more information
9
+ */
10
+ const path = require('path')
11
+ const commist = require('commist')()
12
+ const helpMe = require('help-me')({
13
+ dir: path.join(path.dirname(require.main.filename), '/../doc'),
14
+ ext: '.txt'
15
+ })
16
+
17
+ commist.register('publish', require('./pub'))
18
+ commist.register('subscribe', require('./sub'))
19
+ commist.register('version', function () {
20
+ console.log('MQTT.js version:', require('./../package.json').version)
21
+ })
22
+ commist.register('help', helpMe.toStdout)
23
+
24
+ if (commist.parse(process.argv.slice(2)) !== null) {
25
+ console.log('No such command:', process.argv[2], '\n')
26
+ helpMe.toStdout()
27
+ }
package/bin/pub.js CHANGED
@@ -1,146 +1,146 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict'
4
-
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')({
12
- dir: path.join(__dirname, '..', 'doc')
13
- })
14
- var minimist = require('minimist')
15
- var split2 = require('split2')
16
-
17
- function send (args) {
18
- var client = mqtt.connect(args)
19
- client.on('connect', function () {
20
- client.publish(args.topic, args.message, args, function (err) {
21
- if (err) {
22
- console.warn(err)
23
- }
24
- client.end()
25
- })
26
- })
27
- client.on('error', function (err) {
28
- console.warn(err)
29
- client.end()
30
- })
31
- }
32
-
33
- function multisend (args) {
34
- var client = mqtt.connect(args)
35
- var sender = new Writable({
36
- objectMode: true
37
- })
38
- sender._write = function (line, enc, cb) {
39
- client.publish(args.topic, line.trim(), args, cb)
40
- }
41
-
42
- client.on('connect', function () {
43
- pump(process.stdin, split2(), sender, function (err) {
44
- client.end()
45
- if (err) {
46
- throw err
47
- }
48
- })
49
- })
50
- }
51
-
52
- function start (args) {
53
- args = minimist(args, {
54
- string: ['hostname', 'username', 'password', 'key', 'cert', 'ca', 'message', 'clientId', 'i', 'id'],
55
- boolean: ['stdin', 'retain', 'help', 'insecure', 'multiline'],
56
- alias: {
57
- port: 'p',
58
- hostname: ['h', 'host'],
59
- topic: 't',
60
- message: 'm',
61
- qos: 'q',
62
- clientId: ['i', 'id'],
63
- retain: 'r',
64
- username: 'u',
65
- password: 'P',
66
- stdin: 's',
67
- multiline: 'M',
68
- protocol: ['C', 'l'],
69
- help: 'H',
70
- ca: 'cafile'
71
- },
72
- default: {
73
- host: 'localhost',
74
- qos: 0,
75
- retain: false,
76
- topic: '',
77
- message: ''
78
- }
79
- })
80
-
81
- if (args.help) {
82
- return helpMe.toStdout('publish')
83
- }
84
-
85
- if (args.key) {
86
- args.key = fs.readFileSync(args.key)
87
- }
88
-
89
- if (args.cert) {
90
- args.cert = fs.readFileSync(args.cert)
91
- }
92
-
93
- if (args.ca) {
94
- args.ca = fs.readFileSync(args.ca)
95
- }
96
-
97
- if (args.key && args.cert && !args.protocol) {
98
- args.protocol = 'mqtts'
99
- }
100
-
101
- if (args.port) {
102
- if (typeof args.port !== 'number') {
103
- console.warn('# Port: number expected, \'%s\' was given.', typeof args.port)
104
- return
105
- }
106
- }
107
-
108
- if (args['will-topic']) {
109
- args.will = {}
110
- args.will.topic = args['will-topic']
111
- args.will.payload = args['will-message']
112
- args.will.qos = args['will-qos']
113
- args.will.retain = args['will-retain']
114
- }
115
-
116
- if (args.insecure) {
117
- args.rejectUnauthorized = false
118
- }
119
-
120
- args.topic = (args.topic || args._.shift()).toString()
121
- args.message = (args.message || args._.shift()).toString()
122
-
123
- if (!args.topic) {
124
- console.error('missing topic\n')
125
- return helpMe.toStdout('publish')
126
- }
127
-
128
- if (args.stdin) {
129
- if (args.multiline) {
130
- multisend(args)
131
- } else {
132
- process.stdin.pipe(concat(function (data) {
133
- args.message = data
134
- send(args)
135
- }))
136
- }
137
- } else {
138
- send(args)
139
- }
140
- }
141
-
142
- module.exports = start
143
-
144
- if (require.main === module) {
145
- start(process.argv.slice(2))
146
- }
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict'
4
+
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')({
12
+ dir: path.join(__dirname, '..', 'doc')
13
+ })
14
+ const minimist = require('minimist')
15
+ const split2 = require('split2')
16
+
17
+ function send (args) {
18
+ const client = mqtt.connect(args)
19
+ client.on('connect', function () {
20
+ client.publish(args.topic, args.message, args, function (err) {
21
+ if (err) {
22
+ console.warn(err)
23
+ }
24
+ client.end()
25
+ })
26
+ })
27
+ client.on('error', function (err) {
28
+ console.warn(err)
29
+ client.end()
30
+ })
31
+ }
32
+
33
+ function multisend (args) {
34
+ const client = mqtt.connect(args)
35
+ const sender = new Writable({
36
+ objectMode: true
37
+ })
38
+ sender._write = function (line, enc, cb) {
39
+ client.publish(args.topic, line.trim(), args, cb)
40
+ }
41
+
42
+ client.on('connect', function () {
43
+ pump(process.stdin, split2(), sender, function (err) {
44
+ client.end()
45
+ if (err) {
46
+ throw err
47
+ }
48
+ })
49
+ })
50
+ }
51
+
52
+ function start (args) {
53
+ args = minimist(args, {
54
+ string: ['hostname', 'username', 'password', 'key', 'cert', 'ca', 'message', 'clientId', 'i', 'id'],
55
+ boolean: ['stdin', 'retain', 'help', 'insecure', 'multiline'],
56
+ alias: {
57
+ port: 'p',
58
+ hostname: ['h', 'host'],
59
+ topic: 't',
60
+ message: 'm',
61
+ qos: 'q',
62
+ clientId: ['i', 'id'],
63
+ retain: 'r',
64
+ username: 'u',
65
+ password: 'P',
66
+ stdin: 's',
67
+ multiline: 'M',
68
+ protocol: ['C', 'l'],
69
+ help: 'H',
70
+ ca: 'cafile'
71
+ },
72
+ default: {
73
+ host: 'localhost',
74
+ qos: 0,
75
+ retain: false,
76
+ topic: '',
77
+ message: ''
78
+ }
79
+ })
80
+
81
+ if (args.help) {
82
+ return helpMe.toStdout('publish')
83
+ }
84
+
85
+ if (args.key) {
86
+ args.key = fs.readFileSync(args.key)
87
+ }
88
+
89
+ if (args.cert) {
90
+ args.cert = fs.readFileSync(args.cert)
91
+ }
92
+
93
+ if (args.ca) {
94
+ args.ca = fs.readFileSync(args.ca)
95
+ }
96
+
97
+ if (args.key && args.cert && !args.protocol) {
98
+ args.protocol = 'mqtts'
99
+ }
100
+
101
+ if (args.port) {
102
+ if (typeof args.port !== 'number') {
103
+ console.warn('# Port: number expected, \'%s\' was given.', typeof args.port)
104
+ return
105
+ }
106
+ }
107
+
108
+ if (args['will-topic']) {
109
+ args.will = {}
110
+ args.will.topic = args['will-topic']
111
+ args.will.payload = args['will-message']
112
+ args.will.qos = args['will-qos']
113
+ args.will.retain = args['will-retain']
114
+ }
115
+
116
+ if (args.insecure) {
117
+ args.rejectUnauthorized = false
118
+ }
119
+
120
+ args.topic = (args.topic || args._.shift()).toString()
121
+ args.message = (args.message || args._.shift()).toString()
122
+
123
+ if (!args.topic) {
124
+ console.error('missing topic\n')
125
+ return helpMe.toStdout('publish')
126
+ }
127
+
128
+ if (args.stdin) {
129
+ if (args.multiline) {
130
+ multisend(args)
131
+ } else {
132
+ process.stdin.pipe(concat(function (data) {
133
+ args.message = data
134
+ send(args)
135
+ }))
136
+ }
137
+ } else {
138
+ send(args)
139
+ }
140
+ }
141
+
142
+ module.exports = start
143
+
144
+ if (require.main === module) {
145
+ start(process.argv.slice(2))
146
+ }
package/bin/sub.js CHANGED
@@ -1,123 +1,123 @@
1
- #!/usr/bin/env node
2
-
3
- var mqtt = require('../')
4
- var path = require('path')
5
- var fs = require('fs')
6
- var helpMe = require('help-me')({
7
- dir: path.join(__dirname, '..', 'doc')
8
- })
9
- var minimist = require('minimist')
10
-
11
- function start (args) {
12
- args = minimist(args, {
13
- string: ['hostname', 'username', 'password', 'key', 'cert', 'ca', 'clientId', 'i', 'id'],
14
- boolean: ['stdin', 'help', 'clean', 'insecure'],
15
- alias: {
16
- port: 'p',
17
- hostname: ['h', 'host'],
18
- topic: 't',
19
- qos: 'q',
20
- clean: 'c',
21
- keepalive: 'k',
22
- clientId: ['i', 'id'],
23
- username: 'u',
24
- password: 'P',
25
- protocol: ['C', 'l'],
26
- verbose: 'v',
27
- help: '-H',
28
- ca: 'cafile'
29
- },
30
- default: {
31
- host: 'localhost',
32
- qos: 0,
33
- retain: false,
34
- clean: true,
35
- keepAlive: 30 // 30 sec
36
- }
37
- })
38
-
39
- if (args.help) {
40
- return helpMe.toStdout('subscribe')
41
- }
42
-
43
- args.topic = args.topic || args._.shift()
44
-
45
- if (!args.topic) {
46
- console.error('missing topic\n')
47
- return helpMe.toStdout('subscribe')
48
- }
49
-
50
- if (args.key) {
51
- args.key = fs.readFileSync(args.key)
52
- }
53
-
54
- if (args.cert) {
55
- args.cert = fs.readFileSync(args.cert)
56
- }
57
-
58
- if (args.ca) {
59
- args.ca = fs.readFileSync(args.ca)
60
- }
61
-
62
- if (args.key && args.cert && !args.protocol) {
63
- args.protocol = 'mqtts'
64
- }
65
-
66
- if (args.insecure) {
67
- args.rejectUnauthorized = false
68
- }
69
-
70
- if (args.port) {
71
- if (typeof args.port !== 'number') {
72
- console.warn('# Port: number expected, \'%s\' was given.', typeof args.port)
73
- return
74
- }
75
- }
76
-
77
- if (args['will-topic']) {
78
- args.will = {}
79
- args.will.topic = args['will-topic']
80
- args.will.payload = args['will-message']
81
- args.will.qos = args['will-qos']
82
- args.will.retain = args['will-retain']
83
- }
84
-
85
- args.keepAlive = args['keep-alive']
86
-
87
- var client = mqtt.connect(args)
88
-
89
- client.on('connect', function () {
90
- client.subscribe(args.topic, { qos: args.qos }, function (err, result) {
91
- if (err) {
92
- console.error(err)
93
- process.exit(1)
94
- }
95
-
96
- result.forEach(function (sub) {
97
- if (sub.qos > 2) {
98
- console.error('subscription negated to', sub.topic, 'with code', sub.qos)
99
- process.exit(1)
100
- }
101
- })
102
- })
103
- })
104
-
105
- client.on('message', function (topic, payload) {
106
- if (args.verbose) {
107
- console.log(topic, payload.toString())
108
- } else {
109
- console.log(payload.toString())
110
- }
111
- })
112
-
113
- client.on('error', function (err) {
114
- console.warn(err)
115
- client.end()
116
- })
117
- }
118
-
119
- module.exports = start
120
-
121
- if (require.main === module) {
122
- start(process.argv.slice(2))
123
- }
1
+ #!/usr/bin/env node
2
+
3
+ const mqtt = require('../')
4
+ const path = require('path')
5
+ const fs = require('fs')
6
+ const helpMe = require('help-me')({
7
+ dir: path.join(__dirname, '..', 'doc')
8
+ })
9
+ const minimist = require('minimist')
10
+
11
+ function start (args) {
12
+ args = minimist(args, {
13
+ string: ['hostname', 'username', 'password', 'key', 'cert', 'ca', 'clientId', 'i', 'id'],
14
+ boolean: ['stdin', 'help', 'clean', 'insecure'],
15
+ alias: {
16
+ port: 'p',
17
+ hostname: ['h', 'host'],
18
+ topic: 't',
19
+ qos: 'q',
20
+ clean: 'c',
21
+ keepalive: 'k',
22
+ clientId: ['i', 'id'],
23
+ username: 'u',
24
+ password: 'P',
25
+ protocol: ['C', 'l'],
26
+ verbose: 'v',
27
+ help: '-H',
28
+ ca: 'cafile'
29
+ },
30
+ default: {
31
+ host: 'localhost',
32
+ qos: 0,
33
+ retain: false,
34
+ clean: true,
35
+ keepAlive: 30 // 30 sec
36
+ }
37
+ })
38
+
39
+ if (args.help) {
40
+ return helpMe.toStdout('subscribe')
41
+ }
42
+
43
+ args.topic = args.topic || args._.shift()
44
+
45
+ if (!args.topic) {
46
+ console.error('missing topic\n')
47
+ return helpMe.toStdout('subscribe')
48
+ }
49
+
50
+ if (args.key) {
51
+ args.key = fs.readFileSync(args.key)
52
+ }
53
+
54
+ if (args.cert) {
55
+ args.cert = fs.readFileSync(args.cert)
56
+ }
57
+
58
+ if (args.ca) {
59
+ args.ca = fs.readFileSync(args.ca)
60
+ }
61
+
62
+ if (args.key && args.cert && !args.protocol) {
63
+ args.protocol = 'mqtts'
64
+ }
65
+
66
+ if (args.insecure) {
67
+ args.rejectUnauthorized = false
68
+ }
69
+
70
+ if (args.port) {
71
+ if (typeof args.port !== 'number') {
72
+ console.warn('# Port: number expected, \'%s\' was given.', typeof args.port)
73
+ return
74
+ }
75
+ }
76
+
77
+ if (args['will-topic']) {
78
+ args.will = {}
79
+ args.will.topic = args['will-topic']
80
+ args.will.payload = args['will-message']
81
+ args.will.qos = args['will-qos']
82
+ args.will.retain = args['will-retain']
83
+ }
84
+
85
+ args.keepAlive = args['keep-alive']
86
+
87
+ const client = mqtt.connect(args)
88
+
89
+ client.on('connect', function () {
90
+ client.subscribe(args.topic, { qos: args.qos }, function (err, result) {
91
+ if (err) {
92
+ console.error(err)
93
+ process.exit(1)
94
+ }
95
+
96
+ result.forEach(function (sub) {
97
+ if (sub.qos > 2) {
98
+ console.error('subscription negated to', sub.topic, 'with code', sub.qos)
99
+ process.exit(1)
100
+ }
101
+ })
102
+ })
103
+ })
104
+
105
+ client.on('message', function (topic, payload) {
106
+ if (args.verbose) {
107
+ console.log(topic, payload.toString())
108
+ } else {
109
+ console.log(payload.toString())
110
+ }
111
+ })
112
+
113
+ client.on('error', function (err) {
114
+ console.warn(err)
115
+ client.end()
116
+ })
117
+ }
118
+
119
+ module.exports = start
120
+
121
+ if (require.main === module) {
122
+ start(process.argv.slice(2))
123
+ }