forked from aluchici/rau-webapps-24-25
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup2.js
25 lines (22 loc) · 1.12 KB
/
signup2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// elements from the signup-2.html
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const selfiePreview = document.getElementById('selfiePreview');
const captureSelfieButton = document.getElementById('captureSelfie');
const step2Form = document.getElementById('step2Form');
// activate camera
navigator.mediaDevices.getUserMedia({ video: true }) //ask for access the camera
.then(stream => {
video.srcObject = stream; //source of camera
})
.catch(err => {
console.error("Error accessing the camera: ", err);
alert("Unable to access camera. Please check your browser settings."); //message for user
});
// capture selfie when button clicked
captureSelfieButton.addEventListener('click', () => {
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height); //draw the current video in to the canvas
const selfieData = canvas.toDataURL('image/png'); //convert canvas content to a png data Url
//display captures selfie
selfiePreview.innerHTML = `<img src="${selfieData}" alt="Captured Selfie" />`;
});