Skip to content

Commit 6436a7d

Browse files
committed
fix options stringify crash
1 parent 9e055f0 commit 6436a7d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/react/src/prefabs/PreJoin.tsx

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
LocalAudioTrack,
44
LocalTrack,
55
LocalVideoTrack,
6+
VideoResolution,
67
} from 'livekit-client';
78
import {
89
createLocalAudioTrack,
@@ -52,6 +53,19 @@ export interface PreJoinProps
5253
persistUserChoices?: boolean;
5354
}
5455

56+
const makeComparableOptions = (options: CreateLocalTracksOptions) => {
57+
return {
58+
video:
59+
typeof options.video === 'object'
60+
? { ...options.video, processor: options.video.processor?.name }
61+
: options.video,
62+
audio:
63+
typeof options.audio === 'object'
64+
? { ...options.audio, processor: options.audio.processor?.name }
65+
: options.audio,
66+
};
67+
};
68+
5569
/** @alpha */
5670
export function usePreviewTracks(
5771
options: CreateLocalTracksOptions,
@@ -87,13 +101,16 @@ export function usePreviewTracks(
87101
});
88102

89103
return () => {
104+
// In case this is triggered while awaiting for `createLocalTracks`,
105+
// this makes sure, we will stop the tracks after the creation await.
106+
// (yes needsCleanup is passed into this closure by ref and is the same ref as in the
107+
// lock.then closure)
90108
needsCleanup = true;
91109
localTracks.forEach((track) => {
92110
track.stop();
93111
});
94112
};
95-
}, [JSON.stringify(options), onError, trackLock]);
96-
113+
}, [trackLock, makeComparableOptions(options)]);
97114
return tracks;
98115
}
99116

0 commit comments

Comments
 (0)