mqtt 4.2.4 → 4.2.8
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/CHANGELOG.md +23 -0
- package/CONTRIBUTING.md +27 -27
- package/LICENSE.md +15 -15
- package/README.md +792 -784
- package/bin/mqtt.js +27 -27
- package/bin/pub.js +146 -146
- package/bin/sub.js +123 -123
- package/dist/mqtt.js +7466 -8450
- 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/lib/client.js +1581 -1581
- package/lib/connect/ali.js +128 -128
- package/lib/connect/index.js +164 -177
- package/lib/connect/tcp.js +21 -21
- package/lib/connect/tls.js +45 -45
- package/lib/connect/ws.js +256 -255
- package/lib/connect/wx.js +134 -134
- package/lib/store.js +128 -128
- package/lib/validations.js +52 -52
- package/mqtt.js +17 -17
- package/package.json +109 -108
- package/types/index.d.ts +28 -27
- package/types/lib/client-options.d.ts +191 -191
- package/types/lib/client.d.ts +240 -232
- 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/lib/connect/ali.js
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var Transform = require('readable-stream').Transform
|
|
4
|
-
var duplexify = require('duplexify')
|
|
5
|
-
|
|
6
|
-
/* global FileReader */
|
|
7
|
-
var my
|
|
8
|
-
var proxy
|
|
9
|
-
var stream
|
|
10
|
-
var isInitialized = false
|
|
11
|
-
|
|
12
|
-
function buildProxy () {
|
|
13
|
-
var proxy = new Transform()
|
|
14
|
-
proxy._write = function (chunk, encoding, next) {
|
|
15
|
-
my.sendSocketMessage({
|
|
16
|
-
data: chunk.buffer,
|
|
17
|
-
success: function () {
|
|
18
|
-
next()
|
|
19
|
-
},
|
|
20
|
-
fail: function () {
|
|
21
|
-
next(new Error())
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
proxy._flush = function socketEnd (done) {
|
|
26
|
-
my.closeSocket({
|
|
27
|
-
success: function () {
|
|
28
|
-
done()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return proxy
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function setDefaultOpts (opts) {
|
|
37
|
-
if (!opts.hostname) {
|
|
38
|
-
opts.hostname = 'localhost'
|
|
39
|
-
}
|
|
40
|
-
if (!opts.path) {
|
|
41
|
-
opts.path = '/'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!opts.wsOptions) {
|
|
45
|
-
opts.wsOptions = {}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function buildUrl (opts, client) {
|
|
50
|
-
var protocol = opts.protocol === 'alis' ? 'wss' : 'ws'
|
|
51
|
-
var url = protocol + '://' + opts.hostname + opts.path
|
|
52
|
-
if (opts.port && opts.port !== 80 && opts.port !== 443) {
|
|
53
|
-
url = protocol + '://' + opts.hostname + ':' + opts.port + opts.path
|
|
54
|
-
}
|
|
55
|
-
if (typeof (opts.transformWsUrl) === 'function') {
|
|
56
|
-
url = opts.transformWsUrl(url, opts, client)
|
|
57
|
-
}
|
|
58
|
-
return url
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function bindEventHandler () {
|
|
62
|
-
if (isInitialized) return
|
|
63
|
-
|
|
64
|
-
isInitialized = true
|
|
65
|
-
|
|
66
|
-
my.onSocketOpen(function () {
|
|
67
|
-
stream.setReadable(proxy)
|
|
68
|
-
stream.setWritable(proxy)
|
|
69
|
-
stream.emit('connect')
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
my.onSocketMessage(function (res) {
|
|
73
|
-
if (typeof res.data === 'string') {
|
|
74
|
-
var buffer = Buffer.from(res.data, 'base64')
|
|
75
|
-
proxy.push(buffer)
|
|
76
|
-
} else {
|
|
77
|
-
var reader = new FileReader()
|
|
78
|
-
reader.addEventListener('load', function () {
|
|
79
|
-
var data = reader.result
|
|
80
|
-
|
|
81
|
-
if (data instanceof ArrayBuffer) data = Buffer.from(data)
|
|
82
|
-
else data = Buffer.from(data, 'utf8')
|
|
83
|
-
proxy.push(data)
|
|
84
|
-
})
|
|
85
|
-
reader.readAsArrayBuffer(res.data)
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
my.onSocketClose(function () {
|
|
90
|
-
stream.end()
|
|
91
|
-
stream.destroy()
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
my.onSocketError(function (res) {
|
|
95
|
-
stream.destroy(res)
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function buildStream (client, opts) {
|
|
100
|
-
opts.hostname = opts.hostname || opts.host
|
|
101
|
-
|
|
102
|
-
if (!opts.hostname) {
|
|
103
|
-
throw new Error('Could not determine host. Specify host manually.')
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
var websocketSubProtocol =
|
|
107
|
-
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
|
|
108
|
-
? 'mqttv3.1'
|
|
109
|
-
: 'mqtt'
|
|
110
|
-
|
|
111
|
-
setDefaultOpts(opts)
|
|
112
|
-
|
|
113
|
-
var url = buildUrl(opts, client)
|
|
114
|
-
my = opts.my
|
|
115
|
-
my.connectSocket({
|
|
116
|
-
url: url,
|
|
117
|
-
protocols: websocketSubProtocol
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
proxy = buildProxy()
|
|
121
|
-
stream = duplexify.obj()
|
|
122
|
-
|
|
123
|
-
bindEventHandler()
|
|
124
|
-
|
|
125
|
-
return stream
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
module.exports = buildStream
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var Transform = require('readable-stream').Transform
|
|
4
|
+
var duplexify = require('duplexify')
|
|
5
|
+
|
|
6
|
+
/* global FileReader */
|
|
7
|
+
var my
|
|
8
|
+
var proxy
|
|
9
|
+
var stream
|
|
10
|
+
var isInitialized = false
|
|
11
|
+
|
|
12
|
+
function buildProxy () {
|
|
13
|
+
var proxy = new Transform()
|
|
14
|
+
proxy._write = function (chunk, encoding, next) {
|
|
15
|
+
my.sendSocketMessage({
|
|
16
|
+
data: chunk.buffer,
|
|
17
|
+
success: function () {
|
|
18
|
+
next()
|
|
19
|
+
},
|
|
20
|
+
fail: function () {
|
|
21
|
+
next(new Error())
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
proxy._flush = function socketEnd (done) {
|
|
26
|
+
my.closeSocket({
|
|
27
|
+
success: function () {
|
|
28
|
+
done()
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return proxy
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function setDefaultOpts (opts) {
|
|
37
|
+
if (!opts.hostname) {
|
|
38
|
+
opts.hostname = 'localhost'
|
|
39
|
+
}
|
|
40
|
+
if (!opts.path) {
|
|
41
|
+
opts.path = '/'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!opts.wsOptions) {
|
|
45
|
+
opts.wsOptions = {}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function buildUrl (opts, client) {
|
|
50
|
+
var protocol = opts.protocol === 'alis' ? 'wss' : 'ws'
|
|
51
|
+
var url = protocol + '://' + opts.hostname + opts.path
|
|
52
|
+
if (opts.port && opts.port !== 80 && opts.port !== 443) {
|
|
53
|
+
url = protocol + '://' + opts.hostname + ':' + opts.port + opts.path
|
|
54
|
+
}
|
|
55
|
+
if (typeof (opts.transformWsUrl) === 'function') {
|
|
56
|
+
url = opts.transformWsUrl(url, opts, client)
|
|
57
|
+
}
|
|
58
|
+
return url
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function bindEventHandler () {
|
|
62
|
+
if (isInitialized) return
|
|
63
|
+
|
|
64
|
+
isInitialized = true
|
|
65
|
+
|
|
66
|
+
my.onSocketOpen(function () {
|
|
67
|
+
stream.setReadable(proxy)
|
|
68
|
+
stream.setWritable(proxy)
|
|
69
|
+
stream.emit('connect')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
my.onSocketMessage(function (res) {
|
|
73
|
+
if (typeof res.data === 'string') {
|
|
74
|
+
var buffer = Buffer.from(res.data, 'base64')
|
|
75
|
+
proxy.push(buffer)
|
|
76
|
+
} else {
|
|
77
|
+
var reader = new FileReader()
|
|
78
|
+
reader.addEventListener('load', function () {
|
|
79
|
+
var data = reader.result
|
|
80
|
+
|
|
81
|
+
if (data instanceof ArrayBuffer) data = Buffer.from(data)
|
|
82
|
+
else data = Buffer.from(data, 'utf8')
|
|
83
|
+
proxy.push(data)
|
|
84
|
+
})
|
|
85
|
+
reader.readAsArrayBuffer(res.data)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
my.onSocketClose(function () {
|
|
90
|
+
stream.end()
|
|
91
|
+
stream.destroy()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
my.onSocketError(function (res) {
|
|
95
|
+
stream.destroy(res)
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function buildStream (client, opts) {
|
|
100
|
+
opts.hostname = opts.hostname || opts.host
|
|
101
|
+
|
|
102
|
+
if (!opts.hostname) {
|
|
103
|
+
throw new Error('Could not determine host. Specify host manually.')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var websocketSubProtocol =
|
|
107
|
+
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
|
|
108
|
+
? 'mqttv3.1'
|
|
109
|
+
: 'mqtt'
|
|
110
|
+
|
|
111
|
+
setDefaultOpts(opts)
|
|
112
|
+
|
|
113
|
+
var url = buildUrl(opts, client)
|
|
114
|
+
my = opts.my
|
|
115
|
+
my.connectSocket({
|
|
116
|
+
url: url,
|
|
117
|
+
protocols: websocketSubProtocol
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
proxy = buildProxy()
|
|
121
|
+
stream = duplexify.obj()
|
|
122
|
+
|
|
123
|
+
bindEventHandler()
|
|
124
|
+
|
|
125
|
+
return stream
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = buildStream
|
package/lib/connect/index.js
CHANGED
|
@@ -1,177 +1,164 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var MqttClient = require('../client')
|
|
4
|
-
var Store = require('../store')
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
protocols.
|
|
14
|
-
protocols.
|
|
15
|
-
protocols.
|
|
16
|
-
|
|
17
|
-
protocols.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
protocols.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
opts.
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
opts
|
|
69
|
-
|
|
70
|
-
opts.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
opts.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
'
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
debug('calling streambuilder for', opts.protocol)
|
|
167
|
-
return protocols[opts.protocol](client, opts)
|
|
168
|
-
}
|
|
169
|
-
var client = new MqttClient(wrapper, opts)
|
|
170
|
-
client.on('error', function () { /* Automatically set up client error handling */ })
|
|
171
|
-
return client
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
module.exports = connect
|
|
175
|
-
module.exports.connect = connect
|
|
176
|
-
module.exports.MqttClient = MqttClient
|
|
177
|
-
module.exports.Store = Store
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var MqttClient = require('../client')
|
|
4
|
+
var Store = require('../store')
|
|
5
|
+
var url = require('url')
|
|
6
|
+
var xtend = require('xtend')
|
|
7
|
+
var debug = require('debug')('mqttjs')
|
|
8
|
+
|
|
9
|
+
var protocols = {}
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line camelcase
|
|
12
|
+
if ((typeof process !== 'undefined' && process.title !== 'browser') || typeof __webpack_require__ !== 'function') {
|
|
13
|
+
protocols.mqtt = require('./tcp')
|
|
14
|
+
protocols.tcp = require('./tcp')
|
|
15
|
+
protocols.ssl = require('./tls')
|
|
16
|
+
protocols.tls = require('./tls')
|
|
17
|
+
protocols.mqtts = require('./tls')
|
|
18
|
+
} else {
|
|
19
|
+
protocols.wx = require('./wx')
|
|
20
|
+
protocols.wxs = require('./wx')
|
|
21
|
+
|
|
22
|
+
protocols.ali = require('./ali')
|
|
23
|
+
protocols.alis = require('./ali')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protocols.ws = require('./ws')
|
|
27
|
+
protocols.wss = require('./ws')
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parse the auth attribute and merge username and password in the options object.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} [opts] option object
|
|
33
|
+
*/
|
|
34
|
+
function parseAuthOptions (opts) {
|
|
35
|
+
var matches
|
|
36
|
+
if (opts.auth) {
|
|
37
|
+
matches = opts.auth.match(/^(.+):(.+)$/)
|
|
38
|
+
if (matches) {
|
|
39
|
+
opts.username = matches[1]
|
|
40
|
+
opts.password = matches[2]
|
|
41
|
+
} else {
|
|
42
|
+
opts.username = opts.auth
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* connect - connect to an MQTT broker.
|
|
49
|
+
*
|
|
50
|
+
* @param {String} [brokerUrl] - url of the broker, optional
|
|
51
|
+
* @param {Object} opts - see MqttClient#constructor
|
|
52
|
+
*/
|
|
53
|
+
function connect (brokerUrl, opts) {
|
|
54
|
+
debug('connecting to an MQTT broker...')
|
|
55
|
+
if ((typeof brokerUrl === 'object') && !opts) {
|
|
56
|
+
opts = brokerUrl
|
|
57
|
+
brokerUrl = null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
opts = opts || {}
|
|
61
|
+
|
|
62
|
+
if (brokerUrl) {
|
|
63
|
+
var parsed = url.parse(brokerUrl, true)
|
|
64
|
+
if (parsed.port != null) {
|
|
65
|
+
parsed.port = Number(parsed.port)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
opts = xtend(parsed, opts)
|
|
69
|
+
|
|
70
|
+
if (opts.protocol === null) {
|
|
71
|
+
throw new Error('Missing protocol')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
opts.protocol = opts.protocol.replace(/:$/, '')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// merge in the auth options if supplied
|
|
78
|
+
parseAuthOptions(opts)
|
|
79
|
+
|
|
80
|
+
// support clientId passed in the query string of the url
|
|
81
|
+
if (opts.query && typeof opts.query.clientId === 'string') {
|
|
82
|
+
opts.clientId = opts.query.clientId
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (opts.cert && opts.key) {
|
|
86
|
+
if (opts.protocol) {
|
|
87
|
+
if (['mqtts', 'wss', 'wxs', 'alis'].indexOf(opts.protocol) === -1) {
|
|
88
|
+
switch (opts.protocol) {
|
|
89
|
+
case 'mqtt':
|
|
90
|
+
opts.protocol = 'mqtts'
|
|
91
|
+
break
|
|
92
|
+
case 'ws':
|
|
93
|
+
opts.protocol = 'wss'
|
|
94
|
+
break
|
|
95
|
+
case 'wx':
|
|
96
|
+
opts.protocol = 'wxs'
|
|
97
|
+
break
|
|
98
|
+
case 'ali':
|
|
99
|
+
opts.protocol = 'alis'
|
|
100
|
+
break
|
|
101
|
+
default:
|
|
102
|
+
throw new Error('Unknown protocol for secure connection: "' + opts.protocol + '"!')
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
// A cert and key was provided, however no protocol was specified, so we will throw an error.
|
|
107
|
+
throw new Error('Missing secure protocol key')
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!protocols[opts.protocol]) {
|
|
112
|
+
var isSecure = ['mqtts', 'wss'].indexOf(opts.protocol) !== -1
|
|
113
|
+
opts.protocol = [
|
|
114
|
+
'mqtt',
|
|
115
|
+
'mqtts',
|
|
116
|
+
'ws',
|
|
117
|
+
'wss',
|
|
118
|
+
'wx',
|
|
119
|
+
'wxs',
|
|
120
|
+
'ali',
|
|
121
|
+
'alis'
|
|
122
|
+
].filter(function (key, index) {
|
|
123
|
+
if (isSecure && index % 2 === 0) {
|
|
124
|
+
// Skip insecure protocols when requesting a secure one.
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
return (typeof protocols[key] === 'function')
|
|
128
|
+
})[0]
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (opts.clean === false && !opts.clientId) {
|
|
132
|
+
throw new Error('Missing clientId for unclean clients')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (opts.protocol) {
|
|
136
|
+
opts.defaultProtocol = opts.protocol
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function wrapper (client) {
|
|
140
|
+
if (opts.servers) {
|
|
141
|
+
if (!client._reconnectCount || client._reconnectCount === opts.servers.length) {
|
|
142
|
+
client._reconnectCount = 0
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
opts.host = opts.servers[client._reconnectCount].host
|
|
146
|
+
opts.port = opts.servers[client._reconnectCount].port
|
|
147
|
+
opts.protocol = (!opts.servers[client._reconnectCount].protocol ? opts.defaultProtocol : opts.servers[client._reconnectCount].protocol)
|
|
148
|
+
opts.hostname = opts.host
|
|
149
|
+
|
|
150
|
+
client._reconnectCount++
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
debug('calling streambuilder for', opts.protocol)
|
|
154
|
+
return protocols[opts.protocol](client, opts)
|
|
155
|
+
}
|
|
156
|
+
var client = new MqttClient(wrapper, opts)
|
|
157
|
+
client.on('error', function () { /* Automatically set up client error handling */ })
|
|
158
|
+
return client
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = connect
|
|
162
|
+
module.exports.connect = connect
|
|
163
|
+
module.exports.MqttClient = MqttClient
|
|
164
|
+
module.exports.Store = Store
|
package/lib/connect/tcp.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
var net = require('net')
|
|
3
|
-
var debug = require('debug')('mqttjs:tcp')
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
variables port and host can be removed since
|
|
7
|
-
you have all required information in opts object
|
|
8
|
-
*/
|
|
9
|
-
function streamBuilder (client, opts) {
|
|
10
|
-
var port, host
|
|
11
|
-
opts.port = opts.port || 1883
|
|
12
|
-
opts.hostname = opts.hostname || opts.host || 'localhost'
|
|
13
|
-
|
|
14
|
-
port = opts.port
|
|
15
|
-
host = opts.hostname
|
|
16
|
-
|
|
17
|
-
debug('port %d and host %s', port, host)
|
|
18
|
-
return net.createConnection(port, host)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = streamBuilder
|
|
1
|
+
'use strict'
|
|
2
|
+
var net = require('net')
|
|
3
|
+
var debug = require('debug')('mqttjs:tcp')
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
variables port and host can be removed since
|
|
7
|
+
you have all required information in opts object
|
|
8
|
+
*/
|
|
9
|
+
function streamBuilder (client, opts) {
|
|
10
|
+
var port, host
|
|
11
|
+
opts.port = opts.port || 1883
|
|
12
|
+
opts.hostname = opts.hostname || opts.host || 'localhost'
|
|
13
|
+
|
|
14
|
+
port = opts.port
|
|
15
|
+
host = opts.hostname
|
|
16
|
+
|
|
17
|
+
debug('port %d and host %s', port, host)
|
|
18
|
+
return net.createConnection(port, host)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = streamBuilder
|