summaryrefslogtreecommitdiffstats
path: root/htdocs/binding.js
diff options
context:
space:
mode:
Diffstat (limited to 'htdocs/binding.js')
-rw-r--r--htdocs/binding.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/htdocs/binding.js b/htdocs/binding.js
index c24d62e..7e7439b 100644
--- a/htdocs/binding.js
+++ b/htdocs/binding.js
@@ -3,6 +3,8 @@ var ws;
var evtIdx = 0;
var count = 0;
+var amazon = new AMAZON();
+var amazonCbl;
//**********************************************
// Logger
@@ -10,7 +12,7 @@ var count = 0;
var log = {
command: function (api, verb, query) {
console.log("subscribe api=" + api + " verb=" + verb + " query=", query);
- var question = urlWS + "/" + api + "/" + verb + "?query=" + JSON.stringify(query);
+ var question = afb.url + "/" + api + "/" + verb + "?query=" + JSON.stringify(query);
log._write("question", count + ": " + log.syntaxHighlight(question));
},
@@ -92,6 +94,8 @@ function init(elemID, api, verb, query) {
document.getElementById("connected").innerHTML = "Binder WS Active";
document.getElementById("connected").style.background = "lightgreen";
ws.onevent("*", log.event);
+ // Fetch and render voice agents.
+ fetchAndRenderVoiceAgents();
}
function onabort() {
@@ -165,6 +169,24 @@ 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);
}