Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stopped redundant processing and fixed close button. #1797

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/ui/SetInputStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,48 @@ function setInputStepInit() {
video.onloadedmetadata = function(e) {
video.play();
};

document.getElementById('capture').addEventListener('click', function(stream){
context.drawImage(video, 0, 0, 400, 300);
options.onTakePhoto(canvas.toDataURL());
});

document.getElementById('close').addEventListener('click', function () {
stopStream(stream);
});
}
function handleError(error) {
console.log('navigator.getUserMedia error: ', error);

// when user dismissed the camera access (includes closing of prompt which requests for camera access)
if(error.message == 'Permission denied' || error.message == 'NotAllowedError' || error.message == 'PermissionDismissedError'){
document.getElementById('capture').addEventListener('click', function(e) {
alert('Enable camera access in order to take picture');
});
}

// when user don't have webcam to use.
if(error.message == 'NotFoundError' || error.message == 'DevicesNotFoundError'){
alert('You do not have appropriate devices to use this Functionality');
}

// when webcam is already used by some other application
if(error.message == 'NotReadableError' || error.message == 'TrackStartError' || error.message == 'Concurrent mic process limit'){
alert('Your webcam is already in use by some other application');
}

// when some of the requested constraints can't be satisfied like high frame rate or high resolution
if(error.message == 'OverconstrainedError' || error.message == 'ConstraintNotSatisfiedError'){
console.log('Requested Constraints can not be satisfied ', error);
}
}
navigator.mediaDevices.getUserMedia(constraints).then(handleSuccess).catch(handleError);


document.getElementById('capture').addEventListener('click', function(stream){
context.drawImage(video, 0, 0, 400, 300);
options.onTakePhoto(canvas.toDataURL());

document.getElementById('close').addEventListener('click', function() {
video.style.display = 'none';
});


function stopStream(stream) {
stream.getVideoTracks().forEach(function (track) {
track.stop();
Expand Down