mqtt 4.2.5 → 4.3.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.
@@ -1,16 +1,16 @@
1
1
  'use strict'
2
2
 
3
- var Transform = require('readable-stream').Transform
4
- var duplexify = require('duplexify')
3
+ const Transform = require('readable-stream').Transform
4
+ const duplexify = require('duplexify')
5
5
 
6
6
  /* global FileReader */
7
- var my
8
- var proxy
9
- var stream
10
- var isInitialized = false
7
+ let my
8
+ let proxy
9
+ let stream
10
+ let isInitialized = false
11
11
 
12
12
  function buildProxy () {
13
- var proxy = new Transform()
13
+ const proxy = new Transform()
14
14
  proxy._write = function (chunk, encoding, next) {
15
15
  my.sendSocketMessage({
16
16
  data: chunk.buffer,
@@ -47,8 +47,8 @@ function setDefaultOpts (opts) {
47
47
  }
48
48
 
49
49
  function buildUrl (opts, client) {
50
- var protocol = opts.protocol === 'alis' ? 'wss' : 'ws'
51
- var url = protocol + '://' + opts.hostname + opts.path
50
+ const protocol = opts.protocol === 'alis' ? 'wss' : 'ws'
51
+ let url = protocol + '://' + opts.hostname + opts.path
52
52
  if (opts.port && opts.port !== 80 && opts.port !== 443) {
53
53
  url = protocol + '://' + opts.hostname + ':' + opts.port + opts.path
54
54
  }
@@ -71,12 +71,12 @@ function bindEventHandler () {
71
71
 
72
72
  my.onSocketMessage(function (res) {
73
73
  if (typeof res.data === 'string') {
74
- var buffer = Buffer.from(res.data, 'base64')
74
+ const buffer = Buffer.from(res.data, 'base64')
75
75
  proxy.push(buffer)
76
76
  } else {
77
- var reader = new FileReader()
77
+ const reader = new FileReader()
78
78
  reader.addEventListener('load', function () {
79
- var data = reader.result
79
+ let data = reader.result
80
80
 
81
81
  if (data instanceof ArrayBuffer) data = Buffer.from(data)
82
82
  else data = Buffer.from(data, 'utf8')
@@ -103,14 +103,14 @@ function buildStream (client, opts) {
103
103
  throw new Error('Could not determine host. Specify host manually.')
104
104
  }
105
105
 
106
- var websocketSubProtocol =
106
+ const websocketSubProtocol =
107
107
  (opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
108
108
  ? 'mqttv3.1'
109
109
  : 'mqtt'
110
110
 
111
111
  setDefaultOpts(opts)
112
112
 
113
- var url = buildUrl(opts, client)
113
+ const url = buildUrl(opts, client)
114
114
  my = opts.my
115
115
  my.connectSocket({
116
116
  url: url,
@@ -1,10 +1,12 @@
1
1
  'use strict'
2
2
 
3
- var MqttClient = require('../client')
4
- var Store = require('../store')
5
- var debug = require('debug')('mqttjs')
3
+ const MqttClient = require('../client')
4
+ const Store = require('../store')
5
+ const url = require('url')
6
+ const xtend = require('xtend')
7
+ const debug = require('debug')('mqttjs')
6
8
 
7
- var protocols = {}
9
+ const protocols = {}
8
10
 
9
11
  // eslint-disable-next-line camelcase
10
12
  if ((typeof process !== 'undefined' && process.title !== 'browser') || typeof __webpack_require__ !== 'function') {
@@ -30,7 +32,7 @@ protocols.wss = require('./ws')
30
32
  * @param {Object} [opts] option object
31
33
  */
32
34
  function parseAuthOptions (opts) {
33
- var matches
35
+ let matches
34
36
  if (opts.auth) {
35
37
  matches = opts.auth.match(/^(.+):(.+)$/)
36
38
  if (matches) {
@@ -58,39 +60,25 @@ function connect (brokerUrl, opts) {
58
60
  opts = opts || {}
59
61
 
60
62
  if (brokerUrl) {
63
+ // eslint-disable-next-line
64
+ const parsed = url.parse(brokerUrl, true)
65
+ if (parsed.port != null) {
66
+ parsed.port = Number(parsed.port)
67
+ }
68
+
69
+ opts = xtend(parsed, opts)
70
+
61
71
  if (opts.protocol === null) {
62
72
  throw new Error('Missing protocol')
63
73
  }
64
- var parsed = new URL(brokerUrl)
65
-
66
- // the URL object is a bit special, so copy individual
67
- // items to the opts object
68
- opts.hash = parsed.hash
69
- opts.host = parsed.host
70
- opts.hostname = parsed.hostname
71
- opts.href = parsed.href
72
- opts.origin = parsed.origin
73
- opts.pathname = parsed.pathname
74
- opts.port = Number(parsed.port) || null
75
- opts.protocol = parsed.protocol
76
- opts.username = opts.username || parsed.username || null
77
- opts.password = opts.password || parsed.password || null
78
- opts.search = parsed.search
79
- opts.searchParams = parsed.searchParams
80
- opts.path = parsed.pathname + parsed.search
74
+
81
75
  opts.protocol = opts.protocol.replace(/:$/, '')
82
76
  }
83
77
 
84
78
  // merge in the auth options if supplied
85
- // legacy support for url.parse objects (now deprecated in node.js)
86
79
  parseAuthOptions(opts)
87
80
 
88
81
  // support clientId passed in the query string of the url
89
- if (opts.searchParams && typeof opts.searchParams.get('clientId') === 'string') {
90
- opts.clientId = opts.searchParams.get('clientId')
91
- }
92
-
93
- // legacy support for url.parse objects (now deprecated in node.js)
94
82
  if (opts.query && typeof opts.query.clientId === 'string') {
95
83
  opts.clientId = opts.query.clientId
96
84
  }
@@ -122,7 +110,7 @@ function connect (brokerUrl, opts) {
122
110
  }
123
111
 
124
112
  if (!protocols[opts.protocol]) {
125
- var isSecure = ['mqtts', 'wss'].indexOf(opts.protocol) !== -1
113
+ const isSecure = ['mqtts', 'wss'].indexOf(opts.protocol) !== -1
126
114
  opts.protocol = [
127
115
  'mqtt',
128
116
  'mqtts',
@@ -166,7 +154,7 @@ function connect (brokerUrl, opts) {
166
154
  debug('calling streambuilder for', opts.protocol)
167
155
  return protocols[opts.protocol](client, opts)
168
156
  }
169
- var client = new MqttClient(wrapper, opts)
157
+ const client = new MqttClient(wrapper, opts)
170
158
  client.on('error', function () { /* Automatically set up client error handling */ })
171
159
  return client
172
160
  }
@@ -1,18 +1,17 @@
1
1
  'use strict'
2
- var net = require('net')
3
- var debug = require('debug')('mqttjs:tcp')
2
+ const net = require('net')
3
+ const debug = require('debug')('mqttjs:tcp')
4
4
 
5
5
  /*
6
6
  variables port and host can be removed since
7
7
  you have all required information in opts object
8
8
  */
9
9
  function streamBuilder (client, opts) {
10
- var port, host
11
10
  opts.port = opts.port || 1883
12
11
  opts.hostname = opts.hostname || opts.host || 'localhost'
13
12
 
14
- port = opts.port
15
- host = opts.hostname
13
+ const port = opts.port
14
+ const host = opts.hostname
16
15
 
17
16
  debug('port %d and host %s', port, host)
18
17
  return net.createConnection(port, host)
@@ -1,12 +1,15 @@
1
1
  'use strict'
2
- var tls = require('tls')
3
- var debug = require('debug')('mqttjs:tls')
2
+ const tls = require('tls')
3
+ const net = require('net')
4
+ const debug = require('debug')('mqttjs:tls')
4
5
 
5
6
  function buildBuilder (mqttClient, opts) {
6
- var connection
7
7
  opts.port = opts.port || 8883
8
8
  opts.host = opts.hostname || opts.host || 'localhost'
9
- opts.servername = opts.host
9
+
10
+ if (net.isIP(opts.host) === 0) {
11
+ opts.servername = opts.host
12
+ }
10
13
 
11
14
  opts.rejectUnauthorized = opts.rejectUnauthorized !== false
12
15
 
@@ -14,7 +17,7 @@ function buildBuilder (mqttClient, opts) {
14
17
 
15
18
  debug('port %d host %s rejectUnauthorized %b', opts.port, opts.host, opts.rejectUnauthorized)
16
19
 
17
- connection = tls.connect(opts)
20
+ const connection = tls.connect(opts)
18
21
  /* eslint no-use-before-define: [2, "nofunc"] */
19
22
  connection.on('secureConnect', function () {
20
23
  if (opts.rejectUnauthorized && !connection.authorized) {
package/lib/connect/ws.js CHANGED
@@ -5,7 +5,7 @@ const debug = require('debug')('mqttjs:ws')
5
5
  const duplexify = require('duplexify')
6
6
  const Transform = require('readable-stream').Transform
7
7
 
8
- let WSS_OPTIONS = [
8
+ const WSS_OPTIONS = [
9
9
  'rejectUnauthorized',
10
10
  'ca',
11
11
  'cert',
@@ -24,7 +24,7 @@ function buildUrl (opts, client) {
24
24
  }
25
25
 
26
26
  function setDefaultOpts (opts) {
27
- let options = opts
27
+ const options = opts
28
28
  if (!opts.hostname) {
29
29
  options.hostname = 'localhost'
30
30
  }
@@ -45,7 +45,7 @@ function setDefaultOpts (opts) {
45
45
  if (!IS_BROWSER && opts.protocol === 'wss') {
46
46
  // Add cert/key/ca etc options
47
47
  WSS_OPTIONS.forEach(function (prop) {
48
- if (opts.hasOwnProperty(prop) && !opts.wsOptions.hasOwnProperty(prop)) {
48
+ if (Object.prototype.hasOwnProperty.call(opts, prop) && !Object.prototype.hasOwnProperty.call(opts.wsOptions, prop)) {
49
49
  options.wsOptions[prop] = opts[prop]
50
50
  }
51
51
  })
@@ -55,7 +55,7 @@ function setDefaultOpts (opts) {
55
55
  }
56
56
 
57
57
  function setDefaultBrowserOpts (opts) {
58
- let options = setDefaultOpts(opts)
58
+ const options = setDefaultOpts(opts)
59
59
 
60
60
  if (!options.hostname) {
61
61
  options.hostname = options.host
@@ -93,7 +93,7 @@ function createWebSocket (client, url, opts) {
93
93
  : 'mqtt'
94
94
 
95
95
  debug('creating new Websocket for url: ' + url + ' and protocol: ' + websocketSubProtocol)
96
- let socket = new WS(url, [websocketSubProtocol], opts.wsOptions)
96
+ const socket = new WS(url, [websocketSubProtocol], opts.wsOptions)
97
97
  return socket
98
98
  }
99
99
 
@@ -103,27 +103,28 @@ function createBrowserWebSocket (client, opts) {
103
103
  ? 'mqttv3.1'
104
104
  : 'mqtt'
105
105
 
106
- let url = buildUrl(opts, client)
106
+ const url = buildUrl(opts, client)
107
107
  /* global WebSocket */
108
- let socket = new WebSocket(url, [websocketSubProtocol])
108
+ const socket = new WebSocket(url, [websocketSubProtocol])
109
109
  socket.binaryType = 'arraybuffer'
110
110
  return socket
111
111
  }
112
112
 
113
113
  function streamBuilder (client, opts) {
114
114
  debug('streamBuilder')
115
- let options = setDefaultOpts(opts)
115
+ const options = setDefaultOpts(opts)
116
116
  const url = buildUrl(options, client)
117
- let socket = createWebSocket(client, url, options)
118
- let webSocketStream = WS.createWebSocketStream(socket, options.wsOptions)
117
+ const socket = createWebSocket(client, url, options)
118
+ const webSocketStream = WS.createWebSocketStream(socket, options.wsOptions)
119
119
  webSocketStream.url = url
120
+ socket.on('close', () => { webSocketStream.destroy() })
120
121
  return webSocketStream
121
122
  }
122
123
 
123
124
  function browserStreamBuilder (client, opts) {
124
125
  debug('browserStreamBuilder')
125
126
  let stream
126
- let options = setDefaultBrowserOpts(opts)
127
+ const options = setDefaultBrowserOpts(opts)
127
128
  // sets the maximum socket buffer size before throttling
128
129
  const bufferSize = options.browserBufferSize || 1024 * 512
129
130
 
@@ -131,16 +132,16 @@ function browserStreamBuilder (client, opts) {
131
132
 
132
133
  const coerceToBuffer = !opts.objectMode
133
134
 
134
- let socket = createBrowserWebSocket(client, opts)
135
+ const socket = createBrowserWebSocket(client, opts)
135
136
 
136
- let proxy = buildProxy(opts, socketWriteBrowser, socketEndBrowser)
137
+ const proxy = buildProxy(opts, socketWriteBrowser, socketEndBrowser)
137
138
 
138
139
  if (!opts.objectMode) {
139
140
  proxy._writev = writev
140
141
  }
141
142
  proxy.on('close', () => { socket.close() })
142
143
 
143
- const eventListenerSupport = (typeof socket.addEventListener === 'undefined')
144
+ const eventListenerSupport = (typeof socket.addEventListener !== 'undefined')
144
145
 
145
146
  // was already open when passed in
146
147
  if (socket.readyState === socket.OPEN) {
@@ -173,7 +174,7 @@ function browserStreamBuilder (client, opts) {
173
174
  // methods for browserStreamBuilder
174
175
 
175
176
  function buildProxy (options, socketWrite, socketEnd) {
176
- let proxy = new Transform({
177
+ const proxy = new Transform({
177
178
  objectModeMode: options.objectMode
178
179
  })
179
180
 
package/lib/connect/wx.js CHANGED
@@ -1,15 +1,13 @@
1
1
  'use strict'
2
2
 
3
- var Transform = require('readable-stream').Transform
4
- var duplexify = require('duplexify')
3
+ const Transform = require('readable-stream').Transform
4
+ const duplexify = require('duplexify')
5
5
 
6
6
  /* global wx */
7
- var socketTask
8
- var proxy
9
- var stream
7
+ let socketTask, proxy, stream
10
8
 
11
9
  function buildProxy () {
12
- var proxy = new Transform()
10
+ const proxy = new Transform()
13
11
  proxy._write = function (chunk, encoding, next) {
14
12
  socketTask.send({
15
13
  data: chunk.buffer,
@@ -46,8 +44,8 @@ function setDefaultOpts (opts) {
46
44
  }
47
45
 
48
46
  function buildUrl (opts, client) {
49
- var protocol = opts.protocol === 'wxs' ? 'wss' : 'ws'
50
- var url = protocol + '://' + opts.hostname + opts.path
47
+ const protocol = opts.protocol === 'wxs' ? 'wss' : 'ws'
48
+ let url = protocol + '://' + opts.hostname + opts.path
51
49
  if (opts.port && opts.port !== 80 && opts.port !== 443) {
52
50
  url = protocol + '://' + opts.hostname + ':' + opts.port + opts.path
53
51
  }
@@ -65,7 +63,7 @@ function bindEventHandler () {
65
63
  })
66
64
 
67
65
  socketTask.onMessage(function (res) {
68
- var data = res.data
66
+ let data = res.data
69
67
 
70
68
  if (data instanceof ArrayBuffer) data = Buffer.from(data)
71
69
  else data = Buffer.from(data, 'utf8')
@@ -89,14 +87,14 @@ function buildStream (client, opts) {
89
87
  throw new Error('Could not determine host. Specify host manually.')
90
88
  }
91
89
 
92
- var websocketSubProtocol =
90
+ const websocketSubProtocol =
93
91
  (opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
94
92
  ? 'mqttv3.1'
95
93
  : 'mqtt'
96
94
 
97
95
  setDefaultOpts(opts)
98
96
 
99
- var url = buildUrl(opts, client)
97
+ const url = buildUrl(opts, client)
100
98
  socketTask = wx.connectSocket({
101
99
  url: url,
102
100
  protocols: [websocketSubProtocol]
@@ -112,11 +110,11 @@ function buildStream (client, opts) {
112
110
  })
113
111
  }
114
112
 
115
- var destroyRef = stream.destroy
113
+ const destroyRef = stream.destroy
116
114
  stream.destroy = function () {
117
115
  stream.destroy = destroyRef
118
116
 
119
- var self = this
117
+ const self = this
120
118
  setTimeout(function () {
121
119
  socketTask.close({
122
120
  fail: function () {
@@ -0,0 +1,69 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * DefaultMessageAllocator constructor
5
+ * @constructor
6
+ */
7
+ function DefaultMessageIdProvider () {
8
+ if (!(this instanceof DefaultMessageIdProvider)) {
9
+ return new DefaultMessageIdProvider()
10
+ }
11
+
12
+ /**
13
+ * MessageIDs starting with 1
14
+ * ensure that nextId is min. 1, see https://github.com/mqttjs/MQTT.js/issues/810
15
+ */
16
+ this.nextId = Math.max(1, Math.floor(Math.random() * 65535))
17
+ }
18
+
19
+ /**
20
+ * allocate
21
+ *
22
+ * Get the next messageId.
23
+ * @return unsigned int
24
+ */
25
+ DefaultMessageIdProvider.prototype.allocate = function () {
26
+ // id becomes current state of this.nextId and increments afterwards
27
+ const id = this.nextId++
28
+ // Ensure 16 bit unsigned int (max 65535, nextId got one higher)
29
+ if (this.nextId === 65536) {
30
+ this.nextId = 1
31
+ }
32
+ return id
33
+ }
34
+
35
+ /**
36
+ * getLastAllocated
37
+ * Get the last allocated messageId.
38
+ * @return unsigned int
39
+ */
40
+ DefaultMessageIdProvider.prototype.getLastAllocated = function () {
41
+ return (this.nextId === 1) ? 65535 : (this.nextId - 1)
42
+ }
43
+
44
+ /**
45
+ * register
46
+ * Register messageId. If success return true, otherwise return false.
47
+ * @param { unsigned int } - messageId to register,
48
+ * @return boolean
49
+ */
50
+ DefaultMessageIdProvider.prototype.register = function (messageId) {
51
+ return true
52
+ }
53
+
54
+ /**
55
+ * deallocate
56
+ * Deallocate messageId.
57
+ * @param { unsigned int } - messageId to deallocate,
58
+ */
59
+ DefaultMessageIdProvider.prototype.deallocate = function (messageId) {
60
+ }
61
+
62
+ /**
63
+ * clear
64
+ * Deallocate all messageIds.
65
+ */
66
+ DefaultMessageIdProvider.prototype.clear = function () {
67
+ }
68
+
69
+ module.exports = DefaultMessageIdProvider
package/lib/store.js CHANGED
@@ -3,11 +3,11 @@
3
3
  /**
4
4
  * Module dependencies
5
5
  */
6
- var xtend = require('xtend')
6
+ const xtend = require('xtend')
7
7
 
8
- var Readable = require('readable-stream').Readable
9
- var streamsOpts = { objectMode: true }
10
- var defaultStoreOptions = {
8
+ const Readable = require('readable-stream').Readable
9
+ const streamsOpts = { objectMode: true }
10
+ const defaultStoreOptions = {
11
11
  clean: true
12
12
  }
13
13
 
@@ -50,10 +50,10 @@ Store.prototype.put = function (packet, cb) {
50
50
  *
51
51
  */
52
52
  Store.prototype.createStream = function () {
53
- var stream = new Readable(streamsOpts)
54
- var destroyed = false
55
- var values = []
56
- var i = 0
53
+ const stream = new Readable(streamsOpts)
54
+ const values = []
55
+ let destroyed = false
56
+ let i = 0
57
57
 
58
58
  this._inflights.forEach(function (value, key) {
59
59
  values.push(value)
@@ -72,7 +72,7 @@ Store.prototype.createStream = function () {
72
72
  return
73
73
  }
74
74
 
75
- var self = this
75
+ const self = this
76
76
 
77
77
  destroyed = true
78
78
 
@@ -0,0 +1,47 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Topic Alias receiving manager
5
+ * This holds alias to topic map
6
+ * @param {Number} [max] - topic alias maximum entries
7
+ */
8
+ function TopicAliasRecv (max) {
9
+ if (!(this instanceof TopicAliasRecv)) {
10
+ return new TopicAliasRecv(max)
11
+ }
12
+ this.aliasToTopic = {}
13
+ this.max = max
14
+ }
15
+
16
+ /**
17
+ * Insert or update topic - alias entry.
18
+ * @param {String} [topic] - topic
19
+ * @param {Number} [alias] - topic alias
20
+ * @returns {Boolean} - if success return true otherwise false
21
+ */
22
+ TopicAliasRecv.prototype.put = function (topic, alias) {
23
+ if (alias === 0 || alias > this.max) {
24
+ return false
25
+ }
26
+ this.aliasToTopic[alias] = topic
27
+ this.length = Object.keys(this.aliasToTopic).length
28
+ return true
29
+ }
30
+
31
+ /**
32
+ * Get topic by alias
33
+ * @param {String} [topic] - topic
34
+ * @returns {Number} - if mapped topic exists return topic alias, otherwise return undefined
35
+ */
36
+ TopicAliasRecv.prototype.getTopicByAlias = function (alias) {
37
+ return this.aliasToTopic[alias]
38
+ }
39
+
40
+ /**
41
+ * Clear all entries
42
+ */
43
+ TopicAliasRecv.prototype.clear = function () {
44
+ this.aliasToTopic = {}
45
+ }
46
+
47
+ module.exports = TopicAliasRecv
@@ -0,0 +1,93 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Module dependencies
5
+ */
6
+ const LruMap = require('collections/lru-map')
7
+ const NumberAllocator = require('number-allocator').NumberAllocator
8
+
9
+ /**
10
+ * Topic Alias sending manager
11
+ * This holds both topic to alias and alias to topic map
12
+ * @param {Number} [max] - topic alias maximum entries
13
+ */
14
+ function TopicAliasSend (max) {
15
+ if (!(this instanceof TopicAliasSend)) {
16
+ return new TopicAliasSend(max)
17
+ }
18
+
19
+ if (max > 0) {
20
+ this.aliasToTopic = new LruMap()
21
+ this.topicToAlias = {}
22
+ this.numberAllocator = new NumberAllocator(1, max)
23
+ this.max = max
24
+ this.length = 0
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Insert or update topic - alias entry.
30
+ * @param {String} [topic] - topic
31
+ * @param {Number} [alias] - topic alias
32
+ * @returns {Boolean} - if success return true otherwise false
33
+ */
34
+ TopicAliasSend.prototype.put = function (topic, alias) {
35
+ if (alias === 0 || alias > this.max) {
36
+ return false
37
+ }
38
+ const entry = this.aliasToTopic.get(alias)
39
+ if (entry) {
40
+ delete this.topicToAlias[entry.topic]
41
+ }
42
+ this.aliasToTopic.set(alias, { topic: topic, alias: alias })
43
+ this.topicToAlias[topic] = alias
44
+ this.numberAllocator.use(alias)
45
+ this.length = this.aliasToTopic.length
46
+ return true
47
+ }
48
+
49
+ /**
50
+ * Get topic by alias
51
+ * @param {Number} [alias] - topic alias
52
+ * @returns {String} - if mapped topic exists return topic, otherwise return undefined
53
+ */
54
+ TopicAliasSend.prototype.getTopicByAlias = function (alias) {
55
+ const entry = this.aliasToTopic.get(alias)
56
+ if (typeof entry === 'undefined') return entry
57
+ return entry.topic
58
+ }
59
+
60
+ /**
61
+ * Get topic by alias
62
+ * @param {String} [topic] - topic
63
+ * @returns {Number} - if mapped topic exists return topic alias, otherwise return undefined
64
+ */
65
+ TopicAliasSend.prototype.getAliasByTopic = function (topic) {
66
+ const alias = this.topicToAlias[topic]
67
+ if (typeof alias !== 'undefined') {
68
+ this.aliasToTopic.get(alias) // LRU update
69
+ }
70
+ return alias
71
+ }
72
+
73
+ /**
74
+ * Clear all entries
75
+ */
76
+ TopicAliasSend.prototype.clear = function () {
77
+ this.aliasToTopic.clear()
78
+ this.topicToAlias = {}
79
+ this.numberAllocator.clear()
80
+ this.length = 0
81
+ }
82
+
83
+ /**
84
+ * Get Least Recently Used (LRU) topic alias
85
+ * @returns {Number} - if vacant alias exists then return it, otherwise then return LRU alias
86
+ */
87
+ TopicAliasSend.prototype.getLruAlias = function () {
88
+ const alias = this.numberAllocator.firstVacant()
89
+ if (alias) return alias
90
+ return this.aliasToTopic.min().alias
91
+ }
92
+
93
+ module.exports = TopicAliasSend