@thingwala/node-red-contrib-geyserwala-connect 0.0.7 → 0.0.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
CHANGED
package/package.json
CHANGED
|
@@ -8,13 +8,14 @@ class GeyserwalaConnectorMqtt {
|
|
|
8
8
|
this.nodes = []
|
|
9
9
|
this.subscriptions = {}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
this.broker._clientAwaiter.push(
|
|
12
|
+
(client) => {
|
|
13
|
+
client.on('connect', () => {
|
|
14
|
+
this.updateSubscriptions()
|
|
15
|
+
this.setupBrokerEvents()
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
);
|
|
18
19
|
}
|
|
19
20
|
setupBrokerEvents() {
|
|
20
21
|
if (!this.broker || !this.broker.client) {
|
|
@@ -66,7 +67,6 @@ class GeyserwalaConnectorMqtt {
|
|
|
66
67
|
|
|
67
68
|
this.broker.client.on("error", (error) => {
|
|
68
69
|
this.status({ fill: "red", shape: "ring", text: "error" });
|
|
69
|
-
this.RED.log.error(`{Geyserwala Connect} MQTT error: ${error}`);
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
subTopic(key) {
|
|
@@ -87,17 +87,18 @@ class GeyserwalaConnectorMqtt {
|
|
|
87
87
|
}
|
|
88
88
|
hookNode(node) {
|
|
89
89
|
this.nodes.push(node)
|
|
90
|
-
this.
|
|
90
|
+
this.broker.register(node)
|
|
91
91
|
}
|
|
92
92
|
unhookAllNodes() {
|
|
93
93
|
for (const node in this.nodes) {
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
for(const topic in this.subscriptions) {
|
|
97
|
-
this.unsubscribe(topic)
|
|
98
|
-
}
|
|
99
|
-
this.subscriptions = {}
|
|
94
|
+
this.broker.deregister(node, ()=>{})
|
|
95
|
+
this.status({ fill: "grey", shape: "ring", text: "disconnected" });
|
|
100
96
|
}
|
|
97
|
+
for(const topic in this.subscriptions) {
|
|
98
|
+
this.unsubscribeTopic(topic)
|
|
99
|
+
}
|
|
100
|
+
this.subscriptions = {}
|
|
101
|
+
this.nodes = []
|
|
101
102
|
}
|
|
102
103
|
updateSubscriptions() {
|
|
103
104
|
this.subscriptions = {}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
module.exports = function (RED) {
|
|
3
2
|
class GeyserwalaConnectApi {
|
|
4
3
|
constructor (config) {
|
|
@@ -7,8 +6,24 @@ module.exports = function (RED) {
|
|
|
7
6
|
if (config.api == "MQTT") {
|
|
8
7
|
const GeyserwalaConnectorMqtt = require('./geyserwala-api-mqtt');
|
|
9
8
|
|
|
9
|
+
let mqttBroker = RED.nodes.getNode(config.mqttBroker)
|
|
10
|
+
|
|
11
|
+
if (mqttBroker._clientAwaiter === undefined) {
|
|
12
|
+
mqttBroker._clientAwaiter = []
|
|
13
|
+
let _client;
|
|
14
|
+
Object.defineProperty(mqttBroker, 'client', {
|
|
15
|
+
get: function () { return _client; },
|
|
16
|
+
set: function (val) {
|
|
17
|
+
_client = val;
|
|
18
|
+
mqttBroker._clientAwaiter.forEach(awaiter => {
|
|
19
|
+
awaiter(val)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
this.api = new GeyserwalaConnectorMqtt(RED,
|
|
11
|
-
|
|
26
|
+
mqttBroker,
|
|
12
27
|
config.mqttPubQos,
|
|
13
28
|
config.mqttRetain,
|
|
14
29
|
config.mqttTopicTemplate,
|
|
@@ -12,6 +12,8 @@ module.exports = function (RED) {
|
|
|
12
12
|
"String": String,
|
|
13
13
|
}[config.valueType]
|
|
14
14
|
|
|
15
|
+
this.status({fill:"grey", shape:"ring", text:"initialising ..."});
|
|
16
|
+
|
|
15
17
|
var geyserwalaApi = RED.nodes.getNode(config.geyserwalaApi)
|
|
16
18
|
if (!geyserwalaApi) {
|
|
17
19
|
setTimeout(()=>{
|