Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

655
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda