@logiccloud/node-red-logiccloud-control
Version:
The all-in-one logiccloud control package for Node-RED environment.
60 lines • 3.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../helper/main");
// const cors = require('cors');
// RED.httpNode.use(cors()); // This will allow all origins
module.exports = function (RED) {
function LogiccloudControlOutput(config) {
RED.nodes.createNode(this, config);
this.status({ fill: "red", shape: "ring", text: "disconnected" });
this.logiccloudControl = RED.nodes.getNode(config.logiccloudControl);
if (this.logiccloudControl && this.logiccloudControl.port) {
const variable = config.variable;
this.logiccloudControl.connector.events.on("onConnected", () => {
this.log(`LogiccloudControlOutput, received onConnected from connection wrapper`);
this.status({ fill: "green", shape: "dot", text: "connected" });
});
this.logiccloudControl.connector.events.on("onConnectionClosed", () => {
this.log(`LogiccloudControlOutput, received onConnectionClosed from connection wrapper`);
this.status({ fill: "red", shape: "ring", text: "disconnected" });
});
this.logiccloudControl.connector.events.on("onRuntimeConnectivity", (connected) => {
this.log(`LogiccloudControlOutput, received onRuntimeConnectivity from connection wrapper: ${connected}`);
if (connected) {
this.status({ fill: "green", shape: "dot", text: "connected" });
}
else {
this.status({ fill: "red", shape: "ring", text: "disconnected" });
}
});
this.logiccloudControl.connector.events.on("onOutputsReceived", (updates) => {
if (variable) {
for (let i = 0; i < updates.length; i++) {
const update = updates[i];
// this.log(`LogiccloudControlOutput - ${variable}, received update: ${update.name} = ${update.value}`);
if (update.name === variable) {
this.log(`LogiccloudControlOutput - ${variable}, updating node: ${update.name} = ${update.value}`);
this.send({ payload: update.value });
break;
}
else {
this.log(`LogiccloudControlOutput - ${variable}, ignoring update: ${update.name} = ${update.value}`);
}
}
}
else {
this.trace(`LogiccloudControlOutput, variable is not set`);
}
});
}
this.on("close", () => {
this.log(`LogiccloudControlOutput, close`);
this.status({ fill: "red", shape: "ring", text: "disconnected" });
});
}
RED.nodes.registerType("logiccloud-control-output", LogiccloudControlOutput);
RED.httpNode.get("/logiccloud/outputs", function (req, res) {
res.json(main_1.OutputVariablesByPortCache);
});
};
//# sourceMappingURL=logiccloud-control-output.js.map