Skip to content

Commit

Permalink
add isMuted props to RoomAudioRenderer and AudioTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocupe committed Sep 28, 2023
1 parent 2b77ee5 commit 47a2660
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/react/src/components/RoomAudioRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { AudioTrack } from './participant/AudioTrack';
export interface RoomAudioRendererProps {
/** Sets the volume for all audio tracks rendered by this component. By default, the range is between `0.0` and `1.0`. */
volume?: number;
/** If set to true, mutes all audio tracks rendered by the component. */
isMuted?: boolean;
}

/**
Expand All @@ -22,7 +24,7 @@ export interface RoomAudioRendererProps {
* ```
* @public
*/
export function RoomAudioRenderer({ volume }: RoomAudioRendererProps) {
export function RoomAudioRenderer({ volume, isMuted }: RoomAudioRendererProps) {
const tracks = useTracks(
[Track.Source.Microphone, Track.Source.ScreenShareAudio, Track.Source.Unknown],
{
Expand All @@ -40,7 +42,12 @@ export function RoomAudioRenderer({ volume }: RoomAudioRendererProps) {
return (
<div style={{ display: 'none' }}>
{tracks.map((trackRef) => (
<AudioTrack key={getTrackReferenceId(trackRef)} trackRef={trackRef} volume={volume} />
<AudioTrack
key={getTrackReferenceId(trackRef)}
trackRef={trackRef}
volume={volume}
isMuted={isMuted}
/>
))}
</div>
);
Expand Down
11 changes: 10 additions & 1 deletion packages/react/src/components/participant/AudioTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export interface AudioTrackProps<T extends HTMLMediaElement = HTMLMediaElement>
onSubscriptionStatusChanged?: (subscribed: boolean) => void;
/** Sets the volume of the audio track. By default, the range is between `0.0` and `1.0`. */
volume?: number;
/**
* Mutes the audio track if set to `true`.
* @remarks
* Does not currently support the Web Audio API.
* A workaround is to set the volume to `0` instead.
* @alpha
*/
isMuted?: boolean;
}

/**
Expand All @@ -42,6 +50,7 @@ export function AudioTrack({
trackRef,
onSubscriptionStatusChanged,
volume,
isMuted,
source,
name,
publication,
Expand Down Expand Up @@ -84,5 +93,5 @@ export function AudioTrack({
}
}, [volume, track]);

return <audio ref={mediaEl} {...elementProps} />;
return <audio ref={mediaEl} muted={isMuted} {...elementProps} />;
}

0 comments on commit 47a2660

Please sign in to comment.