diff --git a/.env.example b/.env.example index 3ffec65..683f4ba 100644 --- a/.env.example +++ b/.env.example @@ -14,4 +14,7 @@ NEXT_PUBLIC_STREAM_API_KEY= STREAM_API_SECRET= # supabase | stream -VIDEO_STORAGE_PLATFORM=supabase \ No newline at end of file +VIDEO_STORAGE_PLATFORM=supabase + +# Maximum video length in seconds +NEXT_PUBLIC_VIDEO_MAX_LENGTH=60 \ No newline at end of file diff --git a/app/vlogs/[username]/[vlog_id]/page.tsx b/app/vlogs/[username]/[vlog_id]/page.tsx index 71c191a..0c5bbe6 100644 --- a/app/vlogs/[username]/[vlog_id]/page.tsx +++ b/app/vlogs/[username]/[vlog_id]/page.tsx @@ -99,7 +99,6 @@ const getVlog = async (vlogId: string): Promise => { ? await getVlogFromStream(vlogId) : await getVlogFromSupabase(vlogId); - console.log({ vlog }); return vlog; }; diff --git a/app/vlogs/new/page.tsx b/app/vlogs/new/page.tsx index 78d63ca..a989c1b 100644 --- a/app/vlogs/new/page.tsx +++ b/app/vlogs/new/page.tsx @@ -1,4 +1,3 @@ -import { cookies } from "next/headers"; import { createClient } from "@/utils/supabase/server"; import { redirect } from "next/navigation"; import RecordVlog from "@/components/RecordVlog"; diff --git a/components/RecordVlog.tsx b/components/RecordVlog.tsx index 89f83fc..555c9ea 100644 --- a/components/RecordVlog.tsx +++ b/components/RecordVlog.tsx @@ -24,6 +24,7 @@ import { PiRecordBold } from "react-icons/pi"; import "@stream-io/video-react-sdk/dist/css/styles.css"; import Button from "./Button"; import { createClient } from "@/utils/supabase/client"; +import Config from "@/utils/config"; export default function RecordVideo({ userId, @@ -168,6 +169,47 @@ export const UILayout = ({ }) => { const { useCallCallingState } = useCallStateHooks(); const callingState: CallingState = useCallCallingState(); + const [timeLeft, setTimeLeft] = useState(Config.VIDEO_MAX_LENGTH); + const [timerRunning, setTimerRunning] = useState(false); + const call = useCall(); + + useEffect(() => { + if (timerRunning === false) { + return; + } + const interval = setInterval(() => { + setTimeLeft((prev) => prev - 1); + }, 1000); + + return () => clearInterval(interval); + }, [timerRunning]); + + useEffect(() => { + if (call) { + const handler = async () => { + console.log("in handler"); + setTimerRunning(true); + }; + call.on("call.recording_started", handler); + return () => { + call.off("call.recording_started", handler); + }; + } + }, [call]); + + useEffect(() => { + if (timeLeft <= 0) { + setTimerRunning(false); + const stopCall = async () => { + await onRecordingStopping(); + await call + ?.stopRecording() + .catch((e) => console.error(`Failed to stop`, e)); + }; + stopCall(); + } + }, [timeLeft]); + if ( callingState !== CallingState.JOINED && callingState !== CallingState.LEFT @@ -178,8 +220,12 @@ export const UILayout = ({ } return ( - + +
+ Video time remaining: {timeLeft} second + {timeLeft > 0 && "s"} +
{/* */}