georapbox / barcode-scanner

A Progressive Web Application (PWA) that scans barcodes of various formats, using the Barcode Detection API.
https://georapbox.github.io/barcode-scanner/
MIT License
64 stars 29 forks source link

Feature Request: turn on flash led #16

Closed catrielr closed 1 week ago

catrielr commented 3 weeks ago

I couldn't access the flash LED on IOS. I haven't tried it on Android yet

georapbox commented 3 weeks ago

Hi,

This is not supported at the moment. The MediaTrackConstraints dictionary includes a torch constraint but as far as I know the support is limited and depends on various factors, such as device, OS and browser. For example, on my device (Poco X6 Pro, Android 14) it is supported on Chromium browsers but I cannot guarantee that it will work on other devices, not to mention iOS.

Anyway, I can make some tests and see if it's worth to add it as feature.

georapbox commented 3 weeks ago

I couldn't access the flash LED on IOS. I haven't tried it on Android yet

Now that I read your comment again, could you please clarify if you mean that you couldn't access the flash led from the operation system menu while the app is running or you would wish to have an option to toggle the flash led from inside the app?

My previous comment was referring to the latter one but if this is the first one that you meant, I think that the OS is doing that on purpose because the flashlight is tied to the camera hardware. When the camera is in use by an app (such as in a WebRTC video stream), the system generally locks access to the camera's resources, including the flash.

One solution I'm experimenting right now, is to have a button in the app to control the flashlight but as I already mentioned in my previous comment, this is a feature that might not work on all devices.

catrielr commented 3 weeks ago

Hello George. I mean there is no way to turn on the LED flash from the application. It would be nice to add a button that turns on the LED. I'm testing the app to scan PDF417, and in low light it doesn't read the code.

Another thing that happened to me is that with the iPhone 14 it uses the large camera.

georapbox commented 3 weeks ago

Yes, that can happen with devices with multiple cameras. Unfortunately, I don't have access to an iPhone to test it physically. Nevertheless, I will investigate it further to see if there is any way to provide the ability to the user to select from available cameras if possible. I know for sure that there is a way to enumerate the devices with MediaDevices.enumerateDevices() method which I guess could be used to get the preferred device id and use that to start the selected camera.

georapbox commented 1 week ago

Hi,

I just merged the feature to add support for flash light. The new feature will work only for supported devices. So far, I was able to test it on 3 Android phones, an old Motorola One (Android 10), a Poco X3 Pro (Android 12) and a Poco X6 Pro (Android 14) and it was working as expected. I'm not sure though if this is supported on iOS.

catrielr commented 1 week ago

George, try it on iPhone: 10 worked. 11 didn't work (I think it's the IOS version) 14 worked, and using the zoom buttons the wide angle camera can focus and scan well.