import { useCallback, useEffect, useRef, useState } from 'react'; import Button from '@custom/shared/components/Button'; import { Card, CardBody, CardHeader, CardFooter, } from '@custom/shared/components/Card'; import { TextInput } from '@custom/shared/components/Input'; import DailyIframe from '@daily-co/daily-js'; import { writeText } from 'clipboard-polyfill'; import ExpiryTimer from '../components/ExpiryTimer'; const CALL_OPTIONS = { showLeaveButton: true, iframeStyle: { height: '100%', width: '100%', aspectRatio: 16 / 9, minwidth: '400px', maxWidth: '920px', border: '0', borderRadius: '12px', }, }; export function Call({ room, setRoom, callFrame, setCallFrame, expiry }) { const callRef = useRef(null); const [isLinkCopied, setIsLinkCopied] = useState(false); const handleCopyClick = useCallback(() => { writeText(room); setIsLinkCopied(true); setTimeout(() => setIsLinkCopied(false), 5000); }, [room, isLinkCopied]); const createAndJoinCall = useCallback(() => { const newCallFrame = DailyIframe.createFrame( callRef?.current, CALL_OPTIONS ); setCallFrame(newCallFrame); newCallFrame.join({ url: room }); const leaveCall = () => { setRoom(null); setCallFrame(null); callFrame.destroy(); }; newCallFrame.on('left-meeting', leaveCall); }, [room, setCallFrame]); /** * Initiate Daily iframe creation on component render if it doesn't already exist */ useEffect(() => { if (callFrame) return; createAndJoinCall(); }, [callFrame, createAndJoinCall]); return (
{/* Daily iframe container */}
Copy and share the URL to invite others {expiry && ( Room expires in: )}
); } export default Call;