Overriding the default onInput handler
Hi guys,
I have a noob question about overriding the default oninput handler (see documentation).
I 'think' I do it similar as in the ui-chart node:
// server-side event handlers
const evts = {
onInput: function (msg, send, done) {
// My custom onInput handler
...
},
onSocket: {
...
},
beforeSend: function (msg) {
...
}
}
// inform the dashboard UI that we are adding this node
if (group) {
group.register(node, config, evts)
But when I inject a message into my node, this happens:
- The message arrives in my Vue frontend code
- The
beforeSendof my node is called - My custom onInput handler above is being called
I had assumed that only 3 would happen, and not 1 and 2. Because 1 and 2 are triggered by the default onInput handler (which I have overridden)? Or perhaps I have not interpreted the documentation correctly?
Based on the msg.topic:
- Some messages only need server side processing, so they don't need to be send to the frontend
- Some messages need to be send to the frontend.
Can you please give me any tips about how I could achieve something like that.
Thanks!! Bart
The beforeSend is poorly named- it's actually beforeSendToClient, rather than the send() within the context of Node-RED. So, I would expect the order to be: 2, 3, 1 as you've listed it.
Hi @joepavitt,
Ah yes I see. In the old dashboard you had:
beforeEmitwhich was called before the message was emitted via websocket to the client, so you could change it if required.- 'beforeSend' which was called before the message was send on the output into the flow.
Now the order seems to be:
beforeSendonInputmsg-inputin the Vue frontendbeforeSend
The last one is a bit confusing for me. Seems the beforeSend is called a second time here:
How do we need to take into account that this function is being called in two different locations (i.e. before and after the frontend)? Because if I understand correctly, this function is not only used to preprocess messages before being send to the frontend?
And sorry but I still am not very sure what is the best way to prevent some messages (e.g. with topic xxx) to be pushed to the Vue frontend.
Thanks!!