@burgrp/mqtt-mtl 1.0.3 → 1.1.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/mqtt-mtl.js +19 -3
- package/package.json +1 -1
package/mqtt-mtl.js
CHANGED
|
@@ -11,15 +11,29 @@ module.exports = brokerUrl => {
|
|
|
11
11
|
|
|
12
12
|
listeners: [],
|
|
13
13
|
nextListenerId: 0,
|
|
14
|
+
subscriptions: {},
|
|
14
15
|
|
|
15
16
|
publish(topic, message) {
|
|
16
17
|
this.connection.publish(topic, message);
|
|
17
18
|
},
|
|
18
19
|
|
|
19
20
|
subscribe(topic, listener) {
|
|
20
|
-
this.connection.subscribe(topic);
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
if (!(topic instanceof Object)) {
|
|
23
|
+
topic = {
|
|
24
|
+
strict: topic,
|
|
25
|
+
loose: topic
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!this.subscriptions[topic.loose]) {
|
|
30
|
+
this.connection.subscribe(topic.loose);
|
|
31
|
+
this.subscriptions[topic.loose] = 1;
|
|
32
|
+
} else {
|
|
33
|
+
this.subscriptions[topic.loose]++;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let parsedTopic = topic.strict.split("/");
|
|
23
37
|
|
|
24
38
|
let id = this.nextListenerId++;
|
|
25
39
|
|
|
@@ -45,7 +59,9 @@ module.exports = brokerUrl => {
|
|
|
45
59
|
},
|
|
46
60
|
|
|
47
61
|
unsubscribe(listenerId) {
|
|
48
|
-
|
|
62
|
+
//TODO: unsubscribe from MQTT if it's last subscription in this.subscriptions[]
|
|
63
|
+
//delete this.listeners[listenerId];
|
|
64
|
+
throw new Error("Not implemented yet");
|
|
49
65
|
}
|
|
50
66
|
}
|
|
51
67
|
|