Skip to content

Commit

Permalink
Fix releasing of local tracks in prejoin (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Apr 25, 2024
1 parent 958dba5 commit b8d9ea5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-actors-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Fix releasing of local tracks in prejoin
10 changes: 4 additions & 6 deletions packages/react/src/prefabs/PreJoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ export function usePreviewTracks(

React.useEffect(() => {
let needsCleanup = false;
let localTracks: Array<LocalTrack> = [];
trackLock.lock().then(async (unlock) => {
try {
tracks?.forEach((track) => {
track.stop();
});
if (options.audio || options.video) {
const localTracks = await createLocalTracks(options);
localTracks = await createLocalTracks(options);

if (needsCleanup) {
localTracks.forEach((tr) => tr.stop());
Expand All @@ -90,11 +88,11 @@ export function usePreviewTracks(

return () => {
needsCleanup = true;
tracks?.forEach((track) => {
localTracks.forEach((track) => {
track.stop();
});
};
}, [JSON.stringify(options)]);
}, [JSON.stringify(options), onError, trackLock]);

return tracks;
}
Expand Down

0 comments on commit b8d9ea5

Please sign in to comment.