Hi there,
I want to trace messages through a flow as an aid for beginners to understand how messages are passed through NR flows. I have already done this on the headless in-browser only NR but now I want to build a plugin that does the same the serverful NR.
Having been pointed to the hooks API by Nick, I created a plugin with the following bit of code:
module.exports = function (RED) {
function ConfigMsgTracerFunctionality(config) {
RED.nodes.createNode(this, config)
console.log( "REGISTERED TTPE MSGTTACER")
RED.hooks.add("onReceive", (evnt) => {
try {
let nde = RED.nodes.getNode(evnt.destination.id)
nde.status({ fill: "green", shape: "ring", text: "msg received" })
setTimeout( () => {
nde.status({})
},1000)
} catch(ex) {
console.error(ex)
}
})
}
RED.nodes.registerType('MsgTracerCfg', ConfigMsgTracerFunctionality);
}
This works perfectly, just what I want except .... the hook is added each time the plugin is registered and that is unfortunately each time I do a deploy.
The question is: how do I prevent the hook from being added multiple times?
EDIT: what I also noticed that without the try {...} catch { }, I can actually prevent messages from being passed around in NR, i.e., an exception in the hook will prevent the router from continuing. That should probably not happen and instead the hook dispatcher should wrap those callbacks in it's own try/catch ....
/cc @knolleary
