11'use client'
22
3- import { memo , type RefObject , useEffect , useRef } from 'react'
3+ import { memo , useEffect , useRef } from 'react'
44import { Button , cn , Tooltip , usePrefersReducedMotion } from '@sim/emcn'
55import { Mic } from '@sim/emcn/icons'
66
@@ -12,16 +12,16 @@ const WAVEFORM_EASING = 0.24
1212
1313interface MicButtonProps {
1414 isListening : boolean
15- audioLevelsRef : RefObject < Float32Array | null >
15+ audioLevels : Float32Array
1616 onToggle : ( ) => void
1717}
1818
1919interface VoiceWaveformProps {
20- audioLevelsRef : RefObject < Float32Array | null >
20+ audioLevels : Float32Array
2121 isListening : boolean
2222}
2323
24- function VoiceWaveform ( { audioLevelsRef , isListening } : VoiceWaveformProps ) {
24+ function VoiceWaveform ( { audioLevels , isListening } : VoiceWaveformProps ) {
2525 const prefersReducedMotion = usePrefersReducedMotion ( )
2626 const barRefs = useRef < Array < SVGLineElement | null > > ( [ ] )
2727
@@ -32,10 +32,8 @@ function VoiceWaveform({ audioLevelsRef, isListening }: VoiceWaveformProps) {
3232 let animationFrameId = 0
3333
3434 const draw = ( ) => {
35- const levels = audioLevelsRef . current
36-
3735 for ( let index = 0 ; index < WAVEFORM_BAR_COUNT ; index ++ ) {
38- const level = levels ?. [ index ] ?? 0
36+ const level = audioLevels [ index ] ?? 0
3937 const targetHeight =
4038 WAVEFORM_MIN_HEIGHT +
4139 Math . sqrt ( Math . max ( 0 , level ) ) * ( WAVEFORM_MAX_HEIGHT - WAVEFORM_MIN_HEIGHT )
@@ -53,7 +51,7 @@ function VoiceWaveform({ audioLevelsRef, isListening }: VoiceWaveformProps) {
5351
5452 animationFrameId = window . requestAnimationFrame ( draw )
5553 return ( ) => window . cancelAnimationFrame ( animationFrameId )
56- } , [ audioLevelsRef , isListening , prefersReducedMotion ] )
54+ } , [ audioLevels , isListening , prefersReducedMotion ] )
5755
5856 return (
5957 < svg aria-hidden viewBox = '0 0 18 18' className = 'size-[18px] overflow-hidden' >
@@ -81,7 +79,7 @@ function VoiceWaveform({ audioLevelsRef, isListening }: VoiceWaveformProps) {
8179
8280export const MicButton = memo ( function MicButton ( {
8381 isListening,
84- audioLevelsRef ,
82+ audioLevels ,
8583 onToggle,
8684} : MicButtonProps ) {
8785 return (
@@ -105,7 +103,7 @@ export const MicButton = memo(function MicButton({
105103 isListening ? 'scale-100 opacity-100 blur-none' : 'scale-[0.25] opacity-0 blur-[4px]'
106104 ) }
107105 >
108- < VoiceWaveform audioLevelsRef = { audioLevelsRef } isListening = { isListening } />
106+ < VoiceWaveform audioLevels = { audioLevels } isListening = { isListening } />
109107 </ span >
110108 < Mic
111109 strokeWidth = '1.25'
0 commit comments