Redirect to past meeting authenticated users

This commit is contained in:
2024-09-02 11:51:58 +02:00
parent 2b157c7c8a
commit bda4e1cdc0

View File

@@ -1,8 +1,10 @@
"use client";
import "@whereby.com/browser-sdk/embed";
import { useRef } from "react";
import { useCallback, useEffect, useRef } from "react";
import useRoomMeeting from "./useRoomMeeting";
import { useRouter } from "next/navigation";
import { useFiefIsAuthenticated } from "@fief/fief/build/esm/nextjs/react";
export type RoomDetails = {
params: {
@@ -14,11 +16,27 @@ export default function Room(details: RoomDetails) {
const wherebyRef = useRef<HTMLElement>(null);
const roomName = details.params.roomName;
const meeting = useRoomMeeting(roomName);
const router = useRouter();
const isAuthenticated = useFiefIsAuthenticated();
const roomUrl = meeting?.response?.host_room_url
? meeting?.response?.host_room_url
: meeting?.response?.room_url;
const handleLeave = useCallback((e) => {
router.push("/browse");
}, []);
useEffect(() => {
if (!isAuthenticated || !roomUrl) return;
wherebyRef.current?.addEventListener("leave", handleLeave);
return () => {
wherebyRef.current?.removeEventListener("leave", handleLeave);
};
}, [handleLeave, roomUrl]);
return (
<>
{roomUrl && (