In my project I have WebRTC live stream which is drawn to canvas frame by frame like this:
//GET THE VIDEO STREAM
navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" }, audio: false })
.then(function(stream) {
video.srcObject = stream;
setTimeout(RunningVideo, 0);
})
.catch(function(error) {
console.error("Oops. Something is broken.", error);
});
//DRAW TO CANVAS
async function RunningVideo() {
context2d.drawImage(video, 0, 0, canvas2d.width, canvas2d.height);
src1.data.set(context2d.getImageData(0, 0, canvas2d.width, canvas2d.height).data);
cv.imshow("outputCanvas2d", src1);
let begin = Date.now()
let delay = 1000/FPS - (Date.now() - begin);
setTimeout(RunningVideo, delay);
var GoodMatch = await Myorb_split()
//further code
}
After some condition A is fullfilled I want to run an AR session as it is described here. However, for the time the AR session is running, I need to pause the WebRTC live stream. As far as I understand, to do that I need to pause the setTimeout() method itself. Please, correct me if I am wrong.
I would be very grateful if anyone could help me to understand how to pause the setTimeout(). Thank you.