I am developing an app where there will be two participant in a session and they can have video call. Basically, there will be 3 video stream. Two of the participants and one will be shared screen. This part is already working but when user clicks on record button, those 3 video should be fed in canvas and when paused then it should be paused. I am trying to render only one video in canvas for testing if it work "RangeError: Maximum call stack size exceeded on draw function ".
const draw = (canva, context) => {
console.log('localVideoRef', localVideoRef)
context.drawImage(localVideoRef.current, 0, 0, canva.clientWidth, canva.clientHeight);
console.log('context draw', context)
requestAnimationFrame(draw(canva, context))
}
const handleRecord = () => {
const canva = document.createElement('canvas');
canva.id = "canvas";
const context = canva.getContext("2d");
canva.width = canva.clientWidth;
canva.width = canva.clientHeight;
console.log('canva', context, canva);
console.log('room', room);
draw(canva, context);
requestAnimationFrame(draw(canva, context)) # above error is shown here
console.log('canva after drawing image', canva);
}
The error is in this line requestAnimationFrame(draw(canva, context))
Update(still continuously runs even after stopping the record)
let canva, context = null;
function App(props) {
const [record, setRecord] = React.useState('');
React.useEffect(() => {
canva = document.createElement('canvas');
canva.id = "canvas";
context = canva.getContext("2d");
canva.width = canva.clientWidth;
canva.width = canva.clientHeight;
}, [])
React.useEffect(() => {
console.log('record', record);
if (record === 'start' || record === 'resume') {
requestAnimationFrame(() => draw(canva, context));
console.log('canva after paint video', canva);
} else {
// when pausing or stoping recording, the painting should not be done.
console.log('this is the canva after paused or stopped', canva)
}
}, [record])
const draw = (canva, context) => {
context.drawImage(localMediaRef.current, 0, 0, canva.clientWidth, canva.clientHeight);
console.log('painting');
requestAnimationFrame(() => draw(canva, context));
}
const handleRecord = (type) => {
setRecord(type)
}
render {
return (
)
}
}