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
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var mqtt = require('mqtt')
|
|
4
|
-
var HttpsProxyAgent = require('https-proxy-agent')
|
|
5
|
-
var url = require('url')
|
|
6
|
-
/*
|
|
7
|
-
host: host of the endpoint you want to connect e.g. my.mqqt.host.com
|
|
8
|
-
path: path to you endpoint e.g. '/foo/bar/mqtt'
|
|
9
|
-
*/
|
|
10
|
-
var endpoint = 'wss://<host><path>'
|
|
11
|
-
/* create proxy agent
|
|
12
|
-
proxy: your proxy e.g. proxy.foo.bar.com
|
|
13
|
-
port: http proxy port e.g. 8080
|
|
14
|
-
*/
|
|
15
|
-
var proxy = process.env.http_proxy || 'http://<proxy>:<port>'
|
|
16
|
-
var parsed = url.parse(endpoint)
|
|
17
|
-
var proxyOpts = url.parse(proxy)
|
|
18
|
-
// true for wss
|
|
19
|
-
proxyOpts.secureEndpoint = parsed.protocol ? parsed.protocol === 'wss:' : true
|
|
20
|
-
var agent = new HttpsProxyAgent(proxyOpts)
|
|
21
|
-
var wsOptions = {
|
|
22
|
-
agent: agent
|
|
23
|
-
// other wsOptions
|
|
24
|
-
// foo:'bar'
|
|
25
|
-
}
|
|
26
|
-
var mqttOptions = {
|
|
27
|
-
keepalive: 60,
|
|
28
|
-
reschedulePings: true,
|
|
29
|
-
protocolId: 'MQTT',
|
|
30
|
-
protocolVersion: 4,
|
|
31
|
-
reconnectPeriod: 1000,
|
|
32
|
-
connectTimeout: 30 * 1000,
|
|
33
|
-
clean: true,
|
|
34
|
-
clientId: 'testClient',
|
|
35
|
-
wsOptions: wsOptions
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var client = mqtt.connect(parsed, mqttOptions)
|
|
39
|
-
|
|
40
|
-
client.on('connect', function () {
|
|
41
|
-
console.log('connected')
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
client.on('error', function (a) {
|
|
45
|
-
console.log('error!' + a)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
client.on('offline', function (a) {
|
|
49
|
-
console.log('lost connection!' + a)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
client.on('close', function (a) {
|
|
53
|
-
console.log('connection closed!' + a)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
client.on('message', function (topic, message) {
|
|
57
|
-
console.log(message.toString())
|
|
58
|
-
})
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var mqtt = require('mqtt')
|
|
4
|
+
var HttpsProxyAgent = require('https-proxy-agent')
|
|
5
|
+
var url = require('url')
|
|
6
|
+
/*
|
|
7
|
+
host: host of the endpoint you want to connect e.g. my.mqqt.host.com
|
|
8
|
+
path: path to you endpoint e.g. '/foo/bar/mqtt'
|
|
9
|
+
*/
|
|
10
|
+
var endpoint = 'wss://<host><path>'
|
|
11
|
+
/* create proxy agent
|
|
12
|
+
proxy: your proxy e.g. proxy.foo.bar.com
|
|
13
|
+
port: http proxy port e.g. 8080
|
|
14
|
+
*/
|
|
15
|
+
var proxy = process.env.http_proxy || 'http://<proxy>:<port>'
|
|
16
|
+
var parsed = url.parse(endpoint)
|
|
17
|
+
var proxyOpts = url.parse(proxy)
|
|
18
|
+
// true for wss
|
|
19
|
+
proxyOpts.secureEndpoint = parsed.protocol ? parsed.protocol === 'wss:' : true
|
|
20
|
+
var agent = new HttpsProxyAgent(proxyOpts)
|
|
21
|
+
var wsOptions = {
|
|
22
|
+
agent: agent
|
|
23
|
+
// other wsOptions
|
|
24
|
+
// foo:'bar'
|
|
25
|
+
}
|
|
26
|
+
var mqttOptions = {
|
|
27
|
+
keepalive: 60,
|
|
28
|
+
reschedulePings: true,
|
|
29
|
+
protocolId: 'MQTT',
|
|
30
|
+
protocolVersion: 4,
|
|
31
|
+
reconnectPeriod: 1000,
|
|
32
|
+
connectTimeout: 30 * 1000,
|
|
33
|
+
clean: true,
|
|
34
|
+
clientId: 'testClient',
|
|
35
|
+
wsOptions: wsOptions
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var client = mqtt.connect(parsed, mqttOptions)
|
|
39
|
+
|
|
40
|
+
client.on('connect', function () {
|
|
41
|
+
console.log('connected')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
client.on('error', function (a) {
|
|
45
|
+
console.log('error!' + a)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
client.on('offline', function (a) {
|
|
49
|
+
console.log('lost connection!' + a)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
client.on('close', function (a) {
|
|
53
|
+
console.log('connection closed!' + a)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
client.on('message', function (topic, message) {
|
|
57
|
+
console.log(message.toString())
|
|
58
|
+
})
|