UNPKG

@jellyfish-dev/browser-media-utils

Version:

Facilitates the use of getUserMedia and enumerateDevices.

14 lines (13 loc) 583 B
import { useMemo } from "react"; import { useMedia } from "./useMedia"; /** * Hook that returns the media stream and methods to control it, depending on the passed id of device and type. * * @param type - type of media stream * @param deviceId - id of device * @returns object containing information about the media stream and methods to control it */ export const useUserMediaById = (type, deviceId) => { const media = useMemo(() => (deviceId ? () => navigator.mediaDevices.getUserMedia({ [type]: { deviceId } }) : null), [deviceId, type]); return useMedia(media); };