Skip to content

Commit

Permalink
Fix duplicated incoming audio when using AudioTrack renderer and its …
Browse files Browse the repository at this point in the history
…muted property (#855)
  • Loading branch information
lukasIO authored May 2, 2024
1 parent fd776c3 commit 99158d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-zebras-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Fix duplicated incoming audio when using AudioTrack renderer and its muted property
8 changes: 4 additions & 4 deletions packages/react/src/components/participant/AudioTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface AudioTrackProps extends React.AudioHTMLAttributes<HTMLAudioElem
*/
export const AudioTrack = /* @__PURE__ */ React.forwardRef<HTMLAudioElement, AudioTrackProps>(
function AudioTrack(
{ trackRef, onSubscriptionStatusChanged, volume, ...props }: AudioTrackProps,
{ trackRef, onSubscriptionStatusChanged, volume, muted, ...props }: AudioTrackProps,
ref,
) {
const trackReference = useEnsureTrackRef(trackRef);
Expand Down Expand Up @@ -72,15 +72,15 @@ export const AudioTrack = /* @__PURE__ */ React.forwardRef<HTMLAudioElement, Aud
}, [volume, track]);

React.useEffect(() => {
if (pub === undefined || props.muted === undefined) {
if (pub === undefined || muted === undefined) {
return;
}
if (pub instanceof RemoteTrackPublication) {
pub.setEnabled(!props.muted);
pub.setEnabled(!muted);
} else {
log.warn('Can only call setEnabled on remote track publications.');
}
}, [props.muted, pub, track]);
}, [muted, pub, track]);

return <audio ref={mediaEl} {...elementProps} />;
},
Expand Down

0 comments on commit 99158d5

Please sign in to comment.