Identify if the computer has a QR Code reader

5

The first step of registering my project has two layout options: one for who owns a QR code reader (web cam) and one for those who do not.

I need to identify if the user's browser has access to the webcam for reading the QR Code, how can I do this verification?

    
asked by anonymous 14.12.2015 / 16:43

1 answer

4

You can use HTML5 to detect whether or not the user has an available video recording device:

navigator.getMedia = ( navigator.getUserMedia ||
                      navigator.webkitGetUserMedia ||
                      navigator.mozGetUserMedia ||
                      navigator.msGetUserMedia);

navigator.getMedia({video: true}, function() {
  //Câmera disponível
  $('.com-leitor').show();
  $('.sem-leitor').hide();
}, function() {
  //Câmera não disponível
  $('.com-leitor').hide();
  $('.sem-leitor').show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass='com-leitor'>SUCCESS!=)</div><divclass='sem-leitor'>FAIL!=(</div>

Font

    
14.12.2015 / 16:52