js qr code scanner

Solutions on MaxInterview for js qr code scanner by the best coders in the world

showing results for - "js qr code scanner"
Erik
06 Aug 2016
1var videoSelect = document.querySelector('select#videoSource');
2
3navigator.mediaDevices.enumerateDevices()
4  .then(gotDevices).then(getStream).catch(handleError);
5
6videoSelect.onchange = getStream;
7
8function gotDevices(deviceInfos) {
9  for (var i = deviceInfos.length - 1; i >= 0; --i) {
10    var deviceInfo = deviceInfos[i];
11    var option = document.createElement('option');
12    option.value = deviceInfo.deviceId;
13    if (deviceInfo.kind === 'videoinput') {
14      option.text = deviceInfo.label || 'camera ' +
15        (videoSelect.length + 1);
16      videoSelect.appendChild(option);
17    } else {455
18      console.log('Found one other kind of source/device: ', deviceInfo);
19    }
20  }
21}
22
23function getStream() {
24  buttonGo.disabled = false;
25  if (window.stream) {
26    window.stream.getTracks().forEach(function(track) {
27      track.stop();
28    });
29  }
30
31  var constraints = {
32    video: {
33      deviceId: {exact: videoSelect.value}
34    }
35  };
36
37  navigator.mediaDevices.getUserMedia(constraints).
38    then(gotStream).catch(handleError);
39}
40
41function gotStream(stream) {
42  window.stream = stream; // make stream available to console
43  videoElement.srcObject = stream;
44}
45
46function handleError(error) {
47  console.log('Error: ', error);
48}
49
50