fix(react): forward track to setupDeviceSelector in useMediaDeviceSelect#1330
Open
nikhilgupta58 wants to merge 2 commits into
Open
fix(react): forward track to setupDeviceSelector in useMediaDeviceSelect#1330nikhilgupta58 wants to merge 2 commits into
nikhilgupta58 wants to merge 2 commits into
Conversation
Add a deterministic test that renders useMediaDeviceSelect in preview mode (no connected room) with a local preview track and asserts that setActiveMediaDevice forwards the switch to the track. This fails on the current code because the track is never passed to setupDeviceSelector. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ect (closes livekit#1315) useMediaDeviceSelect listed track in the useMemo deps but called setupDeviceSelector(kind, roomFallback) with only two arguments. Without the localTrack, setupDeviceSelector falls back to room.switchActiveDevice, which no-ops on the dummy Room used in preview / pre-join mode. As a result setActiveMediaDevice silently failed to switch the mic or camera before joining a room. Pass the already-tracked track as the third argument so the preview track's setDeviceId is used in preview mode. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: bb622ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@nikhilgupta58 is attempting to deploy a commit to the LiveKit Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1315
Root cause
useMediaDeviceSelectkeepstrackin itsuseMemodependency array but never forwards it tosetupDeviceSelector.packages/react/src/hooks/useMediaDeviceSelect.ts(line 62-65):packages/core/src/components/mediaDeviceSelect.tsdefines a 3-arg signature and branches on the track:In pre-join / preview UIs there is no connected room, so
roomFallbackis a dummynew Room(). BecauselocalTrackisundefined,setActiveMediaDevicetakes theroom.switchActiveDevicebranch, which does nothing on that dummy room. The result is thatsetActiveMediaDevicesilently fails to switch the mic or camera before joining.The fix
trackis already in theuseMemodeps, so no dependency-array change is needed. This is purely additive forwarding of an already-tracked value.Proof (verify-first)
I reproduced the bug with a deterministic test BEFORE writing the fix.
The test renders
useMediaDeviceSelect({ kind: 'audioinput', track })in preview mode (no room, no RoomContext, soroomFallbackis a freshnew Room()) with a spytrack.setDeviceId, callssetActiveMediaDevice('mic-2'), and asserts the track was switched. It keeps the realsetupDeviceSelector(only the device enumeration and logging are mocked so jsdom does not touchnavigator.mediaDevices).RED on current code (
packages/react):GREEN after the fix:
Full suites stay green:
packages/react8 passed,packages/core98 passed.pnpm build(all packages), lint, and format check are clean.Risk
None expected. The change only forwards a value that was already a memo dependency, and the preview-track code path in
setupDeviceSelectoralready existed and was simply unreachable from this hook.Out of scope
While testing I noticed a separate UI-feedback quirk:
setupDeviceSelectorupdates an internalactiveDeviceSubjectbut returns the room-event-basedactiveDeviceObservable, so the active-item highlight does not reflect a preview-mode switch even after this fix. That is a distinct issue from #1315 (which is about the switch itself not happening) and is not addressed here.