Last active
August 2, 2016 12:12
-
-
Save gbrault/cb5bf9be1d0b9852cfea4c6e6c318b7f to your computer and use it in GitHub Desktop.
multiplexing messages between nodered server and client ui (node-red ui) see first comment for usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"a280b0ca.203e2","type":"ui_template","z":"78b2e9d1.c8c848","tab":"635f39f2.c5f958","name":"","group":"","order":1,"format":"<pre>--{{msg.payload}}--{{msg.sender}}--</pre><br>\nv1:{{v1}}<br>\nv2:{{v2}}<br>\nv3:{{v3}}<br>\n<script>\n(function(scope) {\n scope.v1=\"\";\n scope.v2=\"\";\n scope.v3=\"\";\n scope.$watch('msg.sender', function(newValue, oldValue) {\n if((this.msg===undefined)||(this.msg===null)){console.log(\"msg not defined\");return;}\n switch(this.msg.sender.substr(0,1)){\n case \"1\":\n this.v1=this.msg.payload;\n break;\n case \"2\":\n this.v2=this.msg.payload;\n break;\n case \"3\":\n this.v3=this.msg.payload;\n break;\n default:\n console.log(\"not existing case:\"+this.msg.sender);\n }\n }.bind(scope));\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"x":695,"y":204,"wires":[[]]},{"id":"635f39f2.c5f958","type":"ui_tab","z":"78b2e9d1.c8c848","name":"test","icon":"dashboard","order":"100"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If one keep the message shared memory growing in a flow containing node-red ui components, the amount of data exchanged between the server and the client tend to grow. When this size is becoming to big, performance is degrading.
This gist is a small test which is self contained in one flow.
Just copy-paste the json into a clean flow and open the test ui.
Inject values (from the flow ui), open a client debug browser and see the traffic between the server and the client.
Messages are multiplexed and their states are explicitly saved in the client side according to the received message.
One must be careful about making a variable part (random) for the message sender type, else, angular will not detect the change and the user code for saving the incoming message will not be called if the same type is sent twice in a row!