Skip to content

Commit

Permalink
now the super search is refactored to choose the first webcam if ther…
Browse files Browse the repository at this point in the history
…e are possibly multiple
  • Loading branch information
mantzaris committed May 30, 2024
1 parent f915a2e commit 63091df
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions AppCode/taga-JS/super-search/super-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 139,7 @@ document.getElementById('return-to-main-button-id').onclick = function () {
};

//using the WEBCAM
document.getElementById('use-webcam-button-id').onclick = function () {
document.getElementById('use-webcam-button-id').onclick = async function () {
let modal_meme_click_top_id_element = document.getElementById('modal-meme-clicked-top-id');
modal_meme_click_top_id_element.style.display = 'block';
document.getElementById('webcam-video-id').style.display = 'block';
Expand Down Expand Up @@ -173,18 173,38 @@ document.getElementById('use-webcam-button-id').onclick = function () {

let captured = false;

navigator.mediaDevices
.getUserMedia({ video: true, audio: false })
.then(function (s) {
stream = s;
video.srcObject = stream;
video.play();
})
.catch(function (err) {
console.log('An error occurred: ' err);
alert('Could not access the webcam. Please check if it is connected and try again.');
Close_Modal();
});
// navigator.mediaDevices
// .getUserMedia({ video: true, audio: false })
// .then(function (s) {
// stream = s;
// video.srcObject = stream;
// video.play();
// })
// .catch(function (err) {
// console.log('An error occurred: ' err);
// alert('Could not access the webcam. Please check if it is connected and try again.');
// Close_Modal();
// });

try {
const devices = await navigator.mediaDevices.enumerateDevices();
const videoDevices = devices.filter(device => device.kind === 'videoinput');

if (videoDevices.length === 0) {
throw new Error('No webcams found.');
}

const firstWebcamId = videoDevices[0].deviceId;
stream = await navigator.mediaDevices.getUserMedia({ video: { deviceId: { exact: firstWebcamId } }, audio: false });
video.srcObject = stream;
video.play();
} catch (err) {
console.log('An error occurred: ' err);
alert('Could not access the webcam. Please check if it is connected and try again.');
Close_Modal();
return;
}


let streaming;
video.addEventListener(
Expand Down

0 comments on commit 63091df

Please sign in to comment.