@@ -100,7 +100,8 @@ Similar to `onAction`, when used as a boolean, this flag will trigger the defaul
1001002 . Appends any ` msg.topic ` defined on the node config
1011013 . Runs ` evts.beforeSend() ` _ (if provided)_
1021024 . 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
104105
105106#### Custom ` onChange ` Handler
106107
@@ -111,8 +112,10 @@ Alternatively, you can override this default behaviour by providing a custom `on
111112 * Handle the input from the widget
112113 * @param {object} msg - the last known msg received (prior to this new value)
113114 * @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
114117 */
115- onChange : async function (msg , value ) {
118+ onChange : async function (msg , value , conn , id ) {
116119 // ensure we have latest instance of the widget's node
117120 const wNode = RED .nodes .getNode (node .id )
118121
@@ -127,6 +130,10 @@ onChange: async function (msg, value) {
127130 const off = RED .util .evaluateNodeProperty (config .offvalue , config .offvalueType , wNode)
128131 msg .payload = value ? on : off
129132
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+
130137 // simulate Node-RED node receiving an input
131138 wNode .send (msg)
132139}
0 commit comments