Skip to content

Commit

Permalink
Merge pull request #104 from cloudflare/remove-noise-suppression-from…
Browse files Browse the repository at this point in the history
…-muted-track

Remove noise suppression from muted track
  • Loading branch information
third774 authored Sep 6, 2024
2 parents f7c37e3 + 7ddc7bb commit 53fc12e
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions app/hooks/useUserMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,27 @@ export default function useUserMedia(mode: Mode) {
)
}, [suppressNoiseEnabled$])
const mutedAudioTrack$ = useMemo(() => {
return combineLatest([
getUserMediaTrack$('audioinput').pipe(
tap({
next: (track) => {
track.enabled = false
},
error: (e) => {
invariant(e instanceof Error)
setAudioUnavailableReason(
e.name in errorMessageMap
? (e.name as UserMediaError)
: 'UnknownError'
)
},
})
),
suppressNoiseEnabled$,
]).pipe(
switchMap(([track, suppressNoise]) =>
of(suppressNoise && track ? noiseSuppression(track) : track)
),
return getUserMediaTrack$('audioinput').pipe(
tap({
next: (track) => {
track.enabled = false
},
error: (e) => {
invariant(e instanceof Error)
setAudioUnavailableReason(
e.name in errorMessageMap
? (e.name as UserMediaError)
: 'UnknownError'
)
},
}),
shareReplay({
refCount: true,
bufferSize: 1,
})
)
}, [suppressNoiseEnabled$])
}, [])

const alwaysOnAudioStreamTrack = useSubscribedState(audioTrack$)
const audioDeviceId = alwaysOnAudioStreamTrack?.getSettings().deviceId
const audioEnabled$ = useStateObservable(audioEnabled)
Expand Down

0 comments on commit 53fc12e

Please sign in to comment.