<p><video autoplay="true" id="videoElement"></video></p>
<button type="button" id="start" onclick="cam_on()">Cam-on</button>
<script> var video = document.querySelector("#videoElement");
function cam_on() { stream = navigator.mediaDevices.getUserMedia({ video: true });
stream.then(function (value) { video.srcObject = value; }); } </script>
Writeup on my blog:
I found @Kirupa’s code, here, to be among the most concise that I’ve found; however, there was a slight logical fallacy with the .then implementation, which I addressed with a variable declaration rather conditional, as before. Hoping to hear @Kirupa’s thoughts.