Skip to content

Commit 6dbef8d

Browse files
committed
prevent multiple queued follow-up messages of same type
1 parent 77385f1 commit 6dbef8d

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

www/scripts/sepiaFW.assistant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function sepiaFW_build_assistant(){
247247
* Wait for the right opportunity (e.g. idle time) and let the assistant say a text
248248
* loaded from server.
249249
*/
250-
Assistant.waitForOpportunityAndSay = function(dialogTagOrText, fallbackAction, minWait, maxWait){
250+
Assistant.waitForOpportunityAndSay = function(dialogTagOrText, fallbackAction, minWait, maxWait, doneCallback){
251251
if (!minWait) minWait = 2000;
252252
if (!maxWait) maxWait = 30000;
253253
if (!dialogTagOrText) dialogTagOrText = "<error_client_control_0a>";
@@ -259,6 +259,7 @@ function sepiaFW_build_assistant(){
259259
newReceiver: SepiaFW.assistant.id
260260
};
261261
SepiaFW.client.sendCommand(dataset, options);
262+
if (doneCallback) doneCallback();
262263
}, minWait, maxWait, function(){
263264
//Fallback, e.g.: SepiaFW.ui.showInfo(SepiaFW.local.g('no_client_support'));
264265
if (fallbackAction) fallbackAction();

www/scripts/sepiaFW.client.controls.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,36 @@ function sepiaFW_build_client_controls(){
1515
}
1616

1717
//Wait for opportunity and send a message (e.g. "some text" or "<error_client_control_0a>") and optionally show info fallback.
18-
function sendFollowUpMessage(msgOrAnswerTag, info){
18+
function sendFollowUpMessage(msgOrAnswerTag, info, deliveredCallback, fallbackCallback, sourceTag, blockIfScheduled){
19+
var minWait = 2000;
20+
var maxWait = 30000;
21+
if (sourceTag && blockIfScheduled){
22+
if (followUpsRunning[sourceTag] && (new Date().getTime() - followUpsRunning[sourceTag]) <= maxWait){
23+
//block
24+
return;
25+
}else{
26+
//prepare block
27+
followUpsRunning[sourceTag] = new Date().getTime();
28+
}
29+
}
1930
SepiaFW.assistant.waitForOpportunityAndSay(msgOrAnswerTag, function(){
2031
//Fallback after max-wait:
2132
if (info){
2233
SepiaFW.ui.showInfo(info);
2334
}
24-
}, 2000, 30000); //min-wait, max-wait
35+
if (fallbackCallback) fallbackCallback();
36+
if (sourceTag && blockIfScheduled){
37+
delete followUpsRunning[sourceTag];
38+
}
39+
}, minWait, maxWait, function(){
40+
//Done (success):
41+
if (deliveredCallback) deliveredCallback();
42+
if (sourceTag && blockIfScheduled){
43+
delete followUpsRunning[sourceTag];
44+
}
45+
});
2546
}
47+
var followUpsRunning = {};
2648

2749
//Open/close settings menu
2850
Controls.settings = function(controlData){
@@ -145,7 +167,12 @@ function sepiaFW_build_client_controls(){
145167
//TODO: we could use a Mesh-Node and the sendMessage API in Windows
146168
if (!isInternalPlayerStreaming && !sentAdditionalEvent && !controlData.skipFollowUp){
147169
//The user has probably tried to stop an external app but that was not possible
148-
sendFollowUpMessage(SepiaFW.local.g("tried_but_not_sure"), SepiaFW.local.g('result_unclear') + "Media: STOP"); //"<default_under_construction_0b>"
170+
var blockMultiple = true;
171+
var source = "controls.media.stop";
172+
sendFollowUpMessage(
173+
SepiaFW.local.g("tried_but_not_sure"), SepiaFW.local.g('result_unclear') + " Media: STOP", //"<default_under_construction_0b>"
174+
undefined, undefined, source, blockMultiple
175+
);
149176
}
150177

151178
//RESUME
@@ -175,7 +202,12 @@ function sepiaFW_build_client_controls(){
175202
//TODO: we could use a Mesh-Node and the sendMessage API in Windows
176203
if (!isInternalPlayerStreaming && !sentAdditionalEvent && !controlData.skipFollowUp){
177204
//The user has probably tried to resume an external app but that was not possible
178-
sendFollowUpMessage(SepiaFW.local.g("tried_but_not_sure"), SepiaFW.local.g('result_unclear') + "Media: RESUME"); //"<default_under_construction_0b>"
205+
var blockMultiple = true;
206+
var source = "controls.media.resume";
207+
sendFollowUpMessage(
208+
SepiaFW.local.g("tried_but_not_sure"), SepiaFW.local.g('result_unclear') + " Media: RESUME", //"<default_under_construction_0b>"
209+
undefined, undefined, source, blockMultiple
210+
);
179211
}
180212

181213
//NEXT
@@ -199,19 +231,34 @@ function sepiaFW_build_client_controls(){
199231

200232
//Out of options ... for now
201233
}else if (!controlData.skipFollowUp){
202-
sendFollowUpMessage("<default_under_construction_0b>", SepiaFW.local.g('no_client_support'));
234+
var blockMultiple = true;
235+
var source = "controls.media.next";
236+
sendFollowUpMessage(
237+
"<default_under_construction_0b>", SepiaFW.local.g('no_client_support') + " Media: NEXT",
238+
undefined, undefined, source, blockMultiple
239+
);
203240
SepiaFW.debug.error("Client controls - Unsupported action in 'media': " + controlData.action);
204241
}
205242
//TODO: add iOS and Windows?
206243
//TODO: we could use a Mesh-Node and the sendMessage API in Windows
207244
});
208245

209246
}else{
210-
sendFollowUpMessage("<default_under_construction_0b>", SepiaFW.local.g('no_client_support'));
247+
var blockMultiple = true;
248+
var source = "controls.media.unsupported";
249+
sendFollowUpMessage(
250+
"<default_under_construction_0b>", SepiaFW.local.g('no_client_support') + " Media: " + controlData.action,
251+
undefined, undefined, source, blockMultiple
252+
);
211253
SepiaFW.debug.error("Client controls - Unsupported action in 'media': " + controlData.action);
212254
}
213255
}else{
214-
sendFollowUpMessage("<error_client_control_0a>", SepiaFW.local.g('cant_execute'));
256+
var blockMultiple = true;
257+
var source = "controls.media.error";
258+
sendFollowUpMessage(
259+
"<error_client_control_0a>", SepiaFW.local.g('cant_execute'),
260+
undefined, undefined, source, blockMultiple
261+
);
215262
SepiaFW.debug.error("Client controls - Missing 'controlData' for 'media'!");
216263
}
217264
}

0 commit comments

Comments
 (0)