diff --git a/src/components/MemoriWidget/MemoriWidget.tsx b/src/components/MemoriWidget/MemoriWidget.tsx index ff00a78a..c3298d08 100644 --- a/src/components/MemoriWidget/MemoriWidget.tsx +++ b/src/components/MemoriWidget/MemoriWidget.tsx @@ -122,8 +122,18 @@ const typeMessage = ( hasBatchQueued, }, }); - document.dispatchEvent(e); + + const isSafariIOS = + window.navigator.userAgent.includes('Safari') && + !window.navigator.userAgent.includes('Chrome') && + /iPad|iPhone|iPod/.test(navigator.userAgent); + + if (isSafariIOS) { + setTimeout(() => { + document.dispatchEvent(new CustomEvent('MemoriEndSpeak')); + }, 300); + } }; const typeMessageHidden = ( message: string, @@ -189,10 +199,10 @@ const typeBatchMessages = ( ?.hasAttribute('disabled'); } - const isSafari = + const isSafariIOS = window.navigator.userAgent.includes('Safari') && - !window.navigator.userAgent.includes('Chrome'); - const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent); + !window.navigator.userAgent.includes('Chrome') && + /iPad|iPhone|iPod/.test(navigator.userAgent); const stepsGenerator = (function* () { yield* messages; @@ -209,17 +219,21 @@ const typeBatchMessages = ( disableInputs(); } + let waitForPrevious = step.waitForPrevious; + if (isSafariIOS) waitForPrevious = false; + typeMessage( step.message, - step.waitForPrevious, + waitForPrevious, step.hidden, step.typingText, step.useLoaderTextAsMsg, !next.done ); - if (isIOS && isSafari) { + if (isSafariIOS) { setTimeout(() => { + document.dispatchEvent(new CustomEvent('MemoriEndSpeak')); reEnableInputs(); }, 3000); } @@ -1561,35 +1575,6 @@ const MemoriWidget = ({ audioContext.resume().then(() => speak(text)); return; } - if (isIOS && isSafari) { - if (isPlayingAudio || memoriSpeaking) { - // try { - // memoriSpeaking = false; - // if (speechSynthesizer) { - // speechSynthesizer.close(); - // speechSynthesizer = null; - // } - // if (audioDestination) { - // audioDestination.pause(); - // audioDestination.close(); - // } - // if (audioContext) { - // // audioContext.close().then(() => { - // // audioContext = new AudioContext(); - // // let buffer = audioContext.createBuffer(1, 10000, 22050); - // // let source = audioContext.createBufferSource(); - // // source.buffer = buffer; - // // source.connect(audioContext.destination); - // // }); - // audioContext.destination.disconnect(); - // } - // } catch (e) { - // console.error('stopAudio error: ', e); - // emitEndSpeakEvent(); - // } - // stopAudio(); - } - } if (audioContext.state === 'closed') { audioContext = new AudioContext(); let buffer = audioContext.createBuffer(1, 10000, 22050); @@ -1647,9 +1632,6 @@ const MemoriWidget = ({ memoriSpeaking = true; try { - // if (audioContext.destination.context.state === 'running') { - // audioContext.destination.disconnect(); - // } audioContext.decodeAudioData(result.audioData, function (buffer) { source.buffer = buffer; source.connect(audioContext.destination); @@ -1688,13 +1670,13 @@ const MemoriWidget = ({ speechSynthesizer.close(); speechSynthesizer = null; } - // emitEndSpeakEvent(); + emitEndSpeakEvent(); } } else { audioContext.resume(); setIsPlayingAudio(false); memoriSpeaking = false; - // emitEndSpeakEvent(); + emitEndSpeakEvent(); } }, error => { @@ -1702,7 +1684,7 @@ const MemoriWidget = ({ window.speechSynthesis.speak(new SpeechSynthesisUtterance(text)); setIsPlayingAudio(false); memoriSpeaking = false; - // emitEndSpeakEvent(); + emitEndSpeakEvent(); } ); diff --git a/src/index.stories.tsx b/src/index.stories.tsx index f81b4715..2447e90f 100644 --- a/src/index.stories.tsx +++ b/src/index.stories.tsx @@ -52,6 +52,52 @@ Localhost.args = { integrationID: '82f017cc-450b-4c47-acf5-47910d336ce9', }; +const TemplateWithBatchButton: Story = args => ( +
+ + +
+); +export const WithBatch = TemplateWithBatchButton.bind({}); +WithBatch.args = { + ownerUserName: 'nzambello', + memoriName: 'Nicola', + tenantID: 'app.memorytwin.com', + apiURL: 'https://backend.memori.ai', + baseURL: 'https://app.memorytwin.com', + uiLang: 'it', + showShare: true, + showSettings: true, +}; + // export const Instruction = Template.bind({}); // Instruction.args = { // ownerUserName: 'nzambello', @@ -65,42 +111,3 @@ Localhost.args = { // pin: 'giver pin', // authToken: 'your login token', // }; - -export const DemoSophia = Template.bind({}); -DemoSophia.args = { - layout: 'TOTEM', - memoriName: 'Sophia', - ownerUserName: 'francescoimpellizzeri', - memoriID: '57405959-a2c5-4499-adb8-bb8dcc848ad5', - ownerUserID: '44ccefdb-d7a2-447e-9851-2a76be055a40', - tenantID: 'nextpresent.aclambda.online', - apiURL: 'https://backend.memori.ai', - baseURL: 'https://nextpresent.aclambda.online', - uiLang: 'it', - lang: 'it', - showShare: true, - showSettings: true, - integrationID: 'd10bbffd-26f3-4614-a092-15b215d04ffa', - initialQuestion: 'Welcome Totem', - contextVars: 'CONTEXT:TOTEM', - // https://assets.memori.ai/api/v2/asset/6af08bf1-f011-40ea-92a2-699b7b53a53c.glb -}; - -export const DemoStefano = Template.bind({}); -DemoStefano.args = { - layout: 'TOTEM', - memoriName: 'Stefano Zingoni', - ownerUserName: 'roberta.bianchi', - memoriID: 'd6df4c75-8dfb-4e6d-b19f-193fa8a9bcce', - ownerUserID: 'b242160e-c19c-468f-b7f8-b2dc1ce51045', - tenantID: 'gruppoe.aclambda.online', - apiURL: 'https://backend.memori.ai', - baseURL: 'https://gruppoe.aclambda.online', - uiLang: 'it', - lang: 'it', - showShare: true, - showSettings: true, - contextVars: 'CONTEXT:TOTEM', - integrationID: '5712601d-6174-45e7-bfb1-b4ac71c4ff80', - // https://assets.memori.ai/api/v2/asset/ed50c6a4-37cd-458b-9209-8cabfa256b30.glb -};