Methods returned by useMediaDevice Hook - React
getDevices()
- 
The getDevices()method returns a list of the currently available media input and output devices, such as microphones, cameras, headsets, and so forth. The returnedPromiseis resolved with an array ofDeviceInfoobjects describing the devices.
- 
DeviceInfoclass has four properties :- 
DeviceInfo.deviceId- Returns a string that is an identifier for the represented device, persisted across sessions.
 
- 
DeviceInfo.groupId- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
 
- 
DeviceInfo.kind- Returns an enumerated value that is either videoinput,audioinputoraudiooutput.
 
- Returns an enumerated value that is either 
- 
DeviceInfo.label- Returns a string describing this device (for example "External USB Webcam").
 
 
- 
Returns
- Promise<Array<DeviceInfo>>
getCameras()
- 
The getCameras()method returns a list of currently available video input devices. The returnedPromiseis resolved with an array ofCameraDeviceInfoobjects describing the video input devices.
- 
CameraDeviceInfoclass has four properties :- 
CameraDeviceInfo.deviceId- Returns a string that is an identifier for the represented device, persisted across sessions.
 
- 
CameraDeviceInfo.groupId- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
 
- 
CameraDeviceInfo.kind- Returns an enumerated value that is videoinput.
 
- Returns an enumerated value that is 
- 
CameraDeviceInfo.label- Returns a string describing this device (for example "External USB Webcam").
 
 
- 
Returns
- Promise<Array<CameraDeviceInfo>>
getMicrophones()
- 
The getMicrophones()method returns a list of currently available audio input devices. The returnedPromiseis resolved with an array ofMicrophoneDeviceInfoobjects describing the audio input devices.
- 
MicrophoneDeviceInfoclass has four properties :- 
MicrophoneDeviceInfo.deviceId- Returns a string that is an identifier for the represented device, persisted across sessions.
 
- 
MicrophoneDeviceInfo.groupId- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
 
- 
MicrophoneDeviceInfo.kind- Returns an enumerated value that is audioinput.
 
- Returns an enumerated value that is 
- 
MicrophoneDeviceInfo.label- Returns a string describing this device (for example "External Microphone").
 
 
- 
Returns
- Promise<Array<MicrophoneDeviceInfo>>
getPlaybackDevices()
- 
The getPlaybackDevices()method returns a list of currently available playback devices. The returnedPromiseis resolved with an array ofPlaybackDeviceInfoobjects describing the playback devices.
- 
PlaybackDeviceInfoclass has four properties :- 
PlaybackDeviceInfo.deviceId- Returns a string that is an identifier for the represented device, persisted across sessions.
 
- 
PlaybackDeviceInfo.groupId- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
 
- 
PlaybackDeviceInfo.kind- Returns an enumerated value that is audiooutput.
 
- Returns an enumerated value that is 
- 
PlaybackDeviceInfo.label- Returns a string describing this device (for example "External HeadPhones").
 
 
- 
Returns
- Promise<Array<PlaybackDeviceInfo>>
requestPermission()
- The requestPermission()method prompts the user for permission to use a media input. It returns aPromisethat resolves to aMap<string, boolean>object.
Parameters
- Permission- A stringspecifying the specific kinds of media, that you want to request.
- Optional
- Allow Values : audio,video,audio_video
- Default : audio_video
 
- A 
Returns
- Promise<Map<string, boolean>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-sdk";
const { requestPermission } = useMediaDevice();
try {
  const requestAudioVideoPermission = await requestPermission(
    Constants.permission.AUDIO_VIDEO
  );
  console.log(
    "request Audio and Video Permissions",
    requestAudioVideoPermission.get(Constants.permission.AUDIO),
    requestAudioVideoPermission.get(Constants.permission.VIDEO)
  );
} catch (ex) {
  console.log("Error in requestPermission ", ex);
}
requestPermission() will throw an error when matching media is not available.
checkPermissions()
- The checkPermissions()method checks for permission to use a media input. It returns aPromisethat resolves to aMap<string, boolean>object.
Parameters
- Permission- A stringspecifying the types of media to check.
- Optional
- Allow Values : audio,video,audio_video
- Default : audio_video
 
- A 
Returns
- Promise<Map<string, boolean>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-sdk";
const { checkPermissions } = useMediaDevice();
try {
  const checkAudioVideoPermission = await checkPermissions();
  console.log(
    "check Audio and Video Permissions",
    checkAudioVideoPermission.get(Constants.permission.AUDIO),
    checkAudioVideoPermission.get(Constants.permission.VIDEO)
  );
} catch (ex) {
  console.log("Error in checkPermissions ", ex);
}
checkPermissions() will throw an error when the browser doesn't support permission check functionality.
Got a Question? Ask us on discord

