Skip to content

Commit 003e6d4

Browse files
ThierryLeGaldceejay
authored andcommitted
Add persistantFrontEndValue property to addWidget options so it possbile to avoid replay message to be sent when front end reconnect (#558)
1 parent 7c68465 commit 003e6d4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ function init(RED) {
3232
* [width] - width of widget (default automatic)
3333
* [height] - height of widget (default automatic)
3434
* [order] - property to hold the placement order of the widget (default 0)
35-
* [templateScope] - scope of widhget/global or local (default local)
35+
* [templateScope] - scope of widget/global or local (default local)
3636
* [emitOnlyNewValues] - boolean (default true).
3737
If true, it checks if the payload changed before sending it
3838
to the front-end. If the payload is the same no message is sent.
3939
* [forwardInputMessages] - boolean (default true).
4040
If true, forwards input messages to the output
4141
* [storeFrontEndInputAsState] - boolean (default true).
4242
If true, any message received from front-end is stored as state
43+
[persistantFrontEndValue] - boolean (default true).
44+
If true, last received message is send again when front end reconnect.
4345
* [convert] - callback to convert the value before sending it to the front-end
4446
* [beforeEmit] - callback to prepare the message that is emitted to the front-end
4547
* [convertBack] - callback to convert the message from front-end before sending it to the next connected node
@@ -95,6 +97,9 @@ function addWidget(RED, options) {
9597
if (options.hasOwnProperty("storeFrontEndInputAsState")) {
9698
ui_options.storeFrontEndInputAsState = options.storeFrontEndInputAsState;
9799
}
100+
if (options.hasOwnProperty("persistantFrontEndValue")) {
101+
ui_options.persistantFrontEndValue = options.persistantFrontEndValue;
102+
}
98103
if (options.hasOwnProperty("convert")) {
99104
ui_options.convert = options.convert;
100105
}

ui.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ options:
111111
If true, forwards input messages to the output
112112
[storeFrontEndInputAsState] - boolean (default true).
113113
If true, any message received from front-end is stored as state
114+
[persistantFrontEndValue] - boolean (default true).
115+
If true, last received message is send again when front end reconnect.
114116
115117
[convert] - callback to convert the value before sending it to the front-end
116118
[beforeEmit] - callback to prepare the message that is emitted to the front-end
@@ -131,6 +133,9 @@ function add(opt) {
131133
if (typeof opt.storeFrontEndInputAsState === 'undefined') {
132134
opt.storeFrontEndInputAsState = true;
133135
}
136+
if (typeof opt.persistantFrontEndValue === 'undefined') {
137+
opt.persistantFrontEndValue = true;
138+
}
134139
opt.convert = opt.convert || noConvert;
135140
opt.beforeEmit = opt.beforeEmit || beforeEmit;
136141
opt.convertBack = opt.convertBack || noConvert;
@@ -248,7 +253,9 @@ function add(opt) {
248253
// Emit and Store the data
249254
//if (settings.verbose) { console.log("UI-EMIT",JSON.stringify(toEmit)); }
250255
emitSocket(updateValueEventName, toEmit);
251-
replayMessages[opt.node.id] = toStore;
256+
if (opt.persistantFrontEndValue) {
257+
replayMessages[opt.node.id] = toStore;
258+
}
252259

253260
// Handle the node output
254261
if (opt.forwardInputMessages && opt.node._wireCount) {
@@ -270,7 +277,9 @@ function add(opt) {
270277
var converted = opt.convertBack(msg.value);
271278
if (opt.storeFrontEndInputAsState === true) {
272279
currentValues[msg.id] = converted;
273-
replayMessages[msg.id] = msg;
280+
if (opt.persistantFrontEndValue) {
281+
replayMessages[msg.id] = msg;
282+
}
274283
}
275284
var toSend = {payload:converted};
276285
toSend = opt.beforeSend(toSend, msg) || toSend;

0 commit comments

Comments
 (0)