I have the following JavaScript source code which I retrieved from the https://www.studytonight.com/post/capture-photo-using-webcam-in-javascript link:
function startup() {
video = document.getElementById('video');
canvas = document.getElementById('canvas');
photo = document.getElementById('photo');
startbutton = document.getElementById('startbutton');
// access video stream from webcam
navigator.mediaDevices.getUserMedia({
video: true,
audio: false
})
// on success, stream it in video tag
.then(function(stream) {
video.srcObject = stream;
video.play();
})
.catch(function(err) {
console.log("An error occurred: " + err);
});
My question is what is happening with the following part of this source code:
.then(function(stream) {
video.srcObject = stream;
video.play();
})
.catch(function(err) {
console.log("An error occurred: " + err);
});
Can someone please explain what the .then(function(stream) section is doing in this particular case? Thank you.