Skip to content

Commit 3faf304

Browse files
committed
implemented remote action 'notify' and updated 'broadcast' button
1 parent 996c4c5 commit 3faf304

File tree

2 files changed

+63
-11
lines changed

2 files changed

+63
-11
lines changed

www/scripts/sepiaFW.local.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ function sepiaFW_build_strings(){
171171
StringsDE.remote_action_audio_stream = "Habe einen Audio Stream via Remote-Zugriff empfangen. Stream wird gestartet.";
172172
StringsDE.read_article = "Artikel lesen";
173173
StringsDE.choose_device_for_music = "Wähle ein Gerät auf dem du die Musik abspielen willst";
174+
StringsDE.choose_device_for_action = "Auf welchem Gerät soll die Aktion ausgeführt werden?";
175+
StringsDE.broadcast_to_device_or_chat = "Broadcast an eines deiner Geräte schicken oder per Chat senden?";
174176
StringsDE.relative_precipitation = "relativer Niederschlag";
175177
//Link sharing
176178
StringsDE.link_join_channel = "Einem Chat-Kanal beitreten."
@@ -377,6 +379,8 @@ function sepiaFW_build_strings(){
377379
StringsEN.remote_action_audio_stream = "I've received an audio stream via remote access. Starting now.";
378380
StringsEN.read_article = "Read article";
379381
StringsEN.choose_device_for_music = "Choose a device to play your music on";
382+
StringsEN.choose_device_for_action = "On which device should the action be executed?";
383+
StringsEN.broadcast_to_device_or_chat = "Broadcast to one of your devices or via chat?";
380384
StringsEN.relative_precipitation = "relative precipitation";
381385
//Link sharing
382386
StringsEN.link_join_channel = "Join a chat-channel."

www/scripts/sepiaFW.webSocket.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,14 +1046,14 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
10461046
var backBtn = document.getElementById("sepiaFW-back-btn");
10471047
if (backBtn){
10481048
$(backBtn).off();
1049-
$(backBtn).on("click", function () {
1049+
$(backBtn).on("click", function(){
10501050
SepiaFW.ui.backButtonAction();
10511051
});
10521052
}
10531053
//-always on mode
10541054
var alwaysOnBtn = document.getElementById("sepiaFW-alwaysOn-btn");
10551055
if (alwaysOnBtn){
1056-
$(alwaysOnBtn).off().on("click", function () {
1056+
$(alwaysOnBtn).off().on("click", function(){
10571057
if (SepiaFW.alwaysOn){
10581058
SepiaFW.ui.closeAllMenus();
10591059
SepiaFW.alwaysOn.start();
@@ -1064,7 +1064,7 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
10641064
var teachUiBtn = document.getElementById("sepiaFW-teachUI-open");
10651065
if (teachUiBtn){
10661066
$(teachUiBtn).off();
1067-
$(teachUiBtn).on("click", function () {
1067+
$(teachUiBtn).on("click", function(){
10681068
if (SepiaFW.teach){
10691069
SepiaFW.ui.closeAllMenus();
10701070
SepiaFW.teach.openUI();
@@ -1075,11 +1075,35 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
10751075
var saythisBtn = document.getElementById("sepiaFW-saythis-btn");
10761076
if (saythisBtn){
10771077
$(saythisBtn).off();
1078-
$(saythisBtn).on("click", function () {
1078+
$(saythisBtn).on("click", function(){
10791079
closeControlsMenueWithDelay();
1080-
var inp = document.getElementById("sepiaFW-chat-input");
1081-
inp.value = SepiaFW.assistant.name + ' ' + CMD_SAYTHIS + ' ';
1082-
inp.focus();
1080+
//chat or remote?
1081+
SepiaFW.ui.showPopup(SepiaFW.local.g('broadcast_to_device_or_chat'), {
1082+
inputLabelOne: "Text",
1083+
buttonOneName: "Remote Device",
1084+
buttonOneAction: function(btn, inputVal1){
1085+
//Remote
1086+
if (!inputVal1) return;
1087+
setTimeout(function(){
1088+
SepiaFW.client.showConnectedUserClientsAsMenu(SepiaFW.local.g('choose_device_for_action'),
1089+
function(deviceInfo){
1090+
SepiaFW.client.sendRemoteActionToOwnDevice("notify", {
1091+
type: "assistant_message",
1092+
text: inputVal1,
1093+
language: SepiaFW.speech.getLanguage() //speech or app lang.?
1094+
}, deviceInfo.deviceId);
1095+
}, true
1096+
);
1097+
}, 0);
1098+
},
1099+
buttonTwoName: "Send via Chat",
1100+
buttonTwoAction: function(btn, inputVal1){
1101+
//Chat
1102+
var inp = document.getElementById("sepiaFW-chat-input");
1103+
inp.value = SepiaFW.assistant.name + ' ' + CMD_SAYTHIS + ' ' + inputVal1;
1104+
inp.focus();
1105+
}
1106+
});
10831107
});
10841108
}
10851109
//-clear history
@@ -2229,6 +2253,7 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
22292253
//Music
22302254
}else if (message.data.type === "media"){
22312255
if (typeof action == "string"){
2256+
//default is stream
22322257
action = {
22332258
type: "audio_stream",
22342259
streamURL: action
@@ -2273,12 +2298,32 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
22732298

22742299
//Notification
22752300
}else if (message.data.type === "notify"){
2301+
if (typeof action == "string"){
2302+
//default is assistant text
2303+
action = {
2304+
type: "assistant_message",
2305+
text: action
2306+
}
2307+
}
2308+
SepiaFW.debug.info("remoteAction - notify: " + JSON.stringify(action));
2309+
22762310
//user has to be same! (security)
22772311
if (actionUser !== SepiaFW.account.getUserId()){
22782312
SepiaFW.debug.error("remoteAction - tried to use type 'notify' with wrong user");
22792313
}else{
2280-
//TODO: implement
2281-
SepiaFW.debug.log("remoteAction - no handler yet for type: " + message.data.type);
2314+
//handle
2315+
if (action.type == "assistant_message"){
2316+
if (action.text){
2317+
SepiaFW.assistant.waitForOpportunitySayLocalTextAndRunAction(
2318+
//localizedText, actionFun, fallbackAction, maxWait, speakOptions:
2319+
action.text, function(){}, undefined, 10000, {oneTimeLanguage: action.language}
2320+
);
2321+
//use instead? SepiaFW.events.setProActiveBackgroundNotification(action)
2322+
//TODO: add intro text? add notification? add something in the chat!
2323+
}
2324+
}else{
2325+
SepiaFW.debug.error("remoteAction - type: notify - no support yet for action type: " + action.type);
2326+
}
22822327
}
22832328

22842329
//Unknown
@@ -2568,9 +2613,12 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
25682613
if (message.senderType === "assistant"){
25692614
SepiaFW.speech.speak(messageTextSpeak, function(){
25702615
//finished - same callback as below
2571-
},function(){
2616+
}, function(){
25722617
//error
2573-
});
2618+
}, function(){
2619+
//started
2620+
}, {});
2621+
//TODO: support 'options'
25742622
}
25752623
}else{
25762624
if (message.senderType === "assistant"){

0 commit comments

Comments
 (0)