@@ -100,7 +100,8 @@ Similar to `onAction`, when used as a boolean, this flag will trigger the defaul
100
100
2 . Appends any ` msg.topic ` defined on the node config
101
101
3 . Runs ` evts.beforeSend() ` _ (if provided)_
102
102
4 . Store the most recent message on the widget under the ` ._msg ` property which will contain the latest state/value of the widget
103
- 5 . Sends the ` msg ` onwards to any connected nodes
103
+ 5 . Pushes a ` widget-sync ` event to synchronize the widgets in all clients.
104
+ 6 . Sends the ` msg ` onwards to any connected nodes
104
105
105
106
#### Custom ` onChange ` Handler
106
107
@@ -111,8 +112,10 @@ Alternatively, you can override this default behaviour by providing a custom `on
111
112
* Handle the input from the widget
112
113
* @param {object} msg - the last known msg received (prior to this new value)
113
114
* @param {boolean} value - the updated value sent by the widget
115
+ * @param {Socket} conn - socket.io socket connecting to the server
116
+ * @param {String} id - widget id sending the action
114
117
*/
115
- onChange : async function (msg , value ) {
118
+ onChange : async function (msg , value , conn , id ) {
116
119
// ensure we have latest instance of the widget's node
117
120
const wNode = RED .nodes .getNode (node .id )
118
121
@@ -127,6 +130,10 @@ onChange: async function (msg, value) {
127
130
const off = RED .util .evaluateNodeProperty (config .offvalue , config .offvalueType , wNode)
128
131
msg .payload = value ? on : off
129
132
133
+ // sync this change to all clients with the same widget
134
+ const exclude = [conn .id ]
135
+ base .emit (' widget-sync:' + id, msg, node, exclude)
136
+
130
137
// simulate Node-RED node receiving an input
131
138
wNode .send (msg)
132
139
}
0 commit comments