UNPKG

node-red-contrib-filemaker

Version:

Node-RED FileMaker nodes. These nodes use the FileMaker Data API to connect with a FileMaker database.

43 lines (32 loc) 1.19 kB
module.exports = function(RED) { function status(config) { const { send, handleError } = require("../services"); const { client, output } = config; RED.nodes.createNode(this, config); const node = this; node.client = RED.nodes.getNode(client); node.status({ fill: "blue", shape: "dot", text: "Loading" }); node.handleEvent = ({ connected, message }) => node.status( connected ? { fill: "green", shape: "dot", text: message } : { fill: "red", shape: "dot", text: message } ); /* istanbul ignore else */ if (node.client) node.client.on("status", node.handleEvent); node.on("input", async message => { node.status({ fill: "yellow", shape: "dot", text: "Processing" }); try { await this.client.connection; const client = await this.client.client; client.status().then(response => send(node, output, message, response)); } catch (error) { handleError(node, error.message, message); } }); node.on("close", () => node.client.removeListener("status", node.handleEvent) ); } RED.nodes.registerType("dapi-status", status); };