Skip to content

Commit 52eef80

Browse files
authored
Merge pull request #28 from SEPIA-Framework/dev
final v2.5.0 fixes
2 parents 5182038 + 1a9f9ed commit 52eef80

File tree

6 files changed

+80
-14
lines changed

6 files changed

+80
-14
lines changed

www/scripts/clexi-0.8.2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var ClexiJS = (function(){
3535

3636
Clexi.availableXtensions = {}; //TODO: we should update this somehow (will only update once at welcome event)
3737

38-
Clexi.pingAndConnect = function(host, onPingOrIdError, onOpen, onClose, onError, onConnecting){
38+
Clexi.pingAndConnect = function(host, onPingOrIdError, onOpen, onClose, onError, onConnecting, onWelcome){
3939
var url;
4040
if (!host) url = location.origin;
4141
else url = host.replace(/^wss/, 'https').replace(/^ws/, 'http');
@@ -47,7 +47,7 @@ var ClexiJS = (function(){
4747
//console.log(data);
4848
//check ID
4949
if (data.id && (data.id == Clexi.serverId || (data.id == "[SECRET]" && Clexi.serverId))){
50-
Clexi.connect(host, onOpen, onClose, onError, onConnecting);
50+
Clexi.connect(host, onOpen, onClose, onError, onConnecting, onWelcome);
5151
}else{
5252
if (onPingOrIdError) onPingOrIdError({
5353
code: 418,
@@ -168,7 +168,7 @@ var ClexiJS = (function(){
168168
if (!requestedClose){
169169
//try reconnect?
170170
if (Clexi.doAutoReconnect){
171-
autoReconnect(host, onOpen, onClose, onError, onConnecting);
171+
autoReconnect(host, onOpen, onClose, onError, onConnecting, onWelcome);
172172
}
173173
}else{
174174
if (reconnectTimer) clearTimeout(reconnectTimer);
@@ -185,15 +185,15 @@ var ClexiJS = (function(){
185185
}
186186
}
187187

188-
function autoReconnect(host, onOpen, onClose, onError, onConnecting){
188+
function autoReconnect(host, onOpen, onClose, onError, onConnecting, onWelcome){
189189
reconnectTry++;
190190
var delay = Math.min(reconnectTry*reconnectTry*reconnectBaseDelay, reconnectMaxDelay);
191191
//TODO: we could/should check navigator.onLine here ...
192192
if (reconnectTimer) clearTimeout(reconnectTimer);
193193
reconnectTimer = setTimeout(function(){
194194
if (!isConnected && !requestedClose){
195195
if (Clexi.onLog) Clexi.onLog('CLEXI reconnecting after unexpected close. Try: ' + reconnectTry);
196-
Clexi.connect(host, onOpen, onClose, onError, onConnecting);
196+
Clexi.connect(host, onOpen, onClose, onError, onConnecting, onWelcome);
197197
}
198198
}, delay);
199199
}

www/scripts/sepiaFW.account.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ function sepiaFW_build_account(sepiaSessionId){
530530
//Setup login-box
531531
Account.setupLoginBox = function(){
532532
//demo login?
533-
var isDemoLogin = SepiaFW.data.get('isDemoLogin');
534-
if (isDemoLogin){
535-
userRoles = [isDemoLogin];
536-
skipLogin();
533+
var demoLogin = SepiaFW.data.get('isDemoLogin');
534+
if (demoLogin){
535+
userRoles = [demoLogin];
536+
skipLogin(demoLogin);
537537
return;
538538
}
539539
//try restore from data-storage to avoid login popup - refresh required after e.g. 1 day = 1000*60*60*24
@@ -659,7 +659,13 @@ function sepiaFW_build_account(sepiaSessionId){
659659
//$('#sepiaFW-login-extend-box').hide();
660660
});
661661
}
662-
function skipLogin(){
662+
function skipLogin(demoId){
663+
if (demoId && demoId == "setup"){
664+
//temporarily disabled
665+
SepiaFW.speech.skipTTS = true;
666+
SepiaFW.wakeTriggers.useWakeWord = false;
667+
SepiaFW.debug.log("Deactivated for setup: TTS, Wake-Word");
668+
}
663669
Account.toggleLoginBox();
664670
broadcastEnterWithoutLogin();
665671
Account.afterLogin();
@@ -896,7 +902,7 @@ function sepiaFW_build_account(sepiaSessionId){
896902
SepiaFW.data.set('isDemoLogin', userId);
897903
userRoles = [userId];
898904
SepiaFW.ui.hideLoader();
899-
skipLogin();
905+
skipLogin(userId);
900906
return;
901907
}
902908
//hash password

www/scripts/sepiaFW.inputControls.cmdl.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ function sepiaFW_build_input_controls_cmdl() {
4444
}else{
4545
document.removeEventListener('sepia_speech_event', speechBroadcaster);
4646
}
47+
if (Cmdl.broadcasters.wakeWord){
48+
document.addEventListener('sepia_wake_word', wakeWordBroadcaster);
49+
}else{
50+
document.removeEventListener('sepia_wake_word', wakeWordBroadcaster);
51+
}
4752

4853
//say hello
4954
broadcastEvent("event", {
@@ -56,14 +61,16 @@ function sepiaFW_build_input_controls_cmdl() {
5661
document.removeEventListener('sepia_state_change', stateBroadcaster);
5762
document.removeEventListener('sepia_login_event', loginBroadcaster);
5863
document.removeEventListener('sepia_speech_event', speechBroadcaster);
64+
document.removeEventListener('sepia_wake_word', wakeWordBroadcaster);
5965
}
6066
}
6167

6268
//Broadcasters to use, usually overwritten by headless settings
6369
Cmdl.broadcasters = {
6470
state: false,
6571
login: false,
66-
speech: false
72+
speech: false,
73+
wakeWord: false
6774
};
6875
function stateBroadcaster(ev){
6976
if (Cmdl.broadcasters.state && ev.detail && ev.detail.state){
@@ -87,6 +94,20 @@ function sepiaFW_build_input_controls_cmdl() {
8794
});
8895
}
8996
}
97+
function wakeWordBroadcaster(ev){
98+
if (Cmdl.broadcasters.wakeWord && ev.detail && ev.detail.state){
99+
var d = {
100+
state: ev.detail.state
101+
}
102+
if (ev.detail.keyword){
103+
d.word = ev.detail.keyword;
104+
}
105+
if (ev.detail.msg){
106+
d.msg = ev.detail.msg;
107+
}
108+
broadcastEvent("sepia-wake-word", d);
109+
}
110+
}
90111

91112
function handleClientBroadcastEvents(ev){
92113
//console.log(ev); //DEBUG
@@ -148,6 +169,23 @@ function sepiaFW_build_input_controls_cmdl() {
148169

149170
Cmdl.set = {};
150171

172+
Cmdl.set.wakeword = function(ev){
173+
if (ev.state){
174+
if (ev.state == "on" || ev.state == "active" || ev.state == "activate"){
175+
SepiaFW.wakeTriggers.useWakeWord = true;
176+
if (!SepiaFW.wakeTriggers.engineLoaded){
177+
SepiaFW.wakeTriggers.setupWakeWords(); //will auto-start after setup
178+
}else if (!SepiaFW.wakeTriggers.isListening()){
179+
SepiaFW.wakeTriggers.listenToWakeWords();
180+
}
181+
}else if (ev.state == "off" || ev.state == "inactive" || ev.state == "deactivate"){
182+
if (SepiaFW.wakeTriggers.engineLoaded && SepiaFW.wakeTriggers.isListening()){
183+
SepiaFW.wakeTriggers.stopListeningToWakeWords();
184+
}
185+
}
186+
}
187+
}
188+
151189
//---------- GET ------------
152190

153191
Cmdl.get = {};

www/scripts/sepiaFW.ui.animate.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,19 @@ function sepiaFW_build_animate(){
195195

196196
Animate.wakeWord.active = function(){
197197
$('#sepiaFW-nav-label-online-status').addClass("wake-word-active");
198+
//dispatch event
199+
var event = new CustomEvent('sepia_wake_word', { detail: {
200+
state: "active"
201+
}});
202+
document.dispatchEvent(event);
198203
}
199204
Animate.wakeWord.inactive = function(){
200205
$('#sepiaFW-nav-label-online-status').removeClass("wake-word-active");
206+
//dispatch event
207+
var event = new CustomEvent('sepia_wake_word', { detail: {
208+
state: "inactive"
209+
}});
210+
document.dispatchEvent(event);
201211
}
202212

203213
//channel animations for missed off-channel messages:

www/scripts/sepiaFW.wakeTriggers.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function sepiaFW_build_wake_triggers() {
1818

1919
//dispatch event
2020
var event = new CustomEvent('sepia_wake_word', { detail: {
21-
keyword: keyword
21+
keyword: keyword,
22+
state: "triggered"
2223
}});
2324
document.dispatchEvent(event);
2425

@@ -33,6 +34,15 @@ function sepiaFW_build_wake_triggers() {
3334
});
3435
}
3536
}
37+
function broadcastWakeWordError(error){
38+
//dispatch event
39+
var event = new CustomEvent('sepia_wake_word', { detail: {
40+
msg: error,
41+
state: "error"
42+
}});
43+
document.dispatchEvent(event);
44+
}
45+
//NOTE: active, inactive: see ui.animate.wakeWord...
3646

3747
//Interface
3848

@@ -399,6 +409,7 @@ function sepiaFW_build_wake_triggers() {
399409
}
400410
SepiaFW.debug.error("Porcupine: " + errMsg);
401411
SepiaFW.ui.showPopup("Porcupine error: " + errMsg);
412+
broadcastWakeWordError(errMsg);
402413
};
403414

404415
//-------------------------------------------------

www/settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ SepiaFW.settings = {
3939
broadcast: {
4040
"state": true,
4141
"login": true,
42-
"speech": true
42+
"speech": true,
43+
"wakeWord": true
4344
}
4445
}
4546
};

0 commit comments

Comments
 (0)