Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

♻️(frontend) refactor preview track to avoid unnecessary resets

lebaudantoinee926b407b117
diff --git a/src/frontend/src/features/rooms/components/Join.tsx b/src/frontend/src/features/rooms/components/Join.tsx
index 3258bb85..b3b32a26 100644
--- a/src/frontend/src/features/rooms/components/Join.tsx
+++ b/src/frontend/src/features/rooms/components/Join.tsx
@@ -32,6 +32,7 @@ import { ToggleDevice } from './join/ToggleDevice'
import { SelectDevice } from './join/SelectDevice'
import { useResolveDefaultDeviceId } from '../livekit/hooks/useResolveDefaultDevice'
import { isSafari } from '@/utils/livekit'
+import type { LocalUserChoices } from '@/stores/userChoices'
const onError = (e: Error) => console.error('ERROR', e)
@@ -116,11 +117,27 @@ export const Join = ({
saveProcessorSerialized,
} = usePersistentUserChoices()
+ const initialUserChoices = useRef<LocalUserChoices | null>(null)
+
+ if (initialUserChoices.current === null) {
+ initialUserChoices.current = {
+ audioEnabled,
+ videoEnabled,
+ audioDeviceId,
+ audioOutputDeviceId,
+ videoDeviceId,
+ processorSerialized,
+ username,
+ }
+ }
+
const tracks = usePreviewTracks(
{
- audio: { deviceId: audioDeviceId },
- video: {
- deviceId: videoDeviceId,
+ audio: !!initialUserChoices.current && {
+ deviceId: initialUserChoices.current.audioDeviceId,
+ },
+ video: !!initialUserChoices.current && {
+ deviceId: initialUserChoices.current.videoDeviceId,
processor:
BackgroundProcessorFactory.deserializeProcessor(processorSerialized),
},
@@ -599,7 +616,16 @@ export const Join = ({
<SelectDevice
kind="audioinput"
id={audioDeviceId}
- onSubmit={saveAudioInputDeviceId}
+ onSubmit={async (id) => {
+ try {
+ saveAudioInputDeviceId(id)
+ if (audioTrack) {
+ await audioTrack.setDeviceId({ exact: id })
+ }
+ } catch (err) {
+ console.error('Failed to switch microphone device', err)
+ }
+ }}
/>
</div>
{!isSafari() && (
@@ -623,7 +649,16 @@ export const Join = ({
<SelectDevice
kind="videoinput"
id={videoDeviceId}
- onSubmit={saveVideoInputDeviceId}
+ onSubmit={async (id) => {
+ try {
+ saveVideoInputDeviceId(id)
+ if (videoTrack) {
+ await await videoTrack.setDeviceId({ exact: id })
+ }
+ } catch (err) {
+ console.error('Failed to switch camera device', err)
+ }
+ }}
/>
</div>
</div>