From c492bc0d704424a858b2ff853a18fe1867277da7 Mon Sep 17 00:00:00 2001 From: luisthieme Date: Thu, 12 Dec 2024 15:39:18 +0100 Subject: [PATCH 1/2] add fix for client data with multiple outputs --- nodes/utils/index.js | 45 ++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/nodes/utils/index.js b/nodes/utils/index.js index c16ebafd3..10fdc2ee0 100644 --- a/nodes/utils/index.js +++ b/nodes/utils/index.js @@ -38,23 +38,40 @@ async function appendTopic (RED, config, wNode, msg) { */ function addConnectionCredentials (RED, msg, conn, config) { if (config.includeClientData) { - if (!msg._client) { - msg._client = {} - } - RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => { - if (plugin.hooks?.onAddConnectionCredentials && msg) { - msg = plugin.hooks.onAddConnectionCredentials(conn, msg) + + // Add _client to each element + const addClientData = (item) => { + if (!item._client) { + item._client = {} } - }) - msg._client = { - ...msg._client, - ...{ - socketId: conn.id, - socketIp: conn.handshake?.address + RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => { + if (plugin.hooks?.onAddConnectionCredentials && item) { + item = plugin.hooks.onAddConnectionCredentials(conn, item); + } + }); + item._client = { + ...item._client, + ...{ + socketId: conn.id, + socketIp: conn.handshake?.address + } + }; + return item; + }; + + // Handle arrays and nested arrays + const processMsg = (data) => { + if (Array.isArray(data)) { + return data.map(item => processMsg(item)); + } else if (typeof data === 'object' && data !== null) { + return addClientData(data) } - } + return data; + }; + + msg = processMsg(msg) } - return msg + return msg; } function getThirdPartyWidgets (directory) { From f99d34f1ec5595bf2af3b5f590d70198c09245e1 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 18 Dec 2024 17:47:30 +0000 Subject: [PATCH 2/2] linting fixes --- nodes/utils/index.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/nodes/utils/index.js b/nodes/utils/index.js index 10fdc2ee0..64a824bcc 100644 --- a/nodes/utils/index.js +++ b/nodes/utils/index.js @@ -38,7 +38,6 @@ async function appendTopic (RED, config, wNode, msg) { */ function addConnectionCredentials (RED, msg, conn, config) { if (config.includeClientData) { - // Add _client to each element const addClientData = (item) => { if (!item._client) { @@ -46,32 +45,32 @@ function addConnectionCredentials (RED, msg, conn, config) { } RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => { if (plugin.hooks?.onAddConnectionCredentials && item) { - item = plugin.hooks.onAddConnectionCredentials(conn, item); + item = plugin.hooks.onAddConnectionCredentials(conn, item) } - }); + }) item._client = { ...item._client, ...{ socketId: conn.id, socketIp: conn.handshake?.address } - }; - return item; - }; + } + return item + } // Handle arrays and nested arrays const processMsg = (data) => { if (Array.isArray(data)) { - return data.map(item => processMsg(item)); + return data.map(item => processMsg(item)) } else if (typeof data === 'object' && data !== null) { return addClientData(data) } - return data; - }; + return data + } msg = processMsg(msg) } - return msg; + return msg } function getThirdPartyWidgets (directory) {