Skip to content

Commit

Permalink
move volume indicator into the join dialog video box + remove outside…
Browse files Browse the repository at this point in the history
… volume component
  • Loading branch information
N7Remus committed Jan 8, 2025
1 parent 3cc418e commit 71ddd76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/components/mediapreview/MediaPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MediaControls from '../mediacontrols/MediaControls';
import VideoBox from '../videobox/VideoBox';
import VideoView from '../videoview/VideoView';
import { stopPreviewMic, stopPreviewWebcam, updatePreviewMic, updatePreviewWebcam } from '../../store/actions/mediaActions';
import Volume from '../volume/Volume';

interface MediaPreviewProps {
withControls?: boolean;
Expand All @@ -32,6 +33,8 @@ const MediaPreview = ({
const audioDevice = useAppSelector((state) => state.settings.selectedAudioDevice);
const videoDevice = useAppSelector((state) => state.settings.selectedVideoDevice);
const contain = useAppSelector((state) => state.settings.videoContainEnabled);
// We do not send it so the state is different on join dialog.
const micEnabled = useAppSelector((state) => state.me.previewMicTrackId);

useEffect(() => {
if (startAudio) dispatch(updatePreviewMic({ newDeviceId: audioDevice, updateSelection }));
Expand Down Expand Up @@ -67,9 +70,12 @@ const MediaPreview = ({
offColor='error'
disabledColor='default'
/>

</MediaControls>
)}
{ previewWebcamTrackId && <VideoView contain={contain} mirrored previewTrack /> }
{ micEnabled && <Volume /> }

</VideoBox>
</>
);
Expand Down
20 changes: 18 additions & 2 deletions src/components/volume/Volume.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StateConsumer } from '../../store/slices/consumersSlice';
import { ServiceContext } from '../../store/store';
import { VolumeWatcher } from '../../utils/volumeWatcher';
import type { Consumer as PeerConsumer } from 'ortc-p2p/src/types';
import hark from 'hark';

type VolumeBarProps = {
small: number;
Expand Down Expand Up @@ -53,8 +54,23 @@ const Volume = ({

if (consumer)
media = mediaService.getConsumer(consumer.id);
else
else if (mediaService.mediaSenders['mic'].volumeWatcher)
volumeWatcher = mediaService.mediaSenders['mic'].volumeWatcher;
else if (mediaService.previewMicTrack) {
// We do not send it so the state is different on join dialog.
const harkStream = new MediaStream();

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

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

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

if (media)
volumeWatcher = media.appData.volumeWatcher as VolumeWatcher | undefined;
Expand All @@ -68,7 +84,7 @@ const Volume = ({
return () => {
volumeWatcher?.off('volumeChange', onVolumeChange);
};
}, [ consumer ]);
}, [ consumer, mediaService.previewMicTrack ]);

// Props workaround for: https://github.com/mui/material-ui/issues/25925
return (
Expand Down
4 changes: 1 addition & 3 deletions src/views/join/Join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { meActions } from '../../store/slices/meSlice';
import AudioOutputChooser from '../../components/devicechooser/AudioOutputChooser';
import { canSelectAudioOutput } from '../../store/selectors';
import edumeetConfig from '../../utils/edumeetConfig';
import MicVolume from '../../components/volume/MicVolume';

interface JoinProps {
roomId: string;
Expand Down Expand Up @@ -73,8 +72,7 @@ const Join = ({ roomId }: JoinProps): React.JSX.Element => {
<AudioInputChooser />
{ showAudioOutputChooser && <AudioOutputChooser /> }
<VideoInputChooser />
<MicVolume />


<ChooserDiv>
<TextInputField
label={yourNameLabel()}
Expand Down

0 comments on commit 71ddd76

Please sign in to comment.