useMediaDeviceSelect
function useMediaDeviceSelect(options): {
devices: MediaDeviceInfo[];
className: string;
activeDeviceId: string;
setActiveMediaDevice: (id, options?) => Promise<void>;
};Defined in: packages/react/src/hooks/device/useMediaDeviceSelect.ts:43
The useMediaDeviceSelect hook is used to implement the MediaDeviceSelect component and returns o.a. the list of devices of a given kind (audioinput or videoinput), the currently active device and a function to set the the active
Parameters
| Parameter | Type |
|---|---|
options | UseMediaDeviceSelectOptions |
Returns
{
devices: MediaDeviceInfo[];
className: string;
activeDeviceId: string;
setActiveMediaDevice: (id, options?) => Promise<void>;
}devices
devices: MediaDeviceInfo[];className
className: string;activeDeviceId
activeDeviceId: string;setActiveMediaDevice
setActiveMediaDevice: (id, options?) => Promise<void>;Parameters
| Parameter | Type |
|---|---|
id | string |
options? | unknown |
Returns
Promise<void>
Example
function MicrophoneSelect() {
const { devices, activeDeviceId, setActiveMediaDevice } = useMediaDeviceSelect({
kind: "audioinput",
requestPermissions: true,
});
return <select value={activeDeviceId} onChange={(event) => setActiveMediaDevice(event.target.value)}>
{devices.map((device) => <option key={device.deviceId} value={device.deviceId}>{device.label}</option>)}
</select>;
}