useDevices
useDevices(): Object
Returns information about a participant's media devices and their states, along with helper functions that wrap daily-js device-related methods.
For more information about the different error states, check the camera-error reference.
Return type
Returns an object with the following properties:
| Name | Type | Description | 
|---|---|---|
| cameraError | Object | null | Stores the most recent error object that was emitted through the camera-errorevent | 
| cameras | Object[] | An array of device objects that contains information about each camera | 
| camState | string | 'idle' | 'pending' | 'not-supported' | 'granted' | 'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown', indicates the general state of camera access | 
| currentCam | Object | undefined | References the selected device in the camerasarray. | 
| currentMic | Object | undefined | References the selected device in the microphonesarray. | 
| currentSpeaker | Object | undefined | References the selected device in the speakersarray. | 
| hasCamError | boolean | truein casecamStateis one of'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown' | 
| hasMicError | boolean | truein casemicStateis one of'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown' | 
| microphones | Object[] | An array of device objects that contains information about each microphone | 
| micState | string | 'idle' | 'pending' | 'not-supported' | 'granted' | 'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown', indicates the general state of microphone access | 
| refreshDevices | Function | Refreshes the list of devices using enumerateDevices() | 
| setCamera | Function | Switches to the camera with the specified deviceId. CallssetInputDevicesAsync() | 
| setMicrophone | Function | Switches to the mic with the specified deviceId. CallssetInputDevicesAsync() | 
| setSpeaker | Function | Switches to the speaker with the specified deviceId. CallssetOutputDeviceAsync() | 
| speakers | Object[] | An array of device objects that contains information about each speaker | 
About camState and micState
With 0.7.0 camState and micState have a new default value of "idle" (in previous versions of Daily React, this value was "pending").
Both states remain "idle" as long as no device access has been requested, which is the case for rooms configured with start_audio_off: true and start_video_off: true.
Once device access is requested, camState and micState switch to "pending", as long as device access is pending.
Once the user grants device access they will switch to "granted". In case the user blocked device access they switch to "blocked" accordingly.
In case of an error the most representative error state will be applied.
Device object properties
| Name | Type | Description | 
|---|---|---|
| device | Object | The same device information returned from enumerateDevices() | 
| selected | boolean | truewhen this specific device is currently being used bygetUserMedia() | 
| state | string | 'granted' | 'in-use','granted'means the device is available,'in-use'means the device is used by another app |