Skip to content

Commit

Permalink
Merge pull request FlowFuse#1542 from FlowFuse/fix-for-fix-client-dat…
Browse files Browse the repository at this point in the history
…a-for-multiple-outputs

Add client data to nodes with multiple outputs
  • Loading branch information
joepavitt authored Dec 18, 2024
2 parents 357ebba + f99d34f commit abf3130
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions nodes/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,37 @@ 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
}
Expand Down

0 comments on commit abf3130

Please sign in to comment.