src/browser/src/createQRScannerInternal.js
function getFirstResolvingConstraint(constraintsBestToWorst){
      return new Promise(function(resolveBestConstraints){
        // build a chain of promises which either resolves or continues searching
        return constraintsBestToWorst.reduce(function(chain, next){
          return chain.then(function(searchState){
            if(searchState.found){
              // The best working constraint was found. Skip further tests.
              return searchState;
            } else {
              searchState.nextConstraint = next;
              return window.navigator.mediaDevices.getUserMedia(searchState.nextConstraint).then(function(mediaStream){
                // We found the first working constraint object, now we can stop
                // the stream and short-circuit the search.
                killStream(mediaStream);
                searchState.found = true;
                return searchState;
              }, function(){
                // didn't get a media stream. The search continues:
                return searchState;
              });
            }
          });
        }, Promise.resolve({
          // kick off the search:
          found: false,
          nextConstraint: {}
        })).then(function(searchState){
          if(searchState.found){
            resolveBestConstraints(searchState.nextConstraint);
          } else {
            resolveBestConstraints(null);
          }
        });
      });
    }
function getFirstResolvingConstraint(constraintsBestToWorst){
      return new Promise(function(resolveBestConstraints){
        // build a chain of promises which either resolves or continues searching
        return constraintsBestToWorst.reduce(function(chain, next){
          return chain.then(function(searchState){
            if(searchState.found){
              // The best working constraint was found. Skip further tests.
              return searchState;
            } else {
              searchState.nextConstraint = next;
              return window.navigator.mediaDevices.getUserMedia(searchState.nextConstraint).then(function(mediaStream){
                // We found the first working constraint object, now we can stop
                // the stream and short-circuit the search.
                killStream(mediaStream);
                searchState.found = true;
                return searchState;
              }, function(){
                // didn't get a media stream. The search continues:
                return searchState;
              });
            }
          });
        }, Promise.resolve({
          // kick off the search:
          found: false,
          nextConstraint: {}
        })).then(function(searchState){
          if(searchState.found){
            resolveBestConstraints(searchState.nextConstraint);
          } else {
            resolveBestConstraints(null);
          }
        });
      });
    }
function getFirstResolvingConstraint ( constraintsBestToWorst ) { return new Promise ( function ( resolveBestConstraints ) { // build a chain of promises which either resolves or continues searching return constraintsBestToWorst . reduce ( function ( chain , next ) { return chain . then ( function ( searchState ) { if ( searchState . found ) { // The best working constraint was found. Skip further tests. return searchState ; } else { searchState . nextConstraint = next ; return window . navigator . mediaDevices . getUserMedia ( searchState . nextConstraint ) . then ( function ( mediaStream ) { // We found the first working constraint object, now we can stop // the stream and short-circuit the search. killStream ( mediaStream ) ; searchState . found = true ; return searchState ; } , function ( ) { // didn't get a media stream. The search continues: return searchState ; } ) ; } } ) ; } , Promise . resolve ( { // kick off the search: found : false , nextConstraint : { } } ) ) . then ( function ( searchState ) { if ( searchState . found ) { resolveBestConstraints ( searchState . nextConstraint ) ; } else { resolveBestConstraints ( null ) ; } } ) ; } ) ; }
create a promise which tries to resolve the best constraints for this deviceId rather than reject, failures return a value of `null`
create a promise which tries to resolve the best constraints for this deviceId rather than reject failures return a value of null