generated from cameronking4/VapiBlocks
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathring.tsx
121 lines (112 loc) · 3.73 KB
/
ring.tsx
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, { useEffect, useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import useWebRTCAudioSession from '@/hooks/use-webrtc';
import { Button } from '@/components/ui/button';
import { MicIcon, PhoneOff } from 'lucide-react';
const Visualizer: React.FC = () => {
const { currentVolume, isSessionActive, handleStartStopClick } = useWebRTCAudioSession('alloy');
const [waveData, setWaveData] = useState(Array(100).fill(0));
useEffect(() => {
if (isSessionActive) {
updateWave(currentVolume);
} else {
resetWave();
}
}, [currentVolume, isSessionActive]);
const updateWave = (volume: number) => {
setWaveData(
waveData.map(() => Math.sin(Math.random() * Math.PI * 2) * volume * 30 + 30)
);
};
const resetWave = () => {
setWaveData(Array(100).fill(30));
};
const generateGradient = () => {
const gradientId = `gradient-${Math.random().toString(36).substr(2, 9)}`;
return (
<defs>
<radialGradient id={gradientId} cx="50%" cy="50%" r="50%">
<stop offset="0%" stopColor="#6ea8fe" />
<stop offset="100%" stopColor="#1a73e8" />
</radialGradient>
</defs>
);
};
return (
<div className="flex flex-col items-center justify-center w-full h-full p-6">
<AnimatePresence>
{isSessionActive && (
<motion.div
className="relative w-64 h-64 flex items-center justify-center"
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.8 }}
transition={{ duration: 0.5 }}
>
<motion.svg
width="100%"
height="100%"
viewBox="0 0 200 200"
animate={{ rotate: 360 }}
transition={{
duration: 20,
repeat: Infinity,
ease: "linear"
}}
>
{generateGradient()}
<circle cx="100" cy="100" r="50" fill="url(#gradient)" />
{waveData.map((radius, index) => {
const angle = (index / waveData.length) * 360;
const radians = (angle * Math.PI) / 180;
const x = 100 + Math.cos(radians) * radius;
const y = 100 + Math.sin(radians) * radius;
return (
<circle
key={index}
cx={x}
cy={y}
r="1"
fill="#ffffff"
opacity="0.8"
/>
);
})}
</motion.svg>
</motion.div>
)}
</AnimatePresence>
<motion.div className="mt-4">
<Button
onClick={handleStartStopClick}
className="flex items-center justify-center w-12 h-12 rounded-full shadow-lg"
>
<AnimatePresence>
{isSessionActive ? (
<motion.div
key="phone-off"
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.8 }}
transition={{ duration: 0.3 }}
>
<PhoneOff size={24} />
</motion.div>
) : (
<motion.div
key="mic-icon"
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.8 }}
transition={{ duration: 0.3 }}
>
<MicIcon size={24} />
</motion.div>
)}
</AnimatePresence>
</Button>
</motion.div>
</div>
);
};
export default Visualizer;