Skip to content

Commit

Permalink
Fix prejoin track lock release (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Apr 23, 2024
1 parent 8aa9567 commit 3babc69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-pugs-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/components-react": patch
---

Fix prejoin track lock release
37 changes: 22 additions & 15 deletions packages/react/src/prefabs/PreJoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,28 @@ export function usePreviewTracks(

React.useEffect(() => {
let needsCleanup = false;
trackLock.lock().then((unlock) => {
tracks?.forEach((track) => {
track.stop();
});
if (options.audio || options.video) {
createLocalTracks(options)
.then((tracks) => {
if (needsCleanup) {
tracks.forEach((tr) => tr.stop());
} else {
setTracks(tracks);
}
})
.catch((e) => (onError ? onError(e) : log.error(e)))
.finally(unlock);
trackLock.lock().then(async (unlock) => {
try {
tracks?.forEach((track) => {
track.stop();
});
if (options.audio || options.video) {
const localTracks = await createLocalTracks(options);

if (needsCleanup) {
localTracks.forEach((tr) => tr.stop());
} else {
setTracks(localTracks);
}
}
} catch (e: unknown) {
if (onError && e instanceof Error) {
onError(e);
} else {
log.error(e);
}
} finally {
unlock();
}
});

Expand Down

0 comments on commit 3babc69

Please sign in to comment.