JavaScript rób zdjęcie z kamery

const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const snap = document.getElementById('snap'); //Button
const constraints = {
  audio: false,
  video: {
    width: {
      // min: 1024,
      ideal: canvas.width,
      // max: 1920,
    },
    height: {
      // min: 576,
      ideal: canvas.height,
      // max: 1080,
    },
  }
}

async function startWebCam() {
  try {
    //getUserMedia() returns Promise
    const stream = await navigator.mediaDevices.getUserMedia(constraints);
    video.srcObject = stream;
    window.stream = stream;
  }
  catch (e) {
    console.log(e.toString());
  }
}

var context = canvas.getContext('2d');

snap.addEventListener('click', () => {
  context.drawImage(video, 0, 0, canvas.width, canvas.height);
});

startWebCam();
ofroog