Methods returned by useMediaDevice Hook - React Native
useMediaDevice() returns the methods below. They work outside RoomProvider.
requestPermission()
- The
requestPermission()method prompts the user for permission to use a camera and mic. It returns aPromisethat resolves to aMap<string, boolean>object.
On Android, the SDK does not ask for camera and microphone access by itself. Call requestPermission() before you join. It works outside RoomProvider, so you can ask on your join screen. iOS asks on its own when the room turns the camera or mic on.
createCameraVideoTrack(), createMicrophoneAudioTrack() and runPreCallTest() never ask, on Android or iOS. Call requestPermission() before you use them.
Parameters
Permission- A
stringspecifying the specific kinds of media, that you want to request. Optional- Allow Values :
audio,video,audio_video(Constants.permission.AUDIO,Constants.permission.VIDEO,Constants.permission.AUDIO_AND_VIDEO) - Default :
audio_video
- A
Returns
Promise<Map<string, boolean>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { requestPermission } = useMediaDevice();
const onPress = async () => {
try {
const requestAudioVideoPermission = await requestPermission(
Constants.permission.AUDIO_AND_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() does not throw when the user refuses access. Check the returned values instead: a permission that was not granted is false.
checkPermission()
- The
checkPermission()method checks for permission to use a camera and mic. 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(Constants.permission.AUDIO,Constants.permission.VIDEO,Constants.permission.AUDIO_AND_VIDEO) - Default :
audio_video
- A
Returns
Promise<Map<string, boolean>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { checkPermission } = useMediaDevice();
const onPress = async () => {
try {
const checkAudioVideoPermission = await checkPermission();
console.log(
"check Audio and Video Permissions",
checkAudioVideoPermission.get(Constants.permission.AUDIO),
checkAudioVideoPermission.get(Constants.permission.VIDEO)
);
} catch (ex) {
console.log("Error in checkPermission ", ex);
}
};
checkPermission() only reads the current permission state. It never prompts the user.
checkBlueToothPermission()
- The
checkBlueToothPermission()method checks if the application has permission to access Bluetooth on the device. It returns a Promise that resolves to a boolean value indicating whether Bluetooth permission is granted.
Returns
Promise<boolean>
- This method is only supported on Android devices running Android 12 or later.
- On iOS the returned
Promiserejects.
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { checkBlueToothPermission } = useMediaDevice();
const onPress = async () => {
try {
const checkBTPermission = await checkBlueToothPermission();
console.log("Check BT Permission:", checkBTPermission);
} catch (ex) {
console.log("Error in checkBTPermission ", ex);
}
};
requestBluetoothPermission()
- The
requestBluetoothPermission()method requests permission to access Bluetooth on the device. It returns a Promise that resolves to a boolean value indicating whether the permission request was successful.
Returns
Promise<boolean>
- This method is only supported on Android devices running Android 12 or later.
- On iOS the returned
Promiserejects.
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { requestBluetoothPermission } = useMediaDevice();
const onPress = async () => {
try {
const checkBTPermission = await requestBluetoothPermission();
console.log("Check BT Permission:", checkBTPermission);
} catch (ex) {
console.log("Error in checkBTPermission ", ex);
}
};
getCameras()
-
Resolves the cameras the SDK can open, as
CameraDeviceInfoobjects. -
Each
CameraDeviceInfohas:deviceId: an identifier for the camera. Pass it tochangeCam()or ascameraIdtocreateCameraVideoTrack().kind:videoinput.label: a name for the camera.facingMode:"front","back"ornullwhen the platform does not say.
Returns
Promise<Array<CameraDeviceInfo>>
Example
import { useMediaDevice } from "@videosdk.live/react-native-sdk";
const { getCameras } = useMediaDevice();
const onPress = async () => {
const cameras = await getCameras();
console.log("Cameras:", cameras);
};
getMics()
-
Resolves the audio devices the SDK can route audio to, as
MicrophoneDeviceInfoobjects. -
Each
MicrophoneDeviceInfohas:deviceId: an identifier for the device. Pass it tochangeMic(), tosetAudioDevice(), or asmicrophoneIdtocreateMicrophoneAudioTrack().kind:audioinput.label: a name for the device.
Returns
Promise<Array<MicrophoneDeviceInfo>>
Example
import { useMediaDevice } from "@videosdk.live/react-native-sdk";
const { getMics } = useMediaDevice();
const onPress = async () => {
const mics = await getMics();
console.log("Audio devices:", mics);
};
getDevices()
- Resolves the audio devices from
getMics(), followed by the cameras fromgetCameras(), in one array. - Each
DeviceInfohasdeviceId,labelandkind(videoinputoraudioinput). Cameras also havefacingMode.
Returns
Promise<Array<DeviceInfo>>
Example
import { useMediaDevice } from "@videosdk.live/react-native-sdk";
const { getDevices } = useMediaDevice();
const onPress = async () => {
const devices = await getDevices();
console.log("Devices:", devices);
};
getSelectedVideoDevice()
- Returns the camera you asked for by
deviceId, for example withchangeCam(), as{ deviceId }. Returnsnullwhen the SDK chose the camera or you use a custom track.
Returns
{ deviceId: string } | null
getSelectedAudioDevice()
- Returns the audio device in use, as
{ deviceId }, ornullwhen the SDK chose it.
Returns
{ deviceId: string } | null
Example
import { useMediaDevice } from "@videosdk.live/react-native-sdk";
function SelectedDevices() {
const { getSelectedVideoDevice, getSelectedAudioDevice } = useMediaDevice();
console.log("Camera:", getSelectedVideoDevice()?.deviceId);
console.log("Audio device:", getSelectedAudioDevice()?.deviceId);
return null;
}
To route audio to another device, call setAudioDevice() from useRoom(). To follow devices being connected or removed, pass onAudioDeviceChanged to useMediaDevice().
Got a Question? Ask us on discord

