Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_event.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const { addConnectionCredentials } = require('../utils/index.js')
  2. module.exports = function (RED) {
  3. function EventNode (config) {
  4. const node = this
  5. RED.nodes.createNode(this, config)
  6. // which group are we rendering this widget
  7. const ui = RED.nodes.getNode(config.ui)
  8. const evts = {
  9. onSocket: {
  10. 'ui-event': function (conn, id, msg) {
  11. const wNode = RED.nodes.getNode(node.id)
  12. if (!wNode) {
  13. console.log('ui-event node not found', id)
  14. }
  15. // possible to send to all ui-event nodes,
  16. // or just a specific one specified by id
  17. if ((wNode && id === node.id) || id === 'all') {
  18. // this was sent by this particular node
  19. msg = addConnectionCredentials(RED, msg, conn, ui)
  20. wNode.send(msg)
  21. }
  22. }
  23. }
  24. }
  25. // inform the dashboard UI that we are adding this node
  26. ui?.register(null, null, node, config, evts)
  27. node.on('close', function (removed, done) {
  28. if (removed) {
  29. // handle node being removed
  30. ui?.deregister(null, null, node)
  31. }
  32. done()
  33. })
  34. }
  35. RED.nodes.registerType('ui-event', EventNode)
  36. }