import DailyIframe from '@daily-co/daily-js'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { writeText } from 'clipboard-polyfill'; import Button from '@dailyjs/shared/components/Button'; import { Card, CardBody, CardHeader, CardFooter, } from '@dailyjs/shared/components/Card'; import ExpiryTimer from '@dailyjs/shared/components/ExpiryTimer'; import TextInput from '@dailyjs/shared/components/Input'; const CALL_OPTIONS = { showLeaveButton: true, iframeStyle: { height: '100%', width: '100%', aspectRatio: 16 / 9, minwidth: '400px', maxWidth: '920px', border: '0', borderRadius: '12px', }, }; export const 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); }); /** * 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;