Skip to content

Commit 2e33ed5

Browse files
committed
Update to navigator.mediaDevices
untested
1 parent 49f1e3d commit 2e33ed5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/input/camera_access.js

+35
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@ var streamRef,
99
* @param {Object} success Callback
1010
* @param {Object} failure Callback
1111
*/
12+
13+
function getUserMedia(constraints, success, failure) {
14+
if(navigator.mediaDevices){
15+
if(navigator.mediaDevices.enumerateDevices){
16+
var flag=false;
17+
navigator.mediaDevices.enumerateDevices().then(function(devices){
18+
devices.forEach(function(device){
19+
if(device.kind=="videoinput"){
20+
flag=true;
21+
}
22+
})
23+
})
24+
if (flag){
25+
navigator.mediaDevices.getUserMedia(constraints)
26+
.then(function(mediaStream) {
27+
streamRef = mediaStream;
28+
var videoSrc = (window.URL && window.URL.createObjectURL(mediaStream)) || mediaStream;
29+
success.apply(null, [videoSrc]);
30+
})
31+
.catch(function(error) {
32+
failure(new TypeError("Problem with mediaStream"));
33+
})
34+
} else {
35+
failure(new TypeError("Webcam not available"));
36+
}
37+
} else {
38+
failure(new TypeError("mediaDevices.enumerateDevices not available"));
39+
}
40+
} else {
41+
failure(new TypeError("mediaDevices not available"));
42+
}
43+
}
44+
45+
/*
1246
function getUserMedia(constraints, success, failure) {
1347
if (typeof navigator.getUserMedia !== 'undefined') {
1448
navigator.getUserMedia(constraints, function (stream) {
@@ -20,6 +54,7 @@ function getUserMedia(constraints, success, failure) {
2054
failure(new TypeError("getUserMedia not available"));
2155
}
2256
}
57+
*/
2358

2459
function loadedData(video, callback) {
2560
var attempts = 10;

0 commit comments

Comments
 (0)