Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client data to nodes with multiple outputs #1533

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions nodes/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,41 @@
*
*/
function addConnectionCredentials (RED, msg, conn, config) {
if (config.includeClientData) {

Check failure on line 40 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Block must not be padded by blank lines
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)

Check failure on line 41 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Trailing spaces not allowed
// 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);

Check failure on line 49 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon
}
});

Check failure on line 51 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon
item._client = {
...item._client,
...{
socketId: conn.id,
socketIp: conn.handshake?.address
}
};

Check failure on line 58 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon
return item;

Check failure on line 59 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon
};

Check failure on line 60 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon

// Handle arrays and nested arrays
const processMsg = (data) => {
if (Array.isArray(data)) {
return data.map(item => processMsg(item));

Check failure on line 65 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon
} else if (typeof data === 'object' && data !== null) {
return addClientData(data)
}
}
return data;

Check failure on line 69 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon
};

Check failure on line 70 in nodes/utils/index.js

View workflow job for this annotation

GitHub Actions / build / Build on 18

Extra semicolon

msg = processMsg(msg)
}
return msg
return msg;
}

function getThirdPartyWidgets (directory) {
Expand Down
Loading