onclick = () => {
  recording = !recording;
  file.disabled = recording ? 'disabled' : '';

  if (recording) {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }).then(function(stream) {
      video.srcObject = stream;
      video.setAttribute("playsinline", true);
      video.play();
      requestAnimationFrame(tick);
    });
  }
}




</script>

</body></html>
