Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

647
Views
How to access torch (flashlight) using javascript or jquery?

I am using the html5-qrcode barcode scanner library v2.0.12 based on zxing-js. I am using php, javascript and html to make a PWA that scans barcodes. I am testing on an iphone 8 using iOS 14.7.1.

Here is the documentation link for the library: QR and barcode scanner using HTML and Javascript

My issue is that I cannot find any documentation online that allows any config settings to enable the torch/flashlight option once the scanner window has started. I am wanting to do this for low light settings where it might help to get a better scan.

UPDATE I have found this link to a fork that mentions the flashlight support, but I cannot figure out how to add the appropriate code or where. It does mention the camera must first be activated. Add support for detecting and turning on/off flash light

In the config settings I have tried 'torch: true' but it does not do anything. I have also looked into using getUserMedia. The references I find on this site all seem to not work on iphones.

Is it possible to control the camera light on a phone via a website?

Turn on phone flashlight on web app using JavaScript and HTML

NodeJS - Turn On and Off Tourch/Flashlight in mobile Android/IPhone

Is it possible to use a jquery or javascript code and/or library to add a toggle switch to manually turn it on? At this point the user has already granted permission for the browser to access the phone if that makes a difference.

<script src="https://unpkg.com/html5-qrcode@2.0.9/dist/html5-qrcode.min.js"></script>

<div id="reader" width="350px"></div>

<script>
  const html5QrCode = new Html5Qrcode("reader");
  /** successful scan actions **/
  const qrCodeSuccessCallback = (decodedText, decodedResult) => {
    html5QrCode.stop();
    alert (decodedText);
  };
  /** define scanner default settings **/
  const config = { fps: 60, 
                   qrbox: 275, 
                   torch: true,
                   aspectRatio: 1.0
                 };
  html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Once the camera started, you can power on or off the torch calling applyVideoConstraints.

function powerTorch(powerOn) 
{    
  if(html5QrCode.getState() === Html5QrcodeScannerState.SCANNING ||
     html5QrCode.getState() === Html5QrcodeScannerState.PAUSED
    )
  {
    html5QrCode.applyVideoConstraints(
       {
         advanced: [{torch: powerOn}]
       });
  }
}

But I think it still does not work on iPhones (it doesn't work on the ip13 of my friend).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!