components-js icon indicating copy to clipboard operation
components-js copied to clipboard

MediaDeviceMenu ignoring initialSelection prop

Open mallison opened this issue 9 months ago • 0 comments

Select which package(s) are affected

@livekit/components-react

Describe the bug

What I'm expecting

If I do

<MediaDeviceMenu
  initialSelection={initialVideoDeviceId}
  onActiveDeviceChange={(...args) => console.log("device changed", args)}
  kind="videoinput"
/>

where initialVideoDeviceId is a long device id string.

I don't expect onActiveDeviceChange to fire when the component mounts.

If I open the menu and select the current device I don't expect onActiveDeviceChange to fire.

What happens

onActiveDeviceChange does fire and I see the following in the console.

device changed (2) ['videoinput', 'default']

The deviceId has been initialised to default regardless of the initialSelection passed in.

If I then click on the same device in the menu, onActiveDeviceChange fires again and I see

device changed (2) ['videoinput', '9383a83153e373d05baba1aab7ab47631afbebf1520412ca5b2359f4ac18f27b']

logged.

Reproduction

I've created a small CodeSandox to show the issue https://codesandbox.io/p/sandbox/2y6qfq

Logs

device changed (2) ['videoinput', 'default']
device changed (2) ['videoinput', 'default']
room event activeDeviceChanged {room: '', roomID: , participant: '', pID: '', event: 'activeDeviceChanged', …}args: Array(2)0: "videoinput"1: "414b1d88945790d6941cd3ef3a5eaed05969afa26bac622d502677d5d645beaa"length: 2[[Prototype]]: Array(0)event: "activeDeviceChanged"pID: ""participant: ""room: ""roomID: undefined[[Prototype]]: Object
device changed (2) ['videoinput', '414b1d88945790d6941cd3ef3a5eaed05969afa26bac622d502677d5d645beaa']

System Info

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 89.67 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.1 - ~/.nvm/versions/node/v20.8.1/bin/node
    Yarn: 4.5.0 - /usr/local/bin/yarn
    npm: 10.1.0 - ~/.nvm/versions/node/v20.8.1/bin/npm
  Browsers:
    Brave Browser: 134.1.76.82
    Chrome: 135.0.7049.85
    Safari: 18.2

Severity

serious, but I can work around it

Additional Information

No response

mallison avatar Apr 11 '25 16:04 mallison