From 7755a5e6a76777032a746c785f0228fb9a12e665 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 21 Mar 2022 17:04:22 +0100 Subject: [PATCH] Bug 6815: Display an error in if HTTPS not used and webcam unavailable Signed-off-by: Jonathan Druart --- .../intranet-tmpl/prog/js/patron-webcam.js | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-webcam.js b/koha-tmpl/intranet-tmpl/prog/js/patron-webcam.js index 0736bcb4350..3fd3e8732bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/patron-webcam.js +++ b/koha-tmpl/intranet-tmpl/prog/js/patron-webcam.js @@ -43,19 +43,25 @@ function startup() { camera = document.getElementById("camera"); uploadfiletext = document.getElementById("uploadfiletext"); - navigator.mediaDevices.getUserMedia({ - video: true, - audio: false - }) - .then(function (stream) { - video.srcObject = stream; - video.play(); + try { + navigator.mediaDevices.getUserMedia({ + video: true, + audio: false }) - .catch(function (err) { - $("#capture-patron-image").hide(); - $("#camera-error").css("display", "flex"); - $("#camera-error-message").text( showMediaErrors( err ) ); - }); + .then(function (stream) { + video.srcObject = stream; + video.play(); + }) + .catch(function (err) { + $("#capture-patron-image").hide(); + $("#camera-error").css("display", "flex"); + $("#camera-error-message").text( showMediaErrors( err ) ); + }); + } catch(err) { + $("#capture-patron-image").hide(); + $("#camera-error").css("display", "flex"); + $("#camera-error-message").text( showMediaErrors( err ) ); + } video.addEventListener('canplay', function () { if (!streaming) { @@ -108,6 +114,9 @@ function showMediaErrors( err ){ case "PermissionDeniedError": output = __("Access to camera denied."); break; + case "TypeError": + output = __("This feature is available only in secure contexts (HTTPS)."); + break; default: output = __("An unknown error occurred: ") + err; break; -- 2.25.1