2
0

🐛 (bot) Improve canPlay issue fixin

This commit is contained in:
Baptiste Arnaud
2023-07-12 15:06:39 +02:00
parent 082084a90c
commit 0b4b15ce0a
4 changed files with 17 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.0.77", "version": "0.0.78",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@@ -18,25 +18,26 @@ export const AudioBubble = (props: Props) => {
let audioElement: HTMLAudioElement | undefined let audioElement: HTMLAudioElement | undefined
const [isTyping, setIsTyping] = createSignal(true) const [isTyping, setIsTyping] = createSignal(true)
const autoPlay = () => { const autoPlay = async () => {
if (isPlayed) return
isPlayed = true isPlayed = true
if (audioElement) try {
audioElement if (audioElement) await audioElement.play()
.play() } catch (e) {
.catch((e) => console.warn('Could not autoplay the audio:', e)) console.warn('Could not autoplay the audio:', e)
}
props.onTransitionEnd(ref?.offsetTop) props.onTransitionEnd(ref?.offsetTop)
} }
onMount(() => { onMount(() => {
if (audioElement) if (audioElement)
audioElement.oncanplay = () => { audioElement.oncanplay = () => {
if (isPlayed) return
clearTimeout(typingTimeout) clearTimeout(typingTimeout)
setIsTyping(false) setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration) setTimeout(autoPlay, showAnimationDuration)
} }
typingTimeout = setTimeout(() => { typingTimeout = setTimeout(() => {
if (isPlayed) return
setIsTyping(false) setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration) setTimeout(autoPlay, showAnimationDuration)
}, defaultTypingDuration) }, defaultTypingDuration)

View File

@@ -19,26 +19,26 @@ export const VideoBubble = (props: Props) => {
let videoElement: HTMLVideoElement | undefined let videoElement: HTMLVideoElement | undefined
const [isTyping, setIsTyping] = createSignal(true) const [isTyping, setIsTyping] = createSignal(true)
const autoPlay = () => { const autoPlay = async () => {
if (isPlayed) return
isPlayed = true isPlayed = true
if (videoElement) try {
videoElement if (videoElement) await videoElement.play()
.play() } catch (e) {
.catch((e) => console.warn('Could not autoplay the video:', e)) console.warn('Could not autoplay the video:', e)
}
props.onTransitionEnd(ref?.offsetTop) props.onTransitionEnd(ref?.offsetTop)
} }
onMount(() => { onMount(() => {
if (videoElement) if (videoElement)
videoElement.oncanplay = () => { videoElement.oncanplay = () => {
if (isPlayed) return
clearTimeout(typingTimeout) clearTimeout(typingTimeout)
setIsTyping(false) setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration) setTimeout(autoPlay, showAnimationDuration)
} }
typingTimeout = setTimeout( typingTimeout = setTimeout(
() => { () => {
if (isPlayed) return
setIsTyping(false) setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration) setTimeout(autoPlay, showAnimationDuration)
}, },

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.0.77", "version": "0.0.78",
"description": "React library to display typebots on your website", "description": "React library to display typebots on your website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",