generated from cameronking4/VapiBlocks
-
Notifications
You must be signed in to change notification settings - Fork 8
/
floaty.tsx
81 lines (75 loc) · 2.92 KB
/
floaty.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
import { PhoneCallIcon, MicIcon, AudioLines} from 'lucide-react';
import React, { useState } from 'react';
import { motion } from 'framer-motion';
import useWebRTCAudioSession from '@/hooks/use-webrtc'; // Replace useVapi import
const FloatingCircle = ({ isActive, volumeLevel, handleClick }: { isActive: boolean, volumeLevel: number, handleClick: () => void }) => {
const getIcon = () => {
if (!isActive) {
return <PhoneCallIcon className="text-secondary" />;
} else if (isActive && volumeLevel > 0) {
return <AudioLines className="text-secondary" />;
} else {
return <MicIcon className="text-secondary" />;
}
};
return (
<div className="fixed bottom-5 right-5 z-50">
<div className="relative flex items-center justify-center w-16 h-16">
{isActive && volumeLevel > 0 && (
<>
<motion.div
className="absolute w-16 h-16 rounded-full bg-foreground z-0"
initial={{ scale: 1, opacity: 0.5 }}
animate={{ scale: 2, opacity: 0 }}
transition={{ duration: 1.5, repeat: Infinity, repeatDelay: 0.5 }}
/>
<motion.div
className="absolute w-16 h-16 rounded-full bg-foreground z-0"
initial={{ scale: 1, opacity: 0.5 }}
animate={{ scale: 2, opacity: 0 }}
transition={{ duration: 1.5, repeat: Infinity, repeatDelay: 1 }}
/>
<motion.div
className="absolute w-16 h-16 rounded-full bg-foreground z-0"
initial={{ scale: 1, opacity: 0.5 }}
animate={{ scale: 2, opacity: 0 }}
transition={{ duration: 1.5, repeat: Infinity, repeatDelay: 1.5 }}
/>
</>
)}
<div
className="relative flex items-center justify-center w-16 h-16 rounded-full shadow-xl cursor-pointer z-10 bg-foreground"
onClick={handleClick}
>
{getIcon()}
</div>
</div>
</div>
);
};
const FloatyExample = () => {
const [showCircle, setShowCircle] = useState(false);
const { currentVolume, isSessionActive, handleStartStopClick } = useWebRTCAudioSession('alloy'); // Replace useVapi hook
const handleButtonClick = () => {
setShowCircle(!showCircle);
};
return (
<div className="flex flex-col items-center justify-center min-h-full gap-4">
<button
onClick={handleButtonClick}
className="px-4 py-2 rounded-lg text-sm shadow-md focus:outline-none border hover:bg-primary-dark transition-colors duration-200 ease-in-out"
>
Toggle Floaty
</button>
<p className="text-sm text-muted-foreground">Click to toggle floaty in bottom right corner of the screen.</p>
{showCircle && (
<FloatingCircle
isActive={isSessionActive}
volumeLevel={currentVolume}
handleClick={handleStartStopClick}
/>
)}
</div>
);
}
export default FloatyExample;