Skip to content

Commit

Permalink
Don't auto subscribe to all audio tracks automatically in RoomAudioRe…
Browse files Browse the repository at this point in the history
…nderer (#847)
  • Loading branch information
lukasIO authored Apr 25, 2024
1 parent b8d9ea5 commit 315a9aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-moose-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": minor
---

Don't auto subscribe to all audio tracks automatically in RoomAudioRenderer
9 changes: 1 addition & 8 deletions packages/react/src/components/RoomAudioRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getTrackReferenceId, isLocal } from '@livekit/components-core';
import type { RemoteTrackPublication } from 'livekit-client';
import { Track } from 'livekit-client';
import * as React from 'react';
import { useTracks } from '../hooks';
Expand Down Expand Up @@ -35,16 +34,10 @@ export function RoomAudioRenderer({ volume, muted }: RoomAudioRendererProps) {
[Track.Source.Microphone, Track.Source.ScreenShareAudio, Track.Source.Unknown],
{
updateOnlyOn: [],
onlySubscribed: false,
onlySubscribed: true,
},
).filter((ref) => !isLocal(ref.participant) && ref.publication.kind === Track.Kind.Audio);

React.useEffect(() => {
for (const track of tracks) {
(track.publication as RemoteTrackPublication).setSubscribed(true);
}
}, [tracks]);

return (
<div style={{ display: 'none' }}>
{tracks.map((trackRef) => (
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/hooks/useTracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export function useTracks<T extends SourcesArray = Track.Source[]>(
setParticipants(participants);
});
return () => subscription.unsubscribe();
}, [room, JSON.stringify(options.updateOnlyOn), JSON.stringify(sources)]);
}, [
room,
JSON.stringify(options.onlySubscribed),
JSON.stringify(options.updateOnlyOn),
JSON.stringify(sources),
]);

const maybeTrackReferences = React.useMemo(() => {
if (isSourcesWithOptions(sources)) {
Expand Down

0 comments on commit 315a9aa

Please sign in to comment.