useMediaDevices
React sensor hook that tracks connected hardware devices
Usage
Live Editor
function Demo() { const [state] = useMediaDevices({ requestPermissions: true, }); return <pre>{JSON.stringify(state, null, 2)}</pre>; };
Result
Loading...
API
useMediaDevices
Returns
readonly [{ devices: { deviceId: string; groupId: string; kind: MediaDeviceKind; label: string; }[]; }, () => Promise<boolean>]
: A tuple with the following elements:
- The media devices info.
- A function to request media devices permission.
Arguments
Argument | Description | Type | DefaultValue |
---|---|---|---|
options | optional params | UseMediaDeviceOptions | undefined | - |
UseMediaDeviceOptions
Property | Description | Type | DefaultValue |
---|---|---|---|
requestPermissions | Request for permissions immediately if it's not granted,otherwise label and deviceIds could be empty | boolean | false |
constraints | Request for types of media permissions | MediaStreamConstraints | { audio: true, video: true } |