@@ -9,6 +9,40 @@ var streamRef,
9
9
* @param {Object } success Callback
10
10
* @param {Object } failure Callback
11
11
*/
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
+ /*
12
46
function getUserMedia(constraints, success, failure) {
13
47
if (typeof navigator.getUserMedia !== 'undefined') {
14
48
navigator.getUserMedia(constraints, function (stream) {
@@ -20,6 +54,7 @@ function getUserMedia(constraints, success, failure) {
20
54
failure(new TypeError("getUserMedia not available"));
21
55
}
22
56
}
57
+ */
23
58
24
59
function loadedData ( video , callback ) {
25
60
var attempts = 10 ;
0 commit comments