How do I bind the output of a webcam to the srcObject attribute of a video element in Aurelia?
I have the following video element in my HTML
<video id="video" srcObject.bind="cameraStream" if.bind="cameraStream">Video stream not available.</video>
In my JavaScript file, I have the following
activate() {
navigator.mediaDevices.getUserMedia({video: true, audio: false})
.then((stream) => {
this.cameraStream = stream
console.log('this.cameraStream', this.cameraStream)
})
.catch((err) => {
console.error(`An error occurred:`, err)
})
}
The page asks for access to the webcam, and I've logged the value of this.cameraStream and I get the output below, but I'm not getting any content in the video object.
Thank you in advance for your help.

Ok, I figured it out.
Problem #1: I should have been using the
attachedhandler instead of theactivatehandler because the page object may not be loaded in theactivatehandler.Problem #2: I needed to use the
refattribute on the video element to reference the element in JS.Problem #3: I needed to remove the
if.bindbecause theref="video"attribute will not definethis.videoif the element is not present because ofif.bindevaluating to false.Here's the final working code.
HTML
JS