mqtt 2.18.9 → 3.0.0
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/CONTRIBUTING.md +27 -27
- package/LICENSE.md +15 -15
- package/README.md +689 -612
- package/bin/pub.js +146 -146
- package/bin/sub.js +123 -123
- package/dist/mqtt.js +11916 -14116
- package/dist/mqtt.min.js +1 -1
- package/doc/help.txt +8 -8
- package/doc/publish.txt +26 -26
- package/doc/subscribe.txt +26 -26
- package/examples/client/secure-client.js +24 -24
- package/examples/client/simple-both.js +13 -13
- package/examples/client/simple-publish.js +7 -7
- package/examples/client/simple-subscribe.js +9 -9
- package/examples/tls client/crt.ca.cg.pem +34 -34
- package/examples/tls client/mqttclient.js +48 -48
- package/examples/tls client/tls-cert.pem +13 -13
- package/examples/tls client/tls-key.pem +15 -15
- package/examples/wss/client.js +49 -49
- package/examples/wss/client_with_proxy.js +58 -58
- package/lib/client.js +1460 -1129
- package/lib/connect/ali.js +130 -0
- package/lib/connect/index.js +157 -149
- package/lib/connect/tcp.js +19 -19
- package/lib/connect/tls.js +41 -41
- package/lib/connect/ws.js +92 -92
- package/lib/connect/wx.js +134 -110
- package/lib/store.js +140 -140
- package/lib/validations.js +52 -52
- package/mqtt.js +41 -41
- package/package.json +112 -107
- package/test/abstract_client.js +3084 -2667
- package/test/abstract_store.js +135 -135
- package/test/browser/server.js +132 -132
- package/test/browser/test.js +92 -92
- package/test/client.js +1129 -544
- package/test/helpers/private-csr.pem +16 -16
- package/test/helpers/private-key.pem +27 -27
- package/test/helpers/public-cert.pem +19 -19
- package/test/helpers/public-key.pem +9 -9
- package/test/helpers/server.js +52 -52
- package/test/helpers/server_process.js +9 -9
- package/test/helpers/tls-cert.pem +14 -14
- package/test/helpers/tls-csr.pem +11 -11
- package/test/helpers/tls-key.pem +15 -15
- package/test/helpers/wrong-cert.pem +13 -13
- package/test/helpers/wrong-csr.pem +11 -11
- package/test/helpers/wrong-key.pem +15 -15
- package/test/mocha.opts +4 -4
- package/test/mqtt.js +230 -230
- package/test/mqtt_store.js +9 -9
- package/test/secure_client.js +157 -157
- package/test/server.js +93 -65
- package/test/store.js +10 -10
- package/test/typescript/broker-connect-subscribe-and-publish.js +24 -0
- package/test/typescript/broker-connect-subscribe-and-publish.js.map +1 -0
- package/test/typescript/broker-connect-subscribe-and-publish.ts +22 -22
- package/test/typescript/tsconfig.json +14 -14
- package/test/util.js +13 -13
- package/test/websocket_client.js +144 -144
- package/types/index.d.ts +27 -27
- package/types/lib/client-options.d.ts +178 -137
- package/types/lib/client.d.ts +231 -196
- package/types/lib/connect/index.d.ts +10 -10
- package/types/lib/store-options.d.ts +6 -6
- package/types/lib/store.d.ts +46 -46
- package/test/browser/wx.js +0 -93
package/doc/help.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
MQTT.js command line interface, available commands are:
|
|
2
|
-
|
|
3
|
-
* publish publish a message to the broker
|
|
4
|
-
* subscribe subscribe for updates from the broker
|
|
5
|
-
* version the current MQTT.js version
|
|
6
|
-
* help help about commands
|
|
7
|
-
|
|
8
|
-
Launch 'mqtt help [command]' to know more about the commands.
|
|
1
|
+
MQTT.js command line interface, available commands are:
|
|
2
|
+
|
|
3
|
+
* publish publish a message to the broker
|
|
4
|
+
* subscribe subscribe for updates from the broker
|
|
5
|
+
* version the current MQTT.js version
|
|
6
|
+
* help help about commands
|
|
7
|
+
|
|
8
|
+
Launch 'mqtt help [command]' to know more about the commands.
|
package/doc/publish.txt
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
Usage: mqtt publish [opts] topic [message]
|
|
2
|
-
|
|
3
|
-
Available options:
|
|
4
|
-
|
|
5
|
-
-h/--hostname HOST the broker host
|
|
6
|
-
-p/--port PORT the broker port
|
|
7
|
-
-i/--client-id ID the client id
|
|
8
|
-
-q/--qos 0/1/2 the QoS of the message
|
|
9
|
-
-t/--topic TOPIC the message topic
|
|
10
|
-
-m/--message MSG the message body
|
|
11
|
-
-r/--retain send a retained message
|
|
12
|
-
-s/--stdin read the message body from stdin
|
|
13
|
-
-M/--multiline read lines from stdin as multiple messages
|
|
14
|
-
-u/--username USER the username
|
|
15
|
-
-P/--password PASS the password
|
|
16
|
-
-C/--protocol PROTO the protocol to use, 'mqtt',
|
|
17
|
-
'mqtts', 'ws' or 'wss'
|
|
18
|
-
--key PATH path to the key file
|
|
19
|
-
--cert PATH path to the cert file
|
|
20
|
-
--ca PATH path to the ca certificate
|
|
21
|
-
--insecure do not verify the server certificate
|
|
22
|
-
--will-topic TOPIC the will topic
|
|
23
|
-
--will-payload BODY the will message
|
|
24
|
-
--will-qos 0/1/2 the will qos
|
|
25
|
-
--will-retain send a will retained message
|
|
26
|
-
-H/--help show this
|
|
1
|
+
Usage: mqtt publish [opts] topic [message]
|
|
2
|
+
|
|
3
|
+
Available options:
|
|
4
|
+
|
|
5
|
+
-h/--hostname HOST the broker host
|
|
6
|
+
-p/--port PORT the broker port
|
|
7
|
+
-i/--client-id ID the client id
|
|
8
|
+
-q/--qos 0/1/2 the QoS of the message
|
|
9
|
+
-t/--topic TOPIC the message topic
|
|
10
|
+
-m/--message MSG the message body
|
|
11
|
+
-r/--retain send a retained message
|
|
12
|
+
-s/--stdin read the message body from stdin
|
|
13
|
+
-M/--multiline read lines from stdin as multiple messages
|
|
14
|
+
-u/--username USER the username
|
|
15
|
+
-P/--password PASS the password
|
|
16
|
+
-C/--protocol PROTO the protocol to use, 'mqtt',
|
|
17
|
+
'mqtts', 'ws' or 'wss'
|
|
18
|
+
--key PATH path to the key file
|
|
19
|
+
--cert PATH path to the cert file
|
|
20
|
+
--ca PATH path to the ca certificate
|
|
21
|
+
--insecure do not verify the server certificate
|
|
22
|
+
--will-topic TOPIC the will topic
|
|
23
|
+
--will-payload BODY the will message
|
|
24
|
+
--will-qos 0/1/2 the will qos
|
|
25
|
+
--will-retain send a will retained message
|
|
26
|
+
-H/--help show this
|
package/doc/subscribe.txt
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
Usage: mqtt subscribe [opts] [topic]
|
|
2
|
-
|
|
3
|
-
Available options:
|
|
4
|
-
|
|
5
|
-
-h/--hostname HOST the broker host
|
|
6
|
-
-p/--port PORT the broker port
|
|
7
|
-
-i/--client-id ID the client id
|
|
8
|
-
-q/--qos 0/1/2 the QoS of the message
|
|
9
|
-
--no-clean do not discard any pending message for
|
|
10
|
-
the given id
|
|
11
|
-
-t/--topic TOPIC the message topic
|
|
12
|
-
-k/--keepalive SEC send a ping every SEC seconds
|
|
13
|
-
-u/--username USER the username
|
|
14
|
-
-P/--password PASS the password
|
|
15
|
-
-l/--protocol PROTO the protocol to use, 'mqtt',
|
|
16
|
-
'mqtts', 'ws' or 'wss'
|
|
17
|
-
--key PATH path to the key file
|
|
18
|
-
--cert PATH path to the cert file
|
|
19
|
-
--ca PATH path to the ca certificate
|
|
20
|
-
--insecure do not verify the server certificate
|
|
21
|
-
--will-topic TOPIC the will topic
|
|
22
|
-
--will-message BODY the will message
|
|
23
|
-
--will-qos 0/1/2 the will qos
|
|
24
|
-
--will-retain send a will retained message
|
|
25
|
-
-v/--verbose print the topic before the message
|
|
26
|
-
-H/--help show this
|
|
1
|
+
Usage: mqtt subscribe [opts] [topic]
|
|
2
|
+
|
|
3
|
+
Available options:
|
|
4
|
+
|
|
5
|
+
-h/--hostname HOST the broker host
|
|
6
|
+
-p/--port PORT the broker port
|
|
7
|
+
-i/--client-id ID the client id
|
|
8
|
+
-q/--qos 0/1/2 the QoS of the message
|
|
9
|
+
--no-clean do not discard any pending message for
|
|
10
|
+
the given id
|
|
11
|
+
-t/--topic TOPIC the message topic
|
|
12
|
+
-k/--keepalive SEC send a ping every SEC seconds
|
|
13
|
+
-u/--username USER the username
|
|
14
|
+
-P/--password PASS the password
|
|
15
|
+
-l/--protocol PROTO the protocol to use, 'mqtt',
|
|
16
|
+
'mqtts', 'ws' or 'wss'
|
|
17
|
+
--key PATH path to the key file
|
|
18
|
+
--cert PATH path to the cert file
|
|
19
|
+
--ca PATH path to the ca certificate
|
|
20
|
+
--insecure do not verify the server certificate
|
|
21
|
+
--will-topic TOPIC the will topic
|
|
22
|
+
--will-message BODY the will message
|
|
23
|
+
--will-qos 0/1/2 the will qos
|
|
24
|
+
--will-retain send a will retained message
|
|
25
|
+
-v/--verbose print the topic before the message
|
|
26
|
+
-H/--help show this
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
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'))
|
|
8
|
-
|
|
9
|
-
var PORT = 8443
|
|
10
|
-
|
|
11
|
-
var options = {
|
|
12
|
-
port: PORT,
|
|
13
|
-
key: KEY,
|
|
14
|
-
cert: CERT,
|
|
15
|
-
rejectUnauthorized: false
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var client = mqtt.connect(options)
|
|
19
|
-
|
|
20
|
-
client.subscribe('messages')
|
|
21
|
-
client.publish('messages', 'Current time is: ' + new Date())
|
|
22
|
-
client.on('message', function (topic, message) {
|
|
23
|
-
console.log(message)
|
|
24
|
-
})
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
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'))
|
|
8
|
+
|
|
9
|
+
var PORT = 8443
|
|
10
|
+
|
|
11
|
+
var options = {
|
|
12
|
+
port: PORT,
|
|
13
|
+
key: KEY,
|
|
14
|
+
cert: CERT,
|
|
15
|
+
rejectUnauthorized: false
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var client = mqtt.connect(options)
|
|
19
|
+
|
|
20
|
+
client.subscribe('messages')
|
|
21
|
+
client.publish('messages', 'Current time is: ' + new Date())
|
|
22
|
+
client.on('message', function (topic, message) {
|
|
23
|
+
console.log(message)
|
|
24
|
+
})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var mqtt = require('../..')
|
|
4
|
-
var client = mqtt.connect()
|
|
5
|
-
|
|
6
|
-
// or var client = mqtt.connect({ port: 1883, host: '192.168.1.100', keepalive: 10000});
|
|
7
|
-
|
|
8
|
-
client.subscribe('presence')
|
|
9
|
-
client.publish('presence', 'bin hier')
|
|
10
|
-
client.on('message', function (topic, message) {
|
|
11
|
-
console.log(message)
|
|
12
|
-
})
|
|
13
|
-
client.end()
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var mqtt = require('../..')
|
|
4
|
+
var client = mqtt.connect()
|
|
5
|
+
|
|
6
|
+
// or var client = mqtt.connect({ port: 1883, host: '192.168.1.100', keepalive: 10000});
|
|
7
|
+
|
|
8
|
+
client.subscribe('presence')
|
|
9
|
+
client.publish('presence', 'bin hier')
|
|
10
|
+
client.on('message', function (topic, message) {
|
|
11
|
+
console.log(message)
|
|
12
|
+
})
|
|
13
|
+
client.end()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var mqtt = require('../..')
|
|
4
|
-
var client = mqtt.connect()
|
|
5
|
-
|
|
6
|
-
client.publish('presence', 'hello!')
|
|
7
|
-
client.end()
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var mqtt = require('../..')
|
|
4
|
+
var client = mqtt.connect()
|
|
5
|
+
|
|
6
|
+
client.publish('presence', 'hello!')
|
|
7
|
+
client.end()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var mqtt = require('../..')
|
|
4
|
-
var client = mqtt.connect()
|
|
5
|
-
|
|
6
|
-
client.subscribe('presence')
|
|
7
|
-
client.on('message', function (topic, message) {
|
|
8
|
-
console.log(message)
|
|
9
|
-
})
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var mqtt = require('../..')
|
|
4
|
+
var client = mqtt.connect()
|
|
5
|
+
|
|
6
|
+
client.subscribe('presence')
|
|
7
|
+
client.on('message', function (topic, message) {
|
|
8
|
+
console.log(message)
|
|
9
|
+
})
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
|
2
|
-
MIIF7zCCA9egAwIBAgIJAOeJR1p1PU3qMA0GCSqGSIb3DQEBBQUAMIGNMQswCQYD
|
|
3
|
-
VQQGEwJFUzERMA8GA1UECAwIWmFyYWdvemExETAPBgNVBAcMCFphcmFnb3phMRkw
|
|
4
|
-
FwYDVQQKDBBNUVRUIGZvciBub2RlLmpzMRAwDgYDVQQLDAdNUVRULmpzMQ0wCwYD
|
|
5
|
-
VQQDDARtcXR0MRwwGgYJKoZIhvcNAQkBFg1mYWtlQG1haWwuY29tMB4XDTEzMDgz
|
|
6
|
-
MDEzMDIwNVoXDTIzMDgyODEzMDIwNVowgY0xCzAJBgNVBAYTAkVTMREwDwYDVQQI
|
|
7
|
-
DAhaYXJhZ296YTERMA8GA1UEBwwIWmFyYWdvemExGTAXBgNVBAoMEE1RVFQgZm9y
|
|
8
|
-
IG5vZGUuanMxEDAOBgNVBAsMB01RVFQuanMxDTALBgNVBAMMBG1xdHQxHDAaBgkq
|
|
9
|
-
hkiG9w0BCQEWDWZha2VAbWFpbC5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw
|
|
10
|
-
ggIKAoICAQC7Of6OppOE+xwPdPcsT0w3keCa5k4ufZCqUAHex7+mLlrpjfCjQ2z6
|
|
11
|
-
Rm0XBiCu9vy+xvLtbGDh5e/gocj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HpC41swHwYDVR0jBBgwFoAU1yVv
|
|
22
|
+
/ezoDLs+qjbx0O4KiHpC41swDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC
|
|
23
|
+
AgEAScnfOewEk59DgfICJJ2vhcI33wqqn54zhJ1pi8SX3e7PLv26UEUXZaddIqeZ
|
|
24
|
+
JzA/IWF+GCBQFAL7Z+sI4djXx/UpZp5ptCQBFc0tinHk1CGlC0E+LI3JS/cnFf+2
|
|
25
|
+
L8VKZHbSf4ua2f/VMJo7uoyrw/gQHgUToAlYYWpGcIKKm7d0JYQE60wlHk9TXgCc
|
|
26
|
+
s9XAwI+bP9VKNQkZCeooODG/5VcxdJafZSU3rW1WniFcD/R+ZNq7FZYbM+2u2mRt
|
|
27
|
+
Qm7Hh/FjrN4Hnmf3xdNUE0NLHznwk4CD6EeQukN12yP2ccubnG6Z7HFFdV0g9fEP
|
|
28
|
+
AVMsgY/9E9Te/BBoQKjhIg8c274ozIOsCHODx15Mn52848sq0LIQjyeOH4rtuWLL
|
|
29
|
+
1dFE1ysY2gzSMUtrP+on+r6F1GkndFszxfDrBcZMXs85VAy3eKfY/jzUMrdfn0YJ
|
|
30
|
+
36Wz7F40vnOUd2ni24kaOfnRodbu3lOEYD6l5fDGP79kfITyy+dtL6ExTLZQmEn+
|
|
31
|
+
xKsWM9bBkV4STpFiTF61tJwzlcAL1ZDLqDaSwsM8UDZopnDgvklNoJK9XzdLwD1X
|
|
32
|
+
PofOtUe08G4tq5cBDVURLKif+7EfCyAqvUptQ3MJarhoXzhDy9CjtN8TmWexKC1q
|
|
33
|
+
kB5DBML0Y4NnqTEnfYCs/XFPosaS+0GximGySJcg08ay6ZA=
|
|
34
|
+
-----END CERTIFICATE-----
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/** ************************** IMPORTANT NOTE ***********************************
|
|
4
|
-
|
|
5
|
-
The certificate used on this example has been generated for a host named stark.
|
|
6
|
-
So as host we SHOULD use stark if we want the server to be authorized.
|
|
7
|
-
For testing this we should add on the computer running this example a line on
|
|
8
|
-
the hosts file:
|
|
9
|
-
/etc/hosts [UNIX]
|
|
10
|
-
OR
|
|
11
|
-
\System32\drivers\etc\hosts [Windows]
|
|
12
|
-
|
|
13
|
-
The line to add on the file should be as follows:
|
|
14
|
-
<the ip address of the server> stark
|
|
15
|
-
*******************************************************************************/
|
|
16
|
-
|
|
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'))
|
|
23
|
-
|
|
24
|
-
var PORT = 1883
|
|
25
|
-
var HOST = 'stark'
|
|
26
|
-
|
|
27
|
-
var options = {
|
|
28
|
-
port: PORT,
|
|
29
|
-
host: HOST,
|
|
30
|
-
key: KEY,
|
|
31
|
-
cert: CERT,
|
|
32
|
-
rejectUnauthorized: true,
|
|
33
|
-
// The CA list will be used to determine if server is authorized
|
|
34
|
-
ca: TRUSTED_CA_LIST,
|
|
35
|
-
protocol: 'mqtts'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var client = mqtt.connect(options)
|
|
39
|
-
|
|
40
|
-
client.subscribe('messages')
|
|
41
|
-
client.publish('messages', 'Current time is: ' + new Date())
|
|
42
|
-
client.on('message', function (topic, message) {
|
|
43
|
-
console.log(message)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
client.on('connect', function () {
|
|
47
|
-
console.log('Connected')
|
|
48
|
-
})
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/** ************************** IMPORTANT NOTE ***********************************
|
|
4
|
+
|
|
5
|
+
The certificate used on this example has been generated for a host named stark.
|
|
6
|
+
So as host we SHOULD use stark if we want the server to be authorized.
|
|
7
|
+
For testing this we should add on the computer running this example a line on
|
|
8
|
+
the hosts file:
|
|
9
|
+
/etc/hosts [UNIX]
|
|
10
|
+
OR
|
|
11
|
+
\System32\drivers\etc\hosts [Windows]
|
|
12
|
+
|
|
13
|
+
The line to add on the file should be as follows:
|
|
14
|
+
<the ip address of the server> stark
|
|
15
|
+
*******************************************************************************/
|
|
16
|
+
|
|
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'))
|
|
23
|
+
|
|
24
|
+
var PORT = 1883
|
|
25
|
+
var HOST = 'stark'
|
|
26
|
+
|
|
27
|
+
var options = {
|
|
28
|
+
port: PORT,
|
|
29
|
+
host: HOST,
|
|
30
|
+
key: KEY,
|
|
31
|
+
cert: CERT,
|
|
32
|
+
rejectUnauthorized: true,
|
|
33
|
+
// The CA list will be used to determine if server is authorized
|
|
34
|
+
ca: TRUSTED_CA_LIST,
|
|
35
|
+
protocol: 'mqtts'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var client = mqtt.connect(options)
|
|
39
|
+
|
|
40
|
+
client.subscribe('messages')
|
|
41
|
+
client.publish('messages', 'Current time is: ' + new Date())
|
|
42
|
+
client.on('message', function (topic, message) {
|
|
43
|
+
console.log(message)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
client.on('connect', function () {
|
|
47
|
+
console.log('Connected')
|
|
48
|
+
})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
|
2
|
-
MIICATCCAWoCCQC2pNY4sfld/jANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
|
|
3
|
-
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1fjTek/Iez5NnL
|
|
9
|
+
xHa5w93j2wJBANMGmRTaTxvpGdkUi/utTPtCp6GXL7hS9v41LClmQTYBOYscPn2b
|
|
10
|
+
Dny2fyZPp29sZ7+AvXHWZxw7QtH+jO2Xz1MCQCI7vlqSYgKgffulyq4LchrxS3LU
|
|
11
|
+
7tyIuTmwTz2tXvmuUFyo/ZPO0XsShi0PG1T3E2roW8c8NJ+Ysv6XeEjJL8UCQG0Z
|
|
12
|
+
/S0tzTa15no4SEM/jwxcosRFoRNgOXimTwW8azybl3+Xg6t27h+GTuikyAEwf9cf
|
|
13
|
+
nVJssfSDowFk5MG1+icCQQCqBOTXEukcJRXZixkpfEuuvS3RNzOYwG4ReKjpvWPy
|
|
14
|
+
EvsfHoCsO1Sz9qz8DXpwl3GEWUGGTfWwBfereX6HLXj+
|
|
15
|
+
-----END RSA PRIVATE KEY-----
|
package/examples/wss/client.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var mqtt = require('mqtt')
|
|
4
|
-
|
|
5
|
-
var clientId = 'mqttjs_' + Math.random().toString(16).substr(2, 8)
|
|
6
|
-
|
|
7
|
-
var host = 'wss://localhost:3001/Mosca'
|
|
8
|
-
|
|
9
|
-
var options = {
|
|
10
|
-
keepalive: 10,
|
|
11
|
-
clientId: clientId,
|
|
12
|
-
protocolId: 'MQTT',
|
|
13
|
-
protocolVersion: 4,
|
|
14
|
-
clean: true,
|
|
15
|
-
reconnectPeriod: 1000,
|
|
16
|
-
connectTimeout: 30 * 1000,
|
|
17
|
-
will: {
|
|
18
|
-
topic: 'WillMsg',
|
|
19
|
-
payload: 'Connection Closed abnormally..!',
|
|
20
|
-
qos: 0,
|
|
21
|
-
retain: false
|
|
22
|
-
},
|
|
23
|
-
username: 'demo',
|
|
24
|
-
password: 'demo',
|
|
25
|
-
rejectUnauthorized: false
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var client = mqtt.connect(host, options)
|
|
29
|
-
|
|
30
|
-
client.on('error', function (err) {
|
|
31
|
-
console.log(err)
|
|
32
|
-
client.end()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
client.on('connect', function () {
|
|
36
|
-
console.log('client connected:' + clientId)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
client.subscribe('topic', { qos: 0 })
|
|
40
|
-
|
|
41
|
-
client.publish('topic', 'wss secure connection demo...!', { qos: 0, retain: false })
|
|
42
|
-
|
|
43
|
-
client.on('message', function (topic, message, packet) {
|
|
44
|
-
console.log('Received Message:= ' + message.toString() + '\nOn topic:= ' + topic)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
client.on('close', function () {
|
|
48
|
-
console.log(clientId + ' disconnected')
|
|
49
|
-
})
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var mqtt = require('mqtt')
|
|
4
|
+
|
|
5
|
+
var clientId = 'mqttjs_' + Math.random().toString(16).substr(2, 8)
|
|
6
|
+
|
|
7
|
+
var host = 'wss://localhost:3001/Mosca'
|
|
8
|
+
|
|
9
|
+
var options = {
|
|
10
|
+
keepalive: 10,
|
|
11
|
+
clientId: clientId,
|
|
12
|
+
protocolId: 'MQTT',
|
|
13
|
+
protocolVersion: 4,
|
|
14
|
+
clean: true,
|
|
15
|
+
reconnectPeriod: 1000,
|
|
16
|
+
connectTimeout: 30 * 1000,
|
|
17
|
+
will: {
|
|
18
|
+
topic: 'WillMsg',
|
|
19
|
+
payload: 'Connection Closed abnormally..!',
|
|
20
|
+
qos: 0,
|
|
21
|
+
retain: false
|
|
22
|
+
},
|
|
23
|
+
username: 'demo',
|
|
24
|
+
password: 'demo',
|
|
25
|
+
rejectUnauthorized: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var client = mqtt.connect(host, options)
|
|
29
|
+
|
|
30
|
+
client.on('error', function (err) {
|
|
31
|
+
console.log(err)
|
|
32
|
+
client.end()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
client.on('connect', function () {
|
|
36
|
+
console.log('client connected:' + clientId)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
client.subscribe('topic', { qos: 0 })
|
|
40
|
+
|
|
41
|
+
client.publish('topic', 'wss secure connection demo...!', { qos: 0, retain: false })
|
|
42
|
+
|
|
43
|
+
client.on('message', function (topic, message, packet) {
|
|
44
|
+
console.log('Received Message:= ' + message.toString() + '\nOn topic:= ' + topic)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
client.on('close', function () {
|
|
48
|
+
console.log(clientId + ' disconnected')
|
|
49
|
+
})
|