From 0d580adac3846ee05d183f96fcda81d031bede96 Mon Sep 17 00:00:00 2001
From: juanf <juanf@ethz.ch>
Date: Fri, 2 Jun 2023 12:04:40 +0200
Subject: [PATCH] SSDM-12100: Bugfix to support first time request for camera
 access in some browsers

---
 .../1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js  | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js
index de9787755b2..0cdba21a479 100644
--- a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js
+++ b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js
@@ -75,7 +75,11 @@ var BarcodeUtil = new function() {
                         codeReader.listVideoInputDevices().then((videoInputDevices) => {
                             // Add cameras to devices
                             for(var cIdx = 0; cIdx < videoInputDevices.length; cIdx++) {
-                                var $cameraInput = $("<input>", { id : "camera-" + (cIdx+1), name : "device", type : "radio", value : videoInputDevices[cIdx].deviceId });
+                                var cameraDeviceId = videoInputDevices[cIdx].deviceId;
+                                if(!cameraDeviceId) {
+                                    cameraDeviceId = "trust";
+                                }
+                                var $cameraInput = $("<input>", { id : "camera-" + (cIdx+1), name : "device", type : "radio", value : cameraDeviceId });
                                         $device.append($cameraInput);
                                         deviceInputs.push($cameraInput);
                                         $device.append($("<label>", { for : "camera-" + (cIdx+1),  onclick : "" }).append(videoInputDevices[cIdx].label));
@@ -190,7 +194,9 @@ var BarcodeUtil = new function() {
                             action(null, err);
                         }
                     };
-
+                    if(cameraDeviceId === "trust") {
+                        cameraDeviceId = null;
+                    }
                     codeReader.decodeFromVideoDevice(cameraDeviceId, 'video', decodeFromVideoDeviceCallback);
         });
     }
-- 
GitLab