Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add preview mic volume indication #204

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/components/volume/MicVolume.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import LinearProgress from '@mui/material/LinearProgress';
import { useContext, useEffect, useState } from 'react';
import { ServiceContext } from '../../store/store';
import { VolumeWatcher } from '../../utils/volumeWatcher';
import hark from 'hark';

const MicVolume = (): JSX.Element => {
const { mediaService } = useContext(ServiceContext);
const [ volumeLevel, setVolume ] = useState<number>(0);

useEffect(() => {
let volumeWatcher: VolumeWatcher | undefined;

// Add hark for mic
if (mediaService.previewMicTrack) {
const harkStream = new MediaStream();

harkStream.addTrack(mediaService.previewMicTrack.clone());

const micHark = hark(harkStream, {
play: false,
interval: 100,
threshold: -60,
history: 100
});

volumeWatcher = new VolumeWatcher({ hark: micHark });
}

const onVolumeChange = ({ scaledVolume }: { scaledVolume: number }): void => {
setVolume(scaledVolume*10); // Range: 0-100
};

volumeWatcher?.on('volumeChange', onVolumeChange);

return () => {
volumeWatcher?.off('volumeChange', onVolumeChange);
};
}, [ mediaService.previewMicTrack ]);

return (
<LinearProgress color='success' variant="determinate" value={volumeLevel} />
);
};

export default MicVolume;
2 changes: 2 additions & 0 deletions src/views/join/Join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import AudioOutputChooser from '../../components/devicechooser/AudioOutputChoose
import { canSelectAudioOutput } from '../../store/selectors';
import TestAudioOutputButton from '../../components/audiooutputtest/AudioOutputTest';
import ImpressumButton from '../../components/controlbuttons/ImpressumButton';
import MicVolume from '../../components/volume/MicVolume';

interface JoinProps {
roomId: string;
Expand Down Expand Up @@ -70,6 +71,7 @@ const Join = ({ roomId }: JoinProps): React.JSX.Element => {
<AudioInputChooser />
{ showAudioOutputChooser && <AudioOutputChooser /> }
<VideoInputChooser />
<MicVolume />
<TestAudioOutputButton />
<BlurSwitch />
<ChooserDiv>
Expand Down
Loading