diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index d13cfbd..1af9141 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -12,6 +12,7 @@ import { import { useCallback, useState } from "react"; import { MediaDeviceFailure } from "livekit-client"; import type { ConnectionDetails } from "./api/connection-details/route"; +import { NoAgentNotification } from "@/components/NoAgentNotification"; export default function Page() { const [connectionDetails, updateConnectionDetails] = useState< @@ -67,6 +68,17 @@ function SimpleVoiceAssistant() { return (
+

{state}

+ +

No agent

+

+ No agent has joined the room yet. Please ensure you've followed + the setup instructions and started your agent on your machine.{" "} + + Learn more + +

+
); } diff --git a/frontend/components/NoAgentNotification.tsx b/frontend/components/NoAgentNotification.tsx new file mode 100644 index 0000000..f94e9f7 --- /dev/null +++ b/frontend/components/NoAgentNotification.tsx @@ -0,0 +1,44 @@ +import type { VoiceAssistantState } from "@livekit/components-react"; +import React from "react"; +interface NoAgentNotificationProps extends React.PropsWithChildren { + state: VoiceAssistantState; +} + +/** + * Renders some user info when no agent connects to the room after a certain time. + */ +export function NoAgentNotification(props: NoAgentNotificationProps) { + const timeToWaitMs = 6000; + const timeoutRef = React.useRef(null); + const [showNotification, setShowNotification] = React.useState(false); + + React.useEffect(() => { + if (props.state === "connecting") { + timeoutRef.current = window.setTimeout(() => { + if (props.state === "connecting") { + setShowNotification(true); + } + }, timeToWaitMs); + } else { + setShowNotification(false); + } + + return () => { + if (timeoutRef.current) { + window.clearTimeout(timeoutRef.current); + } + }; + }, [props.state]); + + React.useEffect(() => {}, [props.state]); + + return ( + <> + {showNotification ? ( +
+ {props.children} +
+ ) : null} + + ); +}