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

CB-10502 Fix camera plugin exception in Chrome when click capture. #161

Merged
merged 1 commit into from Feb 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/browser/CameraProxy.js
Expand Up @@ -37,7 +37,7 @@ function takePicture(success, error, opts) {
var imageData = readerEvent.target.result;

return success(imageData.substr(imageData.indexOf(',') + 1));
}
};

reader.readAsDataURL(inputEvent.target.files[0]);
};
Expand All @@ -60,18 +60,25 @@ function capture(success, errorCallback) {
// create a canvas and capture a frame from video stream
var canvas = document.createElement('canvas');
canvas.getContext('2d').drawImage(video, 0, 0, 320, 240);

// convert image stored in canvas to base64 encoded image
var imageData = canvas.toDataURL('img/png');
imageData = imageData.replace('data:image/png;base64,', '');

// stop video stream, remove video and button
localMediaStream.stop();
// stop video stream, remove video and button.
// Note that MediaStream.stop() is deprecated as of Chrome 47.
if (localMediaStream.stop) {
localMediaStream.stop();
} else {
localMediaStream.getTracks().forEach(function (track) {
track.stop();
});
}
video.parentNode.removeChild(video);
button.parentNode.removeChild(button);

return success(imageData);
}
};

navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
Expand All @@ -85,7 +92,7 @@ function capture(success, errorCallback) {

document.body.appendChild(video);
document.body.appendChild(button);
}
};

if (navigator.getUserMedia) {
navigator.getUserMedia({video: true, audio: true}, successCallback, errorCallback);
Expand Down