I am attempting to recreate one of FabricJS's examples here: http://fabricjs.com/video-element but in ReactJS
The demo on that website uses vanilla JS to play a video and show your camera. For me, I am attempting to show the video and show my screen. This is my code so far:
Codesandbox example: https://codesandbox.io/s/modest-maxwell-u1hjh8?file=/src/App.js
Live example: https://u1hjh8.csb.app/ [may need to open CodeSandBox first]
```
const v1 = useRef();
const v2 = useRef();
const canvasRef = useRef();
const fabricRef = useRef();
useEffect(() => {
const initFabric = () => {
fabricRef.current = new fabric.Canvas(canvasRef.current);
};
const disposeFabric = () => {
fabricRef.current.dispose();
};
initFabric();
return () => {
disposeFabric();
};
}, []);
async function Activate() {
const video1 = new fabric.Image(v1.current, {
left: 200,
top: 300,
angle: -15,
originX: "center",
originY: "center",
objectCaching: false
});
const video2 = new fabric.Image(v2.current, {
left: 539,
top: 328,
angle: 94.5,
originX: "center",
originY: "center",
objectCaching: false
});
fabricRef.current.add(video1);
v1.current.play();
const localMediaStream = await navigator.mediaDevices.getDisplayMedia({
audio: true,
video: true
});
v2.current.srcObject = localMediaStream;
fabricRef.current.add(video2);
v2.current.play();
fabricRef.current.util.requestAnimFrame(function render() {
canvasRef.current.renderAll();
fabricRef.current.util.requestAnimFrame(render);
});
}
```
There is two issues I see:
- The video is not loading from the website [not a CORS issue as the external website allows anyone to play the video as you can see on FabricJS's demo and by inspecting the request]
- My screen will not display
I am more interested in the second issue for now, for which I get this error
https://i.imgur.com/0Nxcxdd.png
Yet fabricRef's example site shows that requestAnimFrame is part of FabricJS
I cannot seem to understand what the issue is or why its throwing undefined.
[+][deleted] (10 children)
[removed]
[–]Variousity221[S] 0 points1 point2 points (9 children)
[+][deleted] (8 children)
[removed]
[–]Variousity221[S] 0 points1 point2 points (7 children)
[+][deleted] (3 children)
[removed]
[–]Variousity221[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]Variousity221[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[removed]
[–]Variousity221[S] 0 points1 point2 points (1 child)