aboutsummaryrefslogtreecommitdiffstats
path: root/htdocs/binding.js
diff options
context:
space:
mode:
authorNaveen Bobbili <nbobbili@amazon.com>2019-02-25 17:24:29 -0800
committerNaveen Bobbili <nbobbili@amazon.com>2019-02-25 20:55:05 -0800
commit9eb3a90df3681586b58146b47eea7f3848c348a0 (patch)
tree9c507e13c233fb649d04c6a45d152f7ec12185f8 /htdocs/binding.js
parent143363b9e864ea465c927057ce7214f124a984cb (diff)
Refactored VSHL into vshl-core and vshl-capabilities.
vshl-core: This API is responsible for request arbitration. Verbs exposed are 1. startListening 2. cancelListening 3. subscribe 4. enumerateVoiceAgents 5. setDefaultVoiceAgent Used by applications to subscribe to dialog, connection and auth states of underlying low level voiceagent bindings. Used by applications to trigger voice recognition routine of the underlying low level voiceagent binding. vshl-capabilities: This API exposes publish and subscribe methods for all the speech framework domains/capabilities. For eg. navigation, phonecontrol etc. This API is used by apps and low level voice agent binding to subscribe and publish these capability messages whenever applicable. The code for this is agl-service-voice-high-capabilities repository. This specific commit is for vshl-core API. Change-Id: I1101db19b57ee918482a178843641b088508ac5d Signed-off-by: Naveen Bobbili <nbobbili@amazon.com>
Diffstat (limited to 'htdocs/binding.js')
-rw-r--r--htdocs/binding.js88
1 files changed, 27 insertions, 61 deletions
diff --git a/htdocs/binding.js b/htdocs/binding.js
index 7e7439b..c5ceb06 100644
--- a/htdocs/binding.js
+++ b/htdocs/binding.js
@@ -1,18 +1,14 @@
-var afb = new AFB("api", "mysecret");
+var afbVshlCore;
var ws;
var evtIdx = 0;
var count = 0;
-
-var amazon = new AMAZON();
-var amazonCbl;
-
//**********************************************
// Logger
//**********************************************
var log = {
- command: function (api, verb, query) {
+ command: function (url, api, verb, query) {
console.log("subscribe api=" + api + " verb=" + verb + " query=", query);
- var question = afb.url + "/" + api + "/" + verb + "?query=" + JSON.stringify(query);
+ var question = url + "/" + api + "/" + verb + "?query=" + JSON.stringify(query);
log._write("question", count + ": " + log.syntaxHighlight(question));
},
@@ -67,8 +63,8 @@ var log = {
//**********************************************
// Generic function to call binder
//***********************************************
-function callbinder(api, verb, query) {
- log.command(api, verb, query);
+function callbinder(url, api, verb, query) {
+ log.command(url, api, verb, query);
// ws.call return a Promise
return ws.call(api + '/' + verb, query)
@@ -84,10 +80,15 @@ function callbinder(api, verb, query) {
});
};
+
//**********************************************
-// Init - establish Websocket connection
+// connect - establish Websocket connection
//**********************************************
-function init(elemID, api, verb, query) {
+function connect(elemID, api, verb, query) {
+ connectVshlCore(elemID, api, verb, query);
+}
+
+function connectVshlCore(elemID, api, verb, query) {
function onopen() {
document.getElementById("main").style.visibility = "visible";
@@ -104,7 +105,15 @@ function init(elemID, api, verb, query) {
document.getElementById("connected").style.background = "red";
}
- ws = new afb.ws(onopen, onabort);
+ var urlparams = {
+ base: "api",
+ token: "HELLO",
+ };
+ const vshlCoreAddressInput = document.getElementById('vshl-core-address');
+ urlparams.host = vshlCoreAddressInput.value;
+
+ afbVshlCore = new AFB(urlparams, "HELLO");
+ ws = new afbVshlCore.ws(onopen, onabort);
}
function clearPre(preId) {
@@ -120,11 +129,11 @@ function fetchAndRenderVoiceAgents() {
agentsDiv.removeChild(agentsDiv.firstChild);
}
- const api = 'vshl';
+ const api = 'vshl-core';
const verb = 'enumerateVoiceAgents';
const query = {};
- log.command(api, verb, query);
+ log.command(afbVshlCore.url, api, verb, query);
return ws.call(api + '/' + verb, query)
.then(function (res) {
@@ -155,7 +164,7 @@ function addVoiceAgent(containerDiv, voiceAgent, isDefault) {
const setDefaultBtn = document.createElement("button");
setDefaultBtn.addEventListener('click', (evt) => {
const query = {"id": voiceAgent.id};
- callbinder('vshl', 'setDefaultVoiceAgent', query);
+ callbinder(afbVshlCore.url, 'vshl-core', 'setDefaultVoiceAgent', query);
fetchAndRenderVoiceAgents();
});
setDefaultBtn.innerHTML = 'SetDefault';
@@ -169,24 +178,6 @@ function addVoiceAgent(containerDiv, voiceAgent, isDefault) {
subscribeBtn.innerHTML = 'Subscribe';
agentDiv.appendChild(subscribeBtn);
- // Login implementation for Alexa Voice Agent
- if (voiceAgent.name == "Alexa") {
- amazonCbl = new amazon.cbl();
- if (typeof(Storage) !== "undefined" &&
- localStorage.getItem("access_token") !== null &&
- localStorage.getItem("refresh_token") !== null) {
- amazonCbl.refreshToken(voiceAgent);
- } else {
- const loginWithAmazonBtn = document.createElement("button");
- loginWithAmazonBtn.addEventListener('click', (evt) => {
- loginWithAmazonBtn.style.visibility = "hidden";
- amazonCbl.login(voiceAgent);
- });
- loginWithAmazonBtn.innerHTML = 'Login With Amazon!!';
- agentDiv.appendChild(loginWithAmazonBtn);
- }
- }
-
containerDiv.appendChild(agentDiv);
}
@@ -210,7 +201,7 @@ function showAgentEventChooserDialog(voiceAgentId) {
if (connectionState)
query.events.push('voice_connectionstate_event');
- callbinder('vshl', 'subscribe', query);
+ callbinder(afbVshlCore.url, 'vshl-core', 'subscribe', query);
modal.close();
});
@@ -218,31 +209,6 @@ function showAgentEventChooserDialog(voiceAgentId) {
modal.showModal();
}
-function showTemplateUIEventChooserDialog() {
- const modal = document.getElementById('templateui-event-chooser');
- const subscribeBtn = document.getElementById('templateui-subscribe-btn');
-
- subscribeBtn.addEventListener('click', (evt) => {
- const renderTemplate = document.getElementById('render_template').checked;
- const clearTemplate = document.getElementById('clear_template').checked;
- const renderPlayerInfo = document.getElementById('render_player_info').checked;
- const clearPlayerInfo = document.getElementById('clear_player_info').checked;
-
- const query = {"actions":[]};
-
- if (renderTemplate)
- query.actions.push('render_template');
- if (clearTemplate)
- query.actions.push('clear_template');
- if (renderPlayerInfo)
- query.actions.push('render_player_info');
- if (clearPlayerInfo)
- query.actions.push('clear_player_info');
-
- callbinder('vshl', 'guiMetadata/subscribe', query);
- modal.close();
- });
-
- // makes modal appear (adds `open` attribute)
- modal.showModal();
+function startListening() {
+ callbinder(afbVshlCore.url, 'vshl-core', 'startListening', {});
} \ No newline at end of file