import React, { useEffect, useMemo, useRef, useState } from 'react' import { useTypebot } from 'contexts/TypebotContext' import { Variable, VideoBubbleContent, VideoBubbleContentType, VideoBubbleBlock, } from 'models' import { TypingContent } from './TypingContent' import { parseVariables } from 'services/variable' type Props = { block: VideoBubbleBlock onTransitionEnd: () => void } export const showAnimationDuration = 400 export const mediaLoadingFallbackTimeout = 5000 export const VideoBubble = ({ block, onTransitionEnd }: Props) => { const { typebot, isLoading } = useTypebot() const messageContainer = useRef(null) const [isTyping, setIsTyping] = useState(true) useEffect(() => { if (!isTyping || isLoading) return showContentAfterMediaLoad() // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoading]) const showContentAfterMediaLoad = () => { setTimeout(() => { setIsTyping(false) onTypingEnd() }, 1000) } const onTypingEnd = () => { setIsTyping(false) setTimeout(() => { onTransitionEnd() }, showAnimationDuration) } return (
{isTyping ? : <>}
) } const VideoContent = ({ content, isTyping, variables, }: { content?: VideoBubbleContent isTyping: boolean variables: Variable[] }) => { const url = useMemo( () => parseVariables(variables)(content?.url), // eslint-disable-next-line react-hooks/exhaustive-deps [variables] ) if (!content?.type) return <> switch (content.type) { case VideoBubbleContentType.URL: const isSafariBrowser = window.navigator.vendor.match(/apple/i) return ( ) case VideoBubbleContentType.VIMEO: case VideoBubbleContentType.YOUTUBE: { const baseUrl = content.type === VideoBubbleContentType.VIMEO ? 'https://player.vimeo.com/video' : 'https://www.youtube.com/embed' return (