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

229
Visualizações
Returning a value from an imported function

This may be a simple problem but I can't get my head around it. I have a javascript file that looks like this:

import { canWeCamera } from './modules/_canWeCamera.js';
import { qrReader } from './modules/_qrReader.js';


function init() {
    
    canWeCamera();
    // Need to only run the function below if there is a camera
    qrReader();
  
}
  
init();

And the canWeCamera import looks like this:

export function canWeCamera() {

    if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
        console.log("enumerateDevices() not supported.");
    }
      
      navigator.mediaDevices.enumerateDevices()
      .then(function(devices) {
        devices.forEach(function(device) {
          if(device.kind == 'videoinput') {
              alert('There is a video device');
          }
        });
      })
      .catch(function(err) {
        console.log(err.name + ": " + err.message);
      });

}

Which is all working as expected.

My next step is only running the qrReader function if there is a camera. I guess I need to return a variable from the canWeCamera function, but I can't get it to work.

If anyone has any pointers that would be great

about 4 years ago · Juan Pablo Isaza
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