From 359492fbaf97371b44159507c7390c78aa5884d4 Mon Sep 17 00:00:00 2001 From: Flavio C Date: Sun, 8 Oct 2023 13:59:21 +0200 Subject: [PATCH] feat: adds logic to make it work without a key --- streaming-client-api.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/streaming-client-api.js b/streaming-client-api.js index 3f90f3f..cea52ed 100644 --- a/streaming-client-api.js +++ b/streaming-client-api.js @@ -1,5 +1,15 @@ 'use strict'; -import DID_API from './api.json' assert { type: 'json' }; +// import DID_API from './api.json' assert { type: 'json' }; +let DID_API; +try { + const r = await fetch('api.json'); + DID_API = await r.json(); +} catch { + DID_API = { + key: '', + url: 'https://api.d-id.com', + }; +} const QUESTIONS = [ { @@ -145,7 +155,7 @@ document.getElementById('send-button').addEventListener('click', async function } botMessage.appendChild(loadingDiv); if (highestElement.similarity > 0.2) { - if(streamingOn){ + if (streamingOn) { await startStream(highestElement.id); botMessage.removeChild(loadingDiv); botMessage.textContent = highestElement.answer; @@ -407,7 +417,11 @@ async function fetchWithRetries(url, options, retries = 1) { document.getElementById('startButton').onclick = async () => { document.getElementById('startButton').classList.add('hidden'); document.getElementById('loading').classList.remove('hidden'); - await connect(); + if(DID_API.key){ + await connect(); + } else { + await new Promise(r => setTimeout(r, 2000)); + } document.getElementById('loading').classList.add('hidden'); document.getElementById('content').classList.remove('hidden'); document.getElementById('buttons').classList.remove('hidden');