react-zxing icon indicating copy to clipboard operation
react-zxing copied to clipboard

video is blank when granted camera permissions for the first time

Open kawpiya opened this issue 3 years ago • 8 comments

I notice that in dev mode (my case Nextjs) newly granting camera permission result in empty <video> (white box), but in production mode things work fine.

kawpiya avatar Dec 23 '22 12:12 kawpiya

Is there just a delay or does the stream not start at all? Have you got any clues?

adamalfredsson avatar Jan 04 '23 22:01 adamalfredsson

@nomadoda streaming not starting at all (square with the green border is the video element)

Screenshot from 2023-01-05 11-07-20

kawpiya avatar Jan 05 '23 05:01 kawpiya

@nomadoda I noticed if you change something in the DOM, which causes a HMR, after that video feed is visible.

kawpiya avatar Jan 05 '23 09:01 kawpiya

Also getting following in the console.

Screenshot from 2023-01-05 15-08-36

kawpiya avatar Jan 05 '23 09:01 kawpiya

Just giving my 2 cents. I had this same issue and i believe its because of the timing of how things happen. The way I solved it is I made a separate component with the video and useZxing and I only render this component if there are permissions already given. This completely resolved the issue.

DonKoko avatar Apr 01 '24 10:04 DonKoko

Just giving my 2 cents. I had this same issue and i believe its because of the timing of how things happen. The way I solved it is I made a separate component with the video and useZxing and I only render this component if there are permissions already given. This completely resolved the issue.

Could you please share your code? I tried getting the permissions in advance with navigator.mediaDevices.getUserMedia({ video: true }), and then conditionally show the scanner component, but it still gave me the error above, and then a bunch of "No MultiFormat Readers were able to detect the code." errors. If the scanner is rendered on app start, it works correctly.

lenard-a avatar Oct 17 '24 17:10 lenard-a

@lenard-a there it is: https://github.com/Shelf-nu/shelf.nu/blob/main/app/routes/_layout%2B/scanner.tsx#L51-L91 Hope that helps.

DonKoko avatar Oct 18 '24 08:10 DonKoko

Thank you! I realized that disabling StrictMode makes it happen much less frequent, but I will check your code to fully fix the issue.

lenard-a avatar Oct 18 '24 17:10 lenard-a