fancy-planet-81885
11/04/2025, 4:28 PMtall-airline-16756
11/04/2025, 4:29 PMtall-airline-16756
11/04/2025, 4:30 PMdeviceId and kind ('audioinput' or 'videoinput').
b. Call:
await room.switchActiveDevice(kind, deviceId)
This updates the corresponding local track and republishing is handled for you. Reference
• Track-level (fine-grained control):
◦ If you have the `LocalTrack`:
await localTrack.setDeviceId(deviceId)
• Or hot-swap explicitly:
await localParticipant.replaceTrack(localTrack, { /* options if needed */ })
Reference
If you’re using @livekit/react, I can share a snippet wired to a device selector—do you prefer the room-level helper or track-level control?
Sources: Web Applications & Integration Examples | livekit/livekit_composite | DeepW... | JavaScript SDK & React Components | livekit/livekit_composite | DeepWikifancy-planet-81885
11/04/2025, 4:30 PMtall-airline-16756
11/04/2025, 4:31 PMroom.switchActiveDevice, which hot-swaps the published track smoothly.
import { useEffect, useState } from 'react';
import { useRoom } from '@livekit/components-react';
const kindMap = {
'video-input': 'videoinput',
'audio-input': 'audioinput',
'audio-output': 'audiooutput',
} as const;
export function DeviceSelectors() {
const { room } = useRoom();
const [devices, setDevices] = useState<MediaDeviceInfo[]>([]);
useEffect(() => {
const load = async () => {
const list = await navigator.mediaDevices.enumerateDevices();
setDevices(list);
};
load();
navigator.mediaDevices.addEventListener('devicechange', load);
return () => navigator.mediaDevices.removeEventListener('devicechange', load);
}, []);
const onChange = async (e: React.ChangeEvent<HTMLSelectElement>) => {
const deviceId = e.target.value;
const kind = kindMap[e.target.name as keyof typeof kindMap];
if (room && deviceId && kind) {
await room.switchActiveDevice(kind, deviceId);
}
};
const options = (kind: MediaDeviceKind) =>
devices.filter(d => d.kind === kind).map(d => (
<option key={d.deviceId} value={d.deviceId}>{d.label || d.deviceId}</option>
));
return (
<div>
<label>
Camera
<select name="video-input" onChange={onChange}>{options('videoinput')}</select>
</label>
<label>
Microphone
<select name="audio-input" onChange={onChange}>{options('audioinput')}</select>
</label>
<label>
Speakers
<select name="audio-output" onChange={onChange}>{options('audiooutput')}</select>
</label>
</div>
);
}
• This calls room.switchActiveDevice(kind, deviceId) to swap mic/camera/speakers smoothly. Reference
If you’d prefer track-level control (using LocalTrack.setDeviceId), I can share that variant too.
Sources: Web Applications & Integration Examples | livekit/livekit_composite | DeepW... | JavaScript SDK & React Components | livekit/livekit_composite | DeepWiki | React quickstart | LiveKit docs | React Core and Componentsfancy-planet-81885
11/04/2025, 4:32 PMtall-airline-16756
11/04/2025, 4:32 PMroom.switchActiveDevice.
Key actions:
• Microphone: select → await room.switchActiveDevice('audioinput', deviceId)
• Camera: select → await room.switchActiveDevice('videoinput', deviceId)
• Speakers: select → await room.switchActiveDevice('audiooutput', deviceId)
This hot-swaps the published track/output smoothly for the chosen device. If you’d like, I can adapt the snippet to your UI or show the track-level variant using LocalTrack.setDeviceId for finer control. Reference