@ -98,7 +98,52 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr
var c = { audio : convertConstraints ( constraints . audio ) , video : convertConstraints ( constraints . video ) } ;
var c = { audio : convertConstraints ( constraints . audio ) , video : convertConstraints ( constraints . video ) } ;
// mediaDevices API returns a promise.
// mediaDevices API returns a promise.
console . log ( "Constraints for mediaDevices" , c ) ;
console . log ( "Constraints for mediaDevices" , c ) ;
window . navigator . mediaDevices . getUserMedia ( c ) . then ( success ) . catch ( error ) ;
window . navigator . mediaDevices . getUserMedia ( c ) . then ( success ) . catch ( function ( err ) {
if ( ! navigator . mediaDevices . enumerateDevices ) {
// Don't know how to check for available devices.
error ( err ) ;
return ;
}
// gUM fails if one of audio/video is not available, check which devices are
// available and retry with updated constraints.
console . log ( "getUserMedia with audio/video contraints failed" , err ) ;
navigator . mediaDevices . enumerateDevices ( ) . then ( function ( devices ) {
var has _audio = false ;
var has _video = false ;
console . log ( "Available devices" , devices ) ;
_ . each ( devices , function ( device ) {
switch ( device . kind ) {
case "audioinput" :
has _audio = true ;
break ;
case "videoinput" :
has _video = true ;
break ;
default :
break ;
}
} ) ;
if ( ! has _audio && ! has _video ) {
// No audio or video device found, no need to retry gUM.
error ( err ) ;
return ;
}
if ( ! has _audio ) {
delete c . audio ;
}
if ( ! has _video ) {
delete c . video ;
}
console . log ( "Retry getUserMedia with updated constraints" , c ) ;
window . navigator . mediaDevices . getUserMedia ( c ) . then ( success ) . catch ( error ) ;
} ) . catch ( function ( devicesError ) {
console . log ( "Could not enumerate devices" , devicesError ) ;
// Fail initial gUM
error ( err ) ;
} ) ;
} ) ;
}
}
} else {
} else {
// Use existing adapter.
// Use existing adapter.