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

228
Vistas
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 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