Skip to content

Commit

Permalink
Clean up analyser node on unmount of useLocalAudioInputActivity hook
Browse files Browse the repository at this point in the history
  • Loading branch information
michhyun1 committed Jan 4, 2024
1 parent 1ebd21b commit a30c6af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Remove analyser node on unmount of useLocalAudioInputActivity hook

## [3.7.0] - 2023-04-25

### Added
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/sdk/useLocalAudioInputActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect } from 'react';

import { useAudioVideo } from '../../providers/AudioVideoProvider';
import { useAudioInputs } from '../../providers/DevicesProvider';
import { RemovableAnalyserNode } from 'amazon-chime-sdk-js';

export const useLocalAudioInputActivity = (cb: (decimal: number) => void) => {
const audioVideo = useAudioVideo();
Expand All @@ -15,7 +16,7 @@ export const useLocalAudioInputActivity = (cb: (decimal: number) => void) => {
return;
}

let analyserNode: AnalyserNode | null;
let analyserNode: RemovableAnalyserNode | null;
let restart = false;
let data: Uint8Array;
let frameIndex: number;
Expand Down Expand Up @@ -80,6 +81,7 @@ export const useLocalAudioInputActivity = (cb: (decimal: number) => void) => {

return () => {
isMounted = false;
analyserNode?.removeOriginalInputs();
};
}, [audioVideo, selectedDevice, cb]);
};
Expand Down

0 comments on commit a30c6af

Please sign in to comment.