diff options
Diffstat (limited to 'htdocs/binding.js')
-rw-r--r-- | htdocs/binding.js | 88 |
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 |