JSFiddle - React, Tailwind, and code Playground
HTML
<button id="start">
start
</button>
<video autoplay="true" id="video"></video>
<button id="stop">
stop
</button>
JavaScript
let stream;
document.getElementById("start").onclick = async () => {
console.log('asd')
try {
stream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true
});
console.log('asd2')
document.getElementById("video").srcObject = stream;
} catch (e) {
console.log(e)
}
}
document.getElementById("stop").onclick = async () => {
stream.getTracks().foreach(track => track.stop())
}