Skip to content

Commit abf3130

Browse files
authored
Merge pull request #1542 from FlowFuse/fix-for-fix-client-data-for-multiple-outputs
Add client data to nodes with multiple outputs
2 parents 357ebba + f99d34f commit abf3130

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

nodes/utils/index.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,37 @@ async function appendTopic (RED, config, wNode, msg) {
3838
*/
3939
function addConnectionCredentials (RED, msg, conn, config) {
4040
if (config.includeClientData) {
41-
if (!msg._client) {
42-
msg._client = {}
43-
}
44-
RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => {
45-
if (plugin.hooks?.onAddConnectionCredentials && msg) {
46-
msg = plugin.hooks.onAddConnectionCredentials(conn, msg)
41+
// Add _client to each element
42+
const addClientData = (item) => {
43+
if (!item._client) {
44+
item._client = {}
4745
}
48-
})
49-
msg._client = {
50-
...msg._client,
51-
...{
52-
socketId: conn.id,
53-
socketIp: conn.handshake?.address
46+
RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => {
47+
if (plugin.hooks?.onAddConnectionCredentials && item) {
48+
item = plugin.hooks.onAddConnectionCredentials(conn, item)
49+
}
50+
})
51+
item._client = {
52+
...item._client,
53+
...{
54+
socketId: conn.id,
55+
socketIp: conn.handshake?.address
56+
}
5457
}
58+
return item
5559
}
60+
61+
// Handle arrays and nested arrays
62+
const processMsg = (data) => {
63+
if (Array.isArray(data)) {
64+
return data.map(item => processMsg(item))
65+
} else if (typeof data === 'object' && data !== null) {
66+
return addClientData(data)
67+
}
68+
return data
69+
}
70+
71+
msg = processMsg(msg)
5672
}
5773
return msg
5874
}

0 commit comments

Comments
 (0)