In this episode, we finally start working with capturing a webcam stream straight from the browser! After all the setup work, it's time to get hands-on. We'll be working in our create
page, and the first step is just dropping in some buttons with Breeze's primary button component – keeping things nice and simple.
You'll see how to wire up a button to trigger the webcam using the JavaScript Media API (navigator.mediaDevices.getUserMedia
). We talk through the API options, why webcam and screen capture are handled differently, and test that the browser requests permission as expected. Once the stream is approved, you’ll see how we can live-preview what the webcam sees.
We create a video element to show the stream, set up a Vue ref for it, and hook everything together so the camera output appears right away. Along the way, we refactor to use Vue's reactive state and computed properties to control what the user sees (like hiding the capture buttons once the webcam is on). We use a watcher to make sure the video element always gets updated when the webcam stream becomes available.
There’s a tricky issue with refs and Vue rendering, but we fix it by switching from v-if
to v-show
so everything hooks up properly. By the end, you'll have a solid, reactive UI for starting webcam capture and streaming it live to the page. Next up: doing the same thing for capturing the screen!