Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions docs/en/contributing/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ module.exports = function(RED) {
}
}
},
/**
* onEmitConfig - called when the UI configuration is about to be sent to a client
* @param {object} socket - SocketIO connection object to the client
* @param {object} config - The UI configuration object that will be sent
* @param {object} msg - A msg object, populated with connection credentials by `addConnectionCredentials`
* @returns {object} - The (potentially modified) UI configuration object
*/
onEmitConfig: (socket, config, msg) => {
// modify config in any way you like
// e.g. config.myCustomProperty = "Hello World"
// You can also use data from msg, e.g. msg._client.socketIp
return config
},
/**
* onInput - called when a node receives a message
* @param {object} msg - Node-RED msg object
Expand Down
21 changes: 19 additions & 2 deletions nodes/config/ui_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,33 @@ module.exports = function (RED) {
if (!handshakeEditKey || !meta?.wysiwyg?.editKey || handshakeEditKey !== meta.wysiwyg.editKey) {
delete meta.wysiwyg
}
// pass the connected UI the UI config
socket.emit('ui-config', node.id, {

// Prepare the UI configuration
const uiConfig = {
meta,
dashboards: Object.fromEntries(node.ui.dashboards),
heads: Object.fromEntries(node.ui.heads),
pages: Object.fromEntries(node.ui.pages),
themes: Object.fromEntries(node.ui.themes),
groups: Object.fromEntries(node.ui.groups),
widgets: Object.fromEntries(node.ui.widgets)
}

// Apply plugin modifications with connection credentials
let finalConfig = uiConfig
let msg = {}
msg = addConnectionCredentials(RED, msg, socket, node)
RED.plugins.getByType('node-red-dashboard-2').forEach(plugin => {
if (plugin.hooks?.onEmitConfig) {
const modifiedConfig = plugin.hooks.onEmitConfig(socket, finalConfig, msg)
if (modifiedConfig) {
finalConfig = modifiedConfig
}
}
})

// Pass the connected UI the UI config
socket.emit('ui-config', node.id, finalConfig)
}

// remove event handler socket listeners for a given socket connection
Expand Down
Loading