@@ -200,8 +200,6 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
200200
201201 const config = props ;
202202
203- const micCleanUpFnRef = useRef < null | ( ( ) => void ) > ( null ) ;
204-
205203 const player = useSoundPlayer ( {
206204 onError : ( message ) => {
207205 updateError ( { type : 'audio_error' , message } ) ;
@@ -215,28 +213,6 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
215213 } ,
216214 } ) ;
217215
218- const handleResourceCleanup = useCallback ( ( ) => {
219- player . stopAll ( ) ;
220- if ( micCleanUpFnRef . current !== null ) {
221- micCleanUpFnRef . current ( ) ;
222- }
223- if ( clearMessagesOnDisconnect ) {
224- messageStore . clearMessages ( ) ;
225- }
226- toolStatus . clearStore ( ) ;
227- setIsPaused ( false ) ;
228-
229- if ( status . value !== 'error' ) {
230- setStatus ( { value : 'disconnected' } ) ;
231- }
232- } , [
233- player ,
234- clearMessagesOnDisconnect ,
235- messageStore ,
236- toolStatus ,
237- status . value ,
238- ] ) ;
239-
240216 const { streamRef, getStream, permission : micPermission } = useEncoding ( ) ;
241217
242218 const client = useVoiceClient ( {
@@ -281,10 +257,9 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
281257 ( event ) => {
282258 stopTimer ( ) ;
283259 messageStore . createDisconnectMessage ( event ) ;
284- handleResourceCleanup ( ) ;
285260 onClose . current ?.( event ) ;
286261 } ,
287- [ messageStore , stopTimer , handleResourceCleanup ] ,
262+ [ messageStore , stopTimer ] ,
288263 ) ,
289264 onToolCall : props . onToolCall ,
290265 } ) ;
@@ -320,10 +295,6 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
320295 ) ,
321296 } ) ;
322297
323- useEffect ( ( ) => {
324- micCleanUpFnRef . current = mic . stop ;
325- } , [ mic ] ) ;
326-
327298 const { clearQueue } = player ;
328299
329300 const pauseAssistant = useCallback ( ( ) => {
@@ -402,8 +373,21 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
402373 if ( client . readyState !== VoiceReadyState . CLOSED ) {
403374 client . disconnect ( ) ;
404375 }
405- handleResourceCleanup ( ) ;
406- } , [ client , handleResourceCleanup ] ) ;
376+ player . stopAll ( ) ;
377+ mic . stop ( ) ;
378+ if ( clearMessagesOnDisconnect ) {
379+ messageStore . clearMessages ( ) ;
380+ }
381+ toolStatus . clearStore ( ) ;
382+ setIsPaused ( false ) ;
383+ } , [
384+ client ,
385+ player ,
386+ mic ,
387+ clearMessagesOnDisconnect ,
388+ toolStatus ,
389+ messageStore ,
390+ ] ) ;
407391
408392 const disconnect = useCallback (
409393 ( disconnectOnError ?: boolean ) => {
0 commit comments