jamenamcinteer / react-qr-barcode-scanner

A simple React Component using the client's webcam to read barcodes.
69 stars 71 forks source link

DeviceID #44

Closed hvitis closed 1 year ago

hvitis commented 1 year ago

Hey,

I have stumbled on a problem with a Samsung camera that has couple of lenses. The default being taken to the feed by this library is a long-range one. I would like to change the environment camera, not only the front/back facing. Is there a good way to do this? I have seen that deviceId is being used in the code but not sure how universal it is.

Thanks

hvitis commented 1 year ago

Ok I got that from here

  const [device, setDevice] = useState({})
  const [devices, setDevices] = useState([])

  const handleDevices = useCallback(
    (mediaDevices) => setDevices(mediaDevices.filter(({ kind }) => kind === 'videoinput')),
    [setDevices]
  )

  useEffect(() => {
    navigator.mediaDevices.enumerateDevices().then(handleDevices)
  }, [handleDevices])

<BarcodeScannerComponent videoConstraints={{ deviceId: device.deviceId }} />