diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json
index 3071bfc51..e09713ec3 100644
--- a/packages/embeds/js/package.json
+++ b/packages/embeds/js/package.json
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
- "version": "0.0.74",
+ "version": "0.0.75",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
diff --git a/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx b/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx
index e3d0e65a6..efc375416 100644
--- a/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx
+++ b/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx
@@ -8,26 +8,34 @@ type Props = {
}
const showAnimationDuration = 400
-const typingDuration = 500
+const defaultTypingDuration = 5000
let typingTimeout: NodeJS.Timeout
export const AudioBubble = (props: Props) => {
let ref: HTMLDivElement | undefined
+ let audioElement: HTMLAudioElement | undefined
const [isTyping, setIsTyping] = createSignal(true)
+ const autoPlay = () => {
+ if (audioElement)
+ audioElement
+ .play()
+ .catch((e) => console.warn('Could not autoplay the audio:', e))
+ props.onTransitionEnd(ref?.offsetTop)
+ }
+
onMount(() => {
typingTimeout = setTimeout(() => {
setIsTyping(false)
- setTimeout(() => {
- const audioElement = ref?.querySelector('audio')
- if (audioElement)
- audioElement
- .play()
- .catch((e) => console.warn('Could not autoplay the audio:', e))
- props.onTransitionEnd(ref?.offsetTop)
- }, showAnimationDuration)
- }, typingDuration)
+ setTimeout(autoPlay, showAnimationDuration)
+ }, defaultTypingDuration)
+ if (audioElement)
+ audioElement.oncanplay = () => {
+ clearTimeout(typingTimeout)
+ setIsTyping(false)
+ setTimeout(autoPlay, showAnimationDuration)
+ }
})
onCleanup(() => {
@@ -48,6 +56,7 @@ export const AudioBubble = (props: Props) => {
{isTyping() && }