Methods returned by useMediaDevice Hook - React Native
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 returnedPromise
is resolved with an array ofDeviceInfo
objects describing the devices. -
DeviceInfo
class has four properties :-
DeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
DeviceInfo.kind
- Returns an enumerated value that is either
video
oraudio
.
- Returns an enumerated value that is either
-
DeviceInfo.label
- Returns a string describing this device (for example
BLUETOOTH
).
- Returns a string describing this device (for example
-
Returns
Promise<Array<DeviceInfo>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { getDevices } = useMediaDevice();
const onPress = async () => {
try {
const listofDevice = await getDevices();
console.log("List of Devices:", listofDevice);
} catch (ex) {
console.log("Error in getDevices ", ex);
}
};
getCameras()
-
The
getCameras()
method returns a list of currently available camera devices. The returnedPromise
is resolved with an array ofCameraDeviceInfo
objects describing the camera devices. -
CameraDeviceInfo
class has four properties :-
CameraDeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
CameraDeviceInfo.kind
- Returns an enumerated value that is
video
.
- Returns an enumerated value that is
-
CameraDeviceInfo.facingMode
- Returns a string indicating the camera's position, such as
front
orback
- Returns a string indicating the camera's position, such as
-
Returns
Promise<Array<CameraDeviceInfo>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { getCameras } = useMediaDevice();
const onPress = async () => {
try {
const listofCameras = await getCameras();
console.log("List of Cameras:", listofCameras);
} catch (ex) {
console.log("Error in getting Cameras ", ex);
}
};
getAudioDeviceList()
-
The
getAudioDeviceList()
method returns a list of currently available audio devices. The returnedPromise
is resolved with an array ofMicrophoneDeviceInfo
objects describing the audio devices. -
MicrophoneDeviceInfo
class has four properties :-
MicrophoneDeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
MicrophoneDeviceInfo.kind
- Returns an enumerated value that is
audio
.
- Returns an enumerated value that is
-
MicrophoneDeviceInfo.label
- Returns a string describing this device (for example
BLUETOOTH
).
- Returns a string describing this device (for example
-
Returns
Promise<Array<MicrophoneDeviceInfo>>
Example
import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";
const { getAudioDeviceList } = useMediaDevice();
const onPress = async () => {
try {
const listofMic = await getAudioDeviceList();
console.log("List of Microphone:", listofMic);
} catch (ex) {
console.log("Error in getting Microphone ", ex);
}
};
requestPermission()
- The
requestPermission()
method prompts the user for permission to use a camera and mic. It returns aPromise
that resolves to aMap<string, boolean>
object.
Parameters
Permission
- A
string
specifying 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-native-sdk";
const { requestPermission } = useMediaDevice();
const onPress = async () => {
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.
checkPermission()
- The
checkPermission()
method checks for permission to use a camera and mic. It returns aPromise
that resolves to aMap<string, boolean>
object.
Parameters
Permission
- A
string
specifying 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-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()
will throw an error when the browser doesn't support permission check functionality.
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.
- This method is not supported on iOS devices.
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.
- This method is not supported on iOS devices.
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);
}
};
Got a Question? Ask us on discord