React 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 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-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);
      }

      Note

      This method will throw an error if the browser does not support permission checking functionality.

      • 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 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-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 media device (camera, microphone, or speaker) is connected to or disconnected from the system.
      • This event emits the updated list of available devices after the change has occurred.

      Parameters

      • devices: Promise<DeviceInfo[]>

        An array of currently available media devices.

      Returns void

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

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