I’m attempting to draw a video along with a few shapes using p5.js on a React app.
I’ve noticed that p5.dom.js is not available for React and probably for good reason. This stopped me from using createCapture(VIDEO)
so I went ahead and used getUserMedia
to get the camera working.
The issue is that p5 is expecting a p5.Image|p5.Element
when I add sketch.image(video, 0,0, w, h)
, which I’m not quite sure how to get around that. Any thoughts would be appreciated!
class Stream extends Component {
constructor() {
super();
this.video = React.createRef();
}
componentDidMount() {
const sketch = new p5()
sketch.createCanvas(640, 480)
// Cannot import p5.dom.
// sketch.createCapture(p5.VIDEO)
const video = this.video.current
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
.then((stream) => {
video.srcObject = stream
video.play()
})
.catch(function(err) {
console.log("An error occurred! " + err)
})
}
[continues...]