diff --git a/packages/qr-code-scanner/src/qr-code-scanner.js b/packages/qr-code-scanner/src/qr-code-scanner.js index 1a89160d1acee76c91371fbb7ea103b5b863c9d0..7a45e622f1471daf24db249977bbf352b0d2bce3 100644 --- a/packages/qr-code-scanner/src/qr-code-scanner.js +++ b/packages/qr-code-scanner/src/qr-code-scanner.js @@ -61,7 +61,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { let devices_map = new Map(); const that = this; - let counter = 0; if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices @@ -75,12 +74,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { if (device.kind === 'videoinput') { let id = device.deviceId; if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { - if (counter === 0) { - devices_map.set('environment', i18n.t('back-camera')); - counter = 1; - } else { - devices_map.set('user', i18n.t('front-camera')); - } + devices_map.set('environment', i18n.t('back-camera')); + devices_map.set('user', i18n.t('front-camera')); } else { devices_map.set(id ? id : true, device.label || i18n.t('camera') + (devices_map.size + 1)); } @@ -166,10 +161,15 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { const that = this; let constraint = { video: { deviceId: this._('#videoSource').options[this._('#videoSource').selectedIndex].value } }; - if ( (this._('#videoSource').options[this._('#videoSource').selectedIndex].value === 'environment') || (this._('#videoSource').options[this._('#videoSource').selectedIndex].value === 'user') ) { + if ( (this._('#videoSource').options[this._('#videoSource').selectedIndex].value === 'environment') ) { constraint = { video: { facingMode: "environment" } }; + } else if ( this._('#videoSource').options[this._('#videoSource').selectedIndex].value === 'user' ) { + constraint = { video: { facingMode: "user" } }; } - that._("#error").innerText += " constraint: " + JSON.stringify(constraint); + + + + navigator.mediaDevices.getUserMedia(constraint).then(function(stream) { video.srcObject = stream;