get cryptojs from bower; rework voice dialog

This commit is contained in:
Luke Pulverenti 2015-12-13 15:46:24 -05:00
parent d010a273a6
commit 9e9ef216fa
102 changed files with 7317 additions and 175 deletions

View file

@ -1,28 +1,6 @@
.voiceInputHelp {
background-image: url(../css/images/splash.jpg);
top: 50px;
left: 0;
right: 0;
bottom: 0;
position: fixed;
background-position: center center;
background-size: 100% 100%;
background-repeat: no-repeat;
/* Need to make sure it is on top of content but underneath slideout panels */
z-index: 1097;
}
.voiceInputHelpInner {
background: rgba(10,10,10,.8);
width: 100%;
height: 100%;
color: #eee;
}
.voiceHelpContent {
.voiceHelpContent {
max-width: 600px;
margin: auto;
padding: 1em 1em 0;
}
.exampleCommands {

View file

@ -23,73 +23,76 @@
function getSampleCommands() {
var deferred = DeferredBuilder.Deferred();
return new Promise(function (resolve, reject) {
var commands = [];
var commands = [];
//commands.push('show my movies');
//commands.push('pull up my tv shows');
//commands.push('show my movies');
//commands.push('pull up my tv shows');
commands.push('play my latest episodes');
commands.push('play next up');
commands.push('shuffle my favorite songs');
commands.push('play my latest episodes');
commands.push('play next up');
commands.push('shuffle my favorite songs');
commands.push('show my tv guide');
commands.push('pull up my recordings');
commands.push('control chromecast');
commands.push('control [device name]');
commands.push('turn on display mirroring');
commands.push('turn off display mirroring');
commands.push('toggle display mirroring');
commands.push('show my tv guide');
commands.push('pull up my recordings');
commands.push('control chromecast');
commands.push('control [device name]');
commands.push('turn on display mirroring');
commands.push('turn off display mirroring');
commands.push('toggle display mirroring');
deferred.resolveWith(null, [shuffleArray(commands)]);
return deferred.promise();
resolve(shuffleArray(commands));
});
}
function processText(text) {
var deferred = DeferredBuilder.Deferred();
return new Promise(function (resolve, reject) {
require(['voice/textprocessor-en-us.js'], function (parseText) {
require(['voice/textprocessor-en-us.js'], function (parseText) {
var result = parseText(text);
var result = parseText(text);
switch (result.action) {
switch (result.action) {
case 'show':
showCommand(result);
break;
case 'play':
playCommand(result);
break;
case 'shuffle':
playCommand(result, true);
break;
case 'search':
playCommand(result);
break;
case 'control':
controlCommand(result);
break;
case 'enable':
enableCommand(result);
break;
case 'disable':
disableCommand(result);
break;
case 'toggle':
toggleCommand(result);
break;
default:
deferred.reject();
return;
}
case 'show':
showCommand(result);
break;
case 'play':
playCommand(result);
break;
case 'shuffle':
playCommand(result, true);
break;
case 'search':
playCommand(result);
break;
case 'control':
controlCommand(result);
break;
case 'enable':
enableCommand(result);
break;
case 'disable':
disableCommand(result);
break;
case 'toggle':
toggleCommand(result);
break;
default:
reject();
return;
}
deferred.resolve();
var dlg = currentDialog;
if (dlg) {
PaperDialogHelper.close(dlg);
}
resolve();
});
});
return deferred.promise();
}
function showCommand(result) {
@ -223,23 +226,23 @@
$('.exampleCommands', elem).html(commands);
}
function showVoiceHelp() {
var currentDialog;
function showVoiceHelp(paperDialogHelper) {
var elem = $('.voiceInputHelp');
if (elem.length) {
$('.unrecognizedCommand').hide();
$('.defaultVoiceHelp').show();
return;
}
var dlg = paperDialogHelper.createDialog({
size: 'medium',
removeOnClose: true
});
var html = '';
html += '<h2 class="dialogHeader">';
html += '<paper-fab icon="arrow-back" mini class="btnCancelVoiceInput"></paper-fab>';
html += '</h2>';
html += '<div>';
var getCommandsPromise = getSampleCommands();
html += '<div class="voiceInputHelp">';
html += '<div class="voiceInputHelpInner">';
html += '<div class="voiceHelpContent">';
html += '<div class="defaultVoiceHelp">';
@ -263,27 +266,37 @@
html += '</div>';
html += '<paper-button raised class="block btnCancel" style="background-color:#444;"><iron-icon icon="close"></iron-icon><span>' + Globalize.translate('ButtonCancel') + '</span></paper-button>';
html += '<paper-button raised class="block btnCancelVoiceInput" style="background-color:#444;"><iron-icon icon="close"></iron-icon><span>' + Globalize.translate('ButtonCancel') + '</span></paper-button>';
// voiceHelpContent
html += '</div>';
// voiceInputHelpInner
html += '</div>';
// voiceInputHelp
html += '</div>';
dlg.innerHTML = html;
document.body.appendChild(dlg);
$(document.body).append(html);
paperDialogHelper.open(dlg);
currentDialog = dlg;
elem = $('.voiceInputHelp');
getCommandsPromise.then(function (commands) {
renderSampleCommands(elem, commands);
dlg.addEventListener('iron-overlay-closed', function () {
currentDialog = null;
});
$('.btnCancel', elem).on('click', cancelListener);
$('.btnRetry', elem).on('click', startListening);
$('.btnCancelVoiceInput', dlg).on('click', function () {
destroyCurrentRecognition();
paperDialogHelper.close(dlg);
});
$('.btnRetry', dlg).on('click', function () {
$('.unrecognizedCommand').hide();
$('.defaultVoiceHelp').show();
startListening(false);
});
getCommandsPromise.then(function (commands) {
renderSampleCommands(dlg.querySelector('.voiceHelpContent'), commands);
});
}
function showUnrecognizedCommandHelp() {
@ -292,27 +305,17 @@
$('.defaultVoiceHelp').hide();
}
function hideVoiceHelp() {
$('.voiceInputHelp').remove();
}
function cancelListener() {
destroyCurrentRecognition();
hideVoiceHelp();
}
function destroyCurrentRecognition() {
var recognition = currentRecognition;
if (recognition) {
recognition.cancelled = true;
recognition.abort();
currentRecognition = null;
}
}
function processTranscript(text) {
function processTranscript(text, isCancelled) {
$('.voiceInputText').html(text);
@ -322,19 +325,17 @@
$('.blockedMessage').show();
}
processText(text).then(hideVoiceHelp, showUnrecognizedCommandHelp);
if (text) {
processText(text).catch(showUnrecognizedCommandHelp);
} else if (!isCancelled) {
showUnrecognizedCommandHelp();
}
}
function startListening() {
function startListening(createUI) {
destroyCurrentRecognition();
require(['css!voice/voice.css']);
startListeningInternal();
}
function startListeningInternal() {
var recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
//recognition.continuous = true;
@ -347,16 +348,19 @@
};
recognition.onerror = function () {
processTranscript('');
processTranscript('', recognition.cancelled);
};
recognition.onnomatch = function () {
processTranscript('');
processTranscript('', recognition.cancelled);
};
recognition.start();
currentRecognition = recognition;
showVoiceHelp();
if (createUI !== false) {
require(['components/paperdialoghelper', 'paper-fab', 'css!voice/voice.css'], showVoiceHelp);
}
}
window.VoiceInputManager = {