Missing socketID impacts dashboard template

Working in a dashboard that has a tab that will be visualized in two (or three) different monitors at the same time (queue control in an hospital sector). I simplified and changed the flow to the minimum size that reproduces the issue.

Buttons 1 and 2 do the same thing in a slightly different way. In order to understand the issue you need to open the dashboard in two separate Chrome browsers (can be in the same computer).

When button 1 is clicked the patient name will be displayed in the green announcement area in both computers. This is just perfect.

Now, press button 2 and the patient name will show up in only one computer. This is bad.

This is the flow.

[{"id":"ea4a462.c6c5eb8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4adcd77.55b5428","type":"ui_template","z":"ea4a462.c6c5eb8","group":"e82460d6.00eef","name":"Announcement","order":3,"width":"8","height":"4","format":"<style>\n\n#Painel_Video .nr-dashboard-template {\n    background : rgb(16,203,97);\n    text-align: center;\n}\n\n</style>\n\n\n<div id=\"tex1\" class=\"sizedText\"></div>\n\n<script>\n\n(function(scope) {\n  scope.$watch('msg', function(msg) {\n    if (msg) {\n        console.log(msg);\n        var x = document.getElementById('tex1');\n        x.textContent =  msg.patient; \n    }\n  });\n})(scope);\n\n</script>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":860,"y":160,"wires":[[]]},{"id":"48d8231.17e56dc","type":"ui_button","z":"ea4a462.c6c5eb8","name":"","group":"e82460d6.00eef","order":1,"width":"4","height":"1","passthru":true,"label":"Call Patient 1","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","topicType":"str","x":290,"y":160,"wires":[["e2a883c5.238f2"]]},{"id":"e2a883c5.238f2","type":"function","z":"ea4a462.c6c5eb8","name":"node.send","func":"node.send({\"id\" : \"1234\"});","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":160,"wires":[["8a4c5f7b.318b"]]},{"id":"8a4c5f7b.318b","type":"function","z":"ea4a462.c6c5eb8","name":"","func":"msg.patient = \"AIOT\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":160,"wires":[["4adcd77.55b5428","7257a752.e6cef8"]]},{"id":"7257a752.e6cef8","type":"debug","z":"ea4a462.c6c5eb8","name":"MSG 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":100,"wires":[]},{"id":"614100d7.a982c","type":"ui_button","z":"ea4a462.c6c5eb8","name":"","group":"e82460d6.00eef","order":2,"width":"4","height":"1","passthru":true,"label":"Call Patient 2","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","topicType":"str","x":290,"y":220,"wires":[["449f4bb5.0abca4"]]},{"id":"449f4bb5.0abca4","type":"function","z":"ea4a462.c6c5eb8","name":"standard msg passing","func":"msg.id = \"5678\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":220,"wires":[["f6b95ba6.d74b18"]]},{"id":"f6b95ba6.d74b18","type":"function","z":"ea4a462.c6c5eb8","name":"","func":"msg.patient = \"MAKER\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":220,"wires":[["4adcd77.55b5428","829a5db7.b9495"]]},{"id":"829a5db7.b9495","type":"debug","z":"ea4a462.c6c5eb8","name":"MSG 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":260,"wires":[]},{"id":"e82460d6.00eef","type":"ui_group","name":"Video","tab":"8507c867.0a7328","order":8,"disp":false,"width":"16","collapse":false},{"id":"8507c867.0a7328","type":"ui_tab","name":"Painel","icon":"fa-television","order":1,"disabled":false,"hidden":false}]

Of course I could use only the function node that works as I expect but the point is that I want to understand why this is happening. It bothers me the fact that the "troubled" part of the flow uses the standard way of passing messages in Node-RED.

After more than six hours of troubleshooting I was able to identify that there is a small but crucial difference related to the way of passing messages. The most usual way generates a socketID number whereas using the send method will not generate the socketID number.

A-3

I did a search in the forum to find that a similar issue was reported in the past.

I am lost as I was not expecting that the code inside the ui template node could behave in a different way because of lack of socketID. My understanding is that the runtime would send messages to the all connected template nodes regardless of socketID number.

I am not sure if this is indeed a bug or it is my understanding of the working of ui template node (with scope.$watch) that need to be revised.

It's not template node specific - it is the way the whole dashboard works... Only messages arriving from a UI widget will contain a valid socketid. The dashboard will then (if the socketid is intact) then only reply back to that socketid - precisely so you can do things like only set an alert/notification popup back to that socket (otherwise everyone has to hit OK/Cancel which gets very annoying) - or you can use it to send a ui_control back to only one socket so they can switch tabs without switching all screens.

So if the socketid exists the msg gets sent to that socketid - if not (ie has been either deleted deliberately or a new message generated eg via node.send) then the msg is sent to all.

So yes - working as designed.

2 Likes

Hi @dceejay , indeed makes sense. Thank you very much !!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.