2
0

Revert onCanPlay callback

Introduced too many issues in prod
This commit is contained in:
Baptiste Arnaud
2023-07-12 15:14:34 +02:00
parent 0b4b15ce0a
commit d6c6434050
4 changed files with 24 additions and 49 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.0.78", "version": "0.0.79",
"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

@ -8,8 +8,7 @@ type Props = {
} }
const showAnimationDuration = 400 const showAnimationDuration = 400
const defaultTypingDuration = 5000 const typingDuration = 500
let isPlayed = false
let typingTimeout: NodeJS.Timeout let typingTimeout: NodeJS.Timeout
@ -18,29 +17,18 @@ 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 = async () => {
if (isPlayed) return
isPlayed = true
try {
if (audioElement) await audioElement.play()
} catch (e) {
console.warn('Could not autoplay the audio:', e)
}
props.onTransitionEnd(ref?.offsetTop)
}
onMount(() => { onMount(() => {
if (audioElement)
audioElement.oncanplay = () => {
clearTimeout(typingTimeout)
setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration)
}
typingTimeout = setTimeout(() => { typingTimeout = setTimeout(() => {
setIsTyping(false) setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration) setTimeout(() => {
}, defaultTypingDuration) 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)
}) })
onCleanup(() => { onCleanup(() => {

View File

@ -9,9 +9,6 @@ type Props = {
} }
export const showAnimationDuration = 400 export const showAnimationDuration = 400
const defaultTypingDuration = 5000
let isPlayed = false
let typingTimeout: NodeJS.Timeout let typingTimeout: NodeJS.Timeout
export const VideoBubble = (props: Props) => { export const VideoBubble = (props: Props) => {
@ -19,31 +16,21 @@ 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 = async () => { const onTypingEnd = () => {
if (isPlayed) return const videoElement = ref?.querySelector('video')
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) if (!isTyping()) return
} setIsTyping(false)
setTimeout(() => {
props.onTransitionEnd(ref?.offsetTop) props.onTransitionEnd(ref?.offsetTop)
}, showAnimationDuration)
} }
onMount(() => { onMount(() => {
if (videoElement) typingTimeout = setTimeout(onTypingEnd, 2000)
videoElement.oncanplay = () => {
clearTimeout(typingTimeout)
setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration)
}
typingTimeout = setTimeout(
() => {
setIsTyping(false)
setTimeout(autoPlay, showAnimationDuration)
},
videoElement ? defaultTypingDuration : 2000
)
}) })
onCleanup(() => { onCleanup(() => {

View File

@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.0.78", "version": "0.0.79",
"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",