From 2d7d3f3d6d440a0666480125614986b9e2224609 Mon Sep 17 00:00:00 2001 From: mattherzog Date: Tue, 14 May 2024 18:20:22 -0600 Subject: [PATCH] Improves placeholder content for audio/video tiles when not connected (#57) --- src/components/playground/Playground.tsx | 103 +++++++++++++++-------- 1 file changed, 70 insertions(+), 33 deletions(-) diff --git a/src/components/playground/Playground.tsx b/src/components/playground/Playground.tsx index b015b3a..579a0a6 100644 --- a/src/components/playground/Playground.tsx +++ b/src/components/playground/Playground.tsx @@ -54,7 +54,7 @@ export default function Playground({ themeColors, onConnect, }: PlaygroundProps) { - const {config, setUserSettings} = useConfig(); + const { config, setUserSettings } = useConfig(); const { name } = useRoomInfo(); const [agentState, setAgentState] = useState("offline"); const [messages, setMessages] = useState([]); @@ -182,51 +182,88 @@ export default function Playground({ const videoTileContent = useMemo(() => { const videoFitClassName = `object-${config.video_fit || "cover"}`; + + const disconnectedContent = ( +
+ No video track. Connect to get started. +
+ ); + + const loadingContent = ( +
+ + Waiting for video track +
+ ); + + const videoContent = ( + + ); + + let content = null; + if (roomState === ConnectionState.Disconnected) { + content = disconnectedContent; + } else if (agentVideoTrack) { + content = videoContent; + } else { + content = loadingContent; + } + return (
- {agentVideoTrack ? ( - - ) : ( -
- - Waiting for video track -
- )} + {content}
); - }, [agentVideoTrack, config]); + }, [agentVideoTrack, config, roomState]); const audioTileContent = useMemo(() => { - return ( -
- {agentAudioTrack ? ( - - ) : ( -
- - Waiting for audio track -
- )} + const disconnectedContent = ( +
+ No audio track. Connect to get started.
); + + const waitingContent = ( +
+ + Waiting for audio track +
+ ); + + const visualizerContent = ( +
+ +
+ ); + + if (roomState === ConnectionState.Disconnected) { + return disconnectedContent; + } + + if (!agentAudioTrack) { + return waitingContent; + } + + return visualizerContent; }, [ agentAudioTrack, agentState, config.settings.theme_color, subscribedVolumes, + roomState, ]); const chatTileContent = useMemo(() => {