React Native Api Reference
    Preparing search index...

    Class useMediaDevice

    useMediaDevice provides methods and events to manage media devices and handle media permission access.

    Index

    Constructors

    Methods

      • This method can be used to check whether the application has permission to access Bluetooth on the device.
      • It returns a Promise that resolves to a boolean value indicating if Bluetooth permission is granted.

      INFO

      • This method is supported only on Android devices running Android 12 or later.
      • This method is not supported on iOS devices.

      Returns Promise<boolean>

      import { useMediaDevice } from "@videosdk.live/react-native-sdk";

      const { checkBlueToothPermission } = useMediaDevice();

      const onPress = async () => {
      try {
      const hasPermission = await checkBlueToothPermission();
      console.log("Bluetooth Permission:", hasPermission);
      } catch (error) {
      console.log("Error while checking Bluetooth permission", error);
      }
      };
      • This method can be used to check whether the application already has permission to access media input devices.
      • It returns a Promise that resolves to a Map<string, boolean> indicating the permission status.

      Parameters

      • Optionalpermissions: Permission

        Specifies the type of media permission to request.

        Allowed value: Permission

      Returns Promise<Map<string, boolean>>

      A Promise that resolves to a Map<string, boolean> where:

      • true indicates permission is granted
      • false indicates permission is denied
      AUDIO_AND_VIDEO
      
      import { Constants, useMediaDevice } from "@videosdk.live/react-native-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 checking permissions:", ex);
      }
      • This method can be used to retrieve a list of all currently available media input and output devices.
      • The returned Promise resolves with an array of DeviceInfo objects.

      Returns Promise<DeviceInfo[]>

      • This method can be used to request permission to access Bluetooth on the device.
      • It returns a Promise that resolves to a boolean value indicating whether the permission request was granted.

      INFO

      • This method is supported only on Android devices running Android 12 or later.
      • This method is not supported on iOS devices.

      Returns Promise<boolean>

      import { useMediaDevice } from "@videosdk.live/react-native-sdk";

      const { requestBluetoothPermission } = useMediaDevice();

      const onPress = async () => {
      try {
      const hasPermission = await requestBluetoothPermission();
      console.log("Bluetooth Permission:", hasPermission);
      } catch (error) {
      console.log("Error while requesting Bluetooth permission", error);
      }
      };
      • This method can be used to prompt the user for permission to access media input devices.
      • It requests permission for the specified media types and returns the permission status for each requested media kind.

      Parameters

      • Optionalpermissions: Permission

        Specifies the type of media permission to request.

        Allowed value: Permission

      Returns Promise<Map<string, boolean>>

      import { Constants, useMediaDevice } from "@videosdk.live/react-native-sdk";

      const { requestPermission } = useMediaDevice();

      try {
      const permissionsMap = 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);
      }

      Note

      requestPermission() will throw an error when matching media is not available.

    Events

      • Triggered whenever a audio devices, such as a microphone or speaker is connected to or removed from the device.

      NOTE

      Make sure you have microphone permission granted on the device, otherwise, this event will not return the list.

      Parameters

      • devices: Promise<DeviceInfo[]>

        An array of currently available media devices.

      Returns void

      function onAudioDeviceChanged(devices) {
      console.log("onAudioDeviceChanged ", devices);
      }

      const {
      ...
      } = useMediaDevice({
      onAudioDeviceChanged
      });