Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

✨(frontend) add hook to manage noise reduction processor toggling

lebaudantoine1fe1a557adf9
diff --git a/src/frontend/src/features/rooms/livekit/hooks/useNoiseReduction.ts b/src/frontend/src/features/rooms/livekit/hooks/useNoiseReduction.ts
new file mode 100644
index 00000000..9d257805
--- /dev/null
+++ b/src/frontend/src/features/rooms/livekit/hooks/useNoiseReduction.ts
@@ -0,0 +1,30 @@
+import { useEffect } from 'react'
+import { Track } from 'livekit-client'
+import { useRoomContext } from '@livekit/components-react'
+import { RnnNoiseProcessor } from '../processors/RnnNoiseProcessor'
+import { usePersistentUserChoices } from './usePersistentUserChoices'
+
+export const useNoiseReduction = () => {
+ const room = useRoomContext()
+
+ const {
+ userChoices: { noiseReductionEnabled },
+ } = usePersistentUserChoices()
+
+ const audioTrack = room.localParticipant.getTrackPublication(
+ Track.Source.Microphone
+ )?.audioTrack
+
+ useEffect(() => {
+ if (!audioTrack) return
+
+ const processor = audioTrack?.getProcessor()
+
+ if (noiseReductionEnabled && !processor) {
+ const rnnNoiseProcessor = new RnnNoiseProcessor()
+ audioTrack.setProcessor(rnnNoiseProcessor)
+ } else if (!noiseReductionEnabled && processor) {
+ audioTrack.stopProcessor()
+ }
+ }, [audioTrack, noiseReductionEnabled])
+}
diff --git a/src/frontend/src/features/rooms/livekit/prefabs/VideoConference.tsx b/src/frontend/src/features/rooms/livekit/prefabs/VideoConference.tsx
index 4944ac7f..96d6b74a 100644
--- a/src/frontend/src/features/rooms/livekit/prefabs/VideoConference.tsx
+++ b/src/frontend/src/features/rooms/livekit/prefabs/VideoConference.tsx
@@ -31,6 +31,7 @@ import { useSidePanel } from '../hooks/useSidePanel'
import { RecordingStateToast } from '@/features/recording'
import { ScreenShareErrorModal } from '../components/ScreenShareErrorModal'
import { useConnectionObserver } from '../hooks/useConnectionObserver'
+import { useNoiseReduction } from '../hooks/useNoiseReduction'
const LayoutWrapper = styled(
'div',
@@ -87,6 +88,8 @@ export function VideoConference({ ...props }: VideoConferenceProps) {
const layoutContext = useCreateLayoutContext()
+ useNoiseReduction()
+
const screenShareTracks = tracks
.filter(isTrackReference)
.filter((track) => track.publication.source === Track.Source.ScreenShare)