-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathview-controller.tsx
More file actions
68 lines (62 loc) · 1.82 KB
/
Copy pathview-controller.tsx
File metadata and controls
68 lines (62 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use client';
import { useTheme } from 'next-themes';
import { AnimatePresence, motion } from 'motion/react';
import { useAgent, useSessionContext } from '@livekit/components-react';
import { AgentSessionView_01 } from '@/components/agents-ui/blocks/agent-session-view-01';
import { WelcomeView } from '@/components/app/welcome-view';
const MotionWelcomeView = motion.create(WelcomeView);
const MotionSessionView = motion.create(AgentSessionView_01);
const VIEW_MOTION_PROPS = {
variants: {
visible: {
opacity: 1,
},
hidden: {
opacity: 0,
},
},
initial: 'hidden',
animate: 'visible',
exit: 'hidden',
transition: {
duration: 0.5,
ease: 'linear',
},
};
interface ViewControllerProps {
isVideoInputSupported: boolean;
}
export function ViewController({ isVideoInputSupported }: ViewControllerProps) {
const { isConnected, start } = useSessionContext();
const agent = useAgent();
const { resolvedTheme } = useTheme();
return (
<AnimatePresence mode="wait">
{/* Welcome view */}
{!isConnected && (
<MotionWelcomeView
key="welcome"
{...VIEW_MOTION_PROPS}
startButtonText="Start call"
onStartCall={start}
/>
)}
{/* Session view */}
{isConnected && (
<MotionSessionView
key="session-view"
{...VIEW_MOTION_PROPS}
preConnectMessage={
agent.isConnected ? 'Agent is listening, ask it a question' : 'Waiting for agent'
}
supportsChatInput={true}
supportsVideoInput={isVideoInputSupported}
supportsScreenShare={isVideoInputSupported}
isPreConnectBufferEnabled={true}
themeMode={resolvedTheme === 'dark' ? 'dark' : 'light'}
className="fixed inset-0"
/>
)}
</AnimatePresence>
);
}