"use client"; import "@whereby.com/browser-sdk/embed"; import { useCallback, useEffect, useRef, useState } from "react"; import { Box, Button, Text, VStack, HStack } from "@chakra-ui/react"; import useRoomMeeting from "./useRoomMeeting"; import { useRouter } from "next/navigation"; import useSessionStatus from "../lib/useSessionStatus"; export type RoomDetails = { params: { roomName: string; }; }; export default function Room(details: RoomDetails) { const wherebyRef = useRef(null); const roomName = details.params.roomName; const meeting = useRoomMeeting(roomName); const router = useRouter(); const { isLoading, isAuthenticated } = useSessionStatus(); const [consentGiven, setConsentGiven] = useState(null); const roomUrl = meeting?.response?.host_room_url ? meeting?.response?.host_room_url : meeting?.response?.room_url; const handleLeave = useCallback(() => { router.push("/browse"); }, [router]); const handleConsent = (consent: boolean) => { setConsentGiven(consent); }; useEffect(() => { if (isLoading || !isAuthenticated || !roomUrl) return; wherebyRef.current?.addEventListener("leave", handleLeave); return () => { wherebyRef.current?.removeEventListener("leave", handleLeave); }; }, [handleLeave, roomUrl, isLoading, isAuthenticated]); if (!isAuthenticated && !consentGiven) { return ( {consentGiven === null ? ( <> This meeting may be recorded. Do you consent to being recorded? ) : ( <> You cannot join the meeting without consenting to being recorded. )} ); } return ( <> {roomUrl && ( )} ); }