mqtt 4.3.3 → 4.3.4
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 +4 -0
- package/dist/mqtt.js +1167 -6730
- package/dist/mqtt.min.js +1 -1
- package/lib/topic-alias-send.js +91 -93
- package/package.json +2 -2
package/lib/topic-alias-send.js
CHANGED
|
@@ -1,93 +1,91 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies
|
|
5
|
-
*/
|
|
6
|
-
const LruMap = require('
|
|
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
|
|
41
|
-
}
|
|
42
|
-
this.aliasToTopic.set(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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
module.exports = TopicAliasSend
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Module dependencies
|
|
5
|
+
*/
|
|
6
|
+
const LruMap = require('lru-cache')
|
|
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({ max: max })
|
|
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]
|
|
41
|
+
}
|
|
42
|
+
this.aliasToTopic.set(alias, topic)
|
|
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
|
+
return this.aliasToTopic.get(alias)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get topic by alias
|
|
60
|
+
* @param {String} [topic] - topic
|
|
61
|
+
* @returns {Number} - if mapped topic exists return topic alias, otherwise return undefined
|
|
62
|
+
*/
|
|
63
|
+
TopicAliasSend.prototype.getAliasByTopic = function (topic) {
|
|
64
|
+
const alias = this.topicToAlias[topic]
|
|
65
|
+
if (typeof alias !== 'undefined') {
|
|
66
|
+
this.aliasToTopic.get(alias) // LRU update
|
|
67
|
+
}
|
|
68
|
+
return alias
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Clear all entries
|
|
73
|
+
*/
|
|
74
|
+
TopicAliasSend.prototype.clear = function () {
|
|
75
|
+
this.aliasToTopic.reset()
|
|
76
|
+
this.topicToAlias = {}
|
|
77
|
+
this.numberAllocator.clear()
|
|
78
|
+
this.length = 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get Least Recently Used (LRU) topic alias
|
|
83
|
+
* @returns {Number} - if vacant alias exists then return it, otherwise then return LRU alias
|
|
84
|
+
*/
|
|
85
|
+
TopicAliasSend.prototype.getLruAlias = function () {
|
|
86
|
+
const alias = this.numberAllocator.firstVacant()
|
|
87
|
+
if (alias) return alias
|
|
88
|
+
return this.aliasToTopic.keys()[this.aliasToTopic.length - 1]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = TopicAliasSend
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mqtt",
|
|
3
3
|
"description": "A library for the MQTT protocol",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.4",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Adam Rudd <adamvrr@gmail.com>",
|
|
7
7
|
"Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"net": false
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"collections": "^5.1.13",
|
|
66
65
|
"commist": "^1.0.0",
|
|
67
66
|
"concat-stream": "^2.0.0",
|
|
68
67
|
"debug": "^4.1.1",
|
|
69
68
|
"duplexify": "^4.1.1",
|
|
70
69
|
"help-me": "^3.0.0",
|
|
71
70
|
"inherits": "^2.0.3",
|
|
71
|
+
"lru-cache": "^6.0.0",
|
|
72
72
|
"minimist": "^1.2.5",
|
|
73
73
|
"mqtt-packet": "^6.8.0",
|
|
74
74
|
"number-allocator": "^1.0.9",
|