Skip to content
Snippets Groups Projects
Commit f6db5b9f authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Convert checkSupport to an async function

parent bee132a1
No related branches found
No related tags found
No related merge requests found
...@@ -63,10 +63,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -63,10 +63,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
i18n.changeLanguage(this.lang); i18n.changeLanguage(this.lang);
const that = this;
this.updateComplete.then(()=>{ this.updateComplete.then(async ()=>{
this.checkSupport(); await this.checkSupport();
if (!this.stopScan) { if (!this.stopScan) {
this.qrCodeScannerInit(); this.qrCodeScannerInit();
} }
...@@ -89,44 +88,48 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -89,44 +88,48 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
* Gets video devices of device * Gets video devices of device
* *
*/ */
checkSupport() { async checkSupport() {
const that = this; const that = this;
let devices_map = new Map(); let devices_map = new Map();
if (navigator.mediaDevices if (navigator.mediaDevices
&& navigator.mediaDevices.enumerateDevices && navigator.mediaDevices.enumerateDevices
&& navigator.mediaDevices.getUserMedia) { && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.enumerateDevices()
.then(function (devices) { let devices;
devices.forEach(function (device) { try {
if (device.kind === 'videoinput') { devices = await navigator.mediaDevices.enumerateDevices()
let id = device.deviceId; } catch (err) {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { console.log(err.name + ": " + err.message);
devices_map.set('environment', i18n.t('back-camera')); this.notSupported = true;
devices_map.set('user', i18n.t('front-camera')); return;
} else { }
devices_map.set(id ? id : true, device.label || i18n.t('camera') + (devices_map.size + 1));
} for (let device of devices) {
} if (device.kind === 'videoinput') {
}); let id = device.deviceId;
if (devices_map.size < 1) {
that.notSupported = true;
}
for (let [id, label] of devices_map) {
let opt = document.createElement("option");
opt.value = id;
opt.text = label;
that._('#videoSource').appendChild(opt);
}
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
that.activeCamera = 'environment'; devices_map.set('environment', i18n.t('back-camera'));
devices_map.set('user', i18n.t('front-camera'));
} else { } else {
that.activeCamera = devices_map.size ? Array.from(devices_map)[0][0] : ''; devices_map.set(id ? id : true, device.label || i18n.t('camera') + (devices_map.size + 1));
} }
}) }
.catch(function (err) { }
console.log(err.name + ": " + err.message);
that.notSupported = true; if (devices_map.size < 1) {
}); that.notSupported = true;
}
for (let [id, label] of devices_map) {
let opt = document.createElement("option");
opt.value = id;
opt.text = label;
that._('#videoSource').appendChild(opt);
}
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
that.activeCamera = 'environment';
} else {
that.activeCamera = devices_map.size ? Array.from(devices_map)[0][0] : '';
}
} else if (MediaStreamTrack && MediaStreamTrack.getSources) { } else if (MediaStreamTrack && MediaStreamTrack.getSources) {
this._log("MediaStreamTrack.getSources used"); this._log("MediaStreamTrack.getSources used");
const callback = sourceInfos => { const callback = sourceInfos => {
...@@ -155,7 +158,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -155,7 +158,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
else { else {
that.notSupported = true; that.notSupported = true;
} }
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment