<aside> 💡 Request the user to start their webcam stream
</aside>
HTML
<video autoplay="true" id="videoElement">
JavaScript
var video= document.querySelector("#videoElement");
if(navigator.mediaDevices.getUserMedia){
navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (error) {
console.log("Error streaming");
});
}
getUserMedia()
API which allows you to access a user's camera and mic without any pluginsgetUserMedia
is supportednavigator.mediaDevices.getUserMedia(constraints).then(successCallback).catch(errorCallback)
getUserMedia()
method takes one argument called the MediaStreamConstraints
object which allows you to specify the constrains/specifications of the media . In this case video
is set to true
Media.getUserMedia()
returns then method which returns a promise which will take 2 parameter:Resources:
http://www.medien.ifi.lmu.de/lehre/ws1920/omm/uebung/folien/OMM-10-Media-Streaming.pdf