Currently I am trying to find a way to record video from the webcam using WebRTC and getUserMedia. I managed to capture a video for a given time but what I wanted to do was to start recording on the first page of the application and keep recording until the user presses a certain button after several pages. Here what happens is when user goes to another page the recording stops even if time is not up.
I am kind of new to front end development and using Node.js. Is there a way for me to use the webcam globally through the application?
Here is the code I used for simple recording in HTML:
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then(async function(stream) {
let recorder = RecordRTC(stream, {
type: 'video'
});
recorder.startRecording();
const sleep = m => new Promise(r => setTimeout(r, m));
await sleep(10000);
recorder.stopRecording(function() {
let blob = recorder.getBlob();
invokeSaveAsDialog(blob);
var url = URL.createObjectURL(blob);
document.querySelector("video").src = url;
});
});