@energyweb/node-red-contrib-green-proof-worker
Version:
## Peer dependencies
55 lines (54 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeRedApi = void 0;
class NodeRedApi {
constructor(RED, instance = null) {
this.RED = RED;
this.instance = instance;
if (instance) {
this.RED.nodes.createNode(instance.node, instance.config);
}
}
cloneAndInstantiate(node, config) {
return new NodeRedApi(this.RED, { node: node, config });
}
send(msg) {
this.instance.node.send(msg);
}
error(log) {
this.instance.node.error(log);
}
log(log) {
this.instance.node.log(log);
}
warn(log) {
this.instance.node.warn(log);
}
findNodeIdByType(type) {
let found = undefined;
this.RED.nodes.eachNode(node => {
if (found !== undefined) { // if already found
return;
}
if (node.type === type) {
found = node.id;
}
});
return found;
}
getNode(id) {
return this.RED.nodes.getNode(id);
}
on(event, cb) {
if (event === 'input') {
this.instance.node.on('input', (msg, _, done) => cb(msg, done));
}
else if (event === 'close') {
this.instance.node.on('close', (done) => cb(done));
}
}
status(status) {
this.instance.node.status(status);
}
}
exports.NodeRedApi = NodeRedApi;