
Request the user to start their webcam stream
- Using the getUserMedia() API which allows you to access a user’s camera and mic without any plugins
- Streams have inputs (video) and outputs (video)
- The if-conditional checks if the
getUserMedia
is supported - Syntax:
navigator.mediaDevices.getUserMedia(constraints).then(successCallback).catch(errorCallback)
- The
getUserMedia()
method takes one argument called theMediaStreamConstraints
object which allows you to specify the constrains/specifications of the media . In this casevideo
is set totrue
Media.getUserMedia()
returns then method which returns a promise which will take 2 parameter:
- a callback function which resolves to a media stream object, in this case video
- failure function for a failure
- If there is is an error, or the user refuses to give permission to access the webcam then ‘error’ is logged to the console