var mediaStreamTrack;
function openMedia () {
const constraints = { audio: false, video: { width: 260, height: 260 } }
navigator.mediaDevices.getUserMedia(constraints)
.then(
(mediaStream) => {
const video = document.querySelector('video')
mediaStreamTrack = mediaStream
video.srcObject = mediaStream;
video.onloadedmetadata = (e) => { video.play() };
}
).catch((err) => { console.log(err.name + ": " + err.message) });
}
function closeMedia () {
mediaStreamTrack.getVideoTracks().forEach(track => {
track.stop();
})
}
function drawMedia () {
const video = document.getElementById('video')
const faceImg = document.getElementById('faceImg')
const canvas = document.createElement("canvas")
canvas.width = video.clientWidth
canvas.height = video.clientHeight
canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height)
const faceURL = canvas.toDataURL("image/png")
faceImg.src = faceURL
}