I found a code in the google that I can enable my webcam, but I would like to write a function that record the video and save in my directory server automatically when I stop it. My code:
index.html
<head>
<title>CAM</title>
<script src="script.js"></script>
<link href="style.css" rel="stylesheet">
</head>
<body onload="main()">
<canvas id="myCanvas"></canvas>
<button id ="record">Record</button>
<button id ="stop">Stop</button>
</body>
Script.js
let VIDEO = null;
let CONTEXT = null;
function main(){
CANVAS = document.getElementById("myCanvas");
CONTEXT = CANVAS.getContext("2d");
CANVAS.width = window.innerWidth;
CANVAS.height = window.innerHeight;
let promise = navigator.mediaDevices.getUserMedia({video:true});
promise.then(function(signal){
VIDEO = document.createElement("video");
VIDEO.srcObject = signal;
VIDEO.play();
VIDEO.onloadeddata = function(){
updateCanvas();
}
}).catch(function(err){
alert("Camera error: "+err);
})
}
function updateCanvas(){
CONTEXT.drawImage(VIDEO, 0, 0);
window.requestAnimationFrame(updateCanvas);
}
Someone can help me?