Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

649
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda