title: How should (Android) / Chrome getUserMedia() constraints be formatted?
body: <p>I've been trying to access the rear camera on an LG G4 Android phone running Chrome. I'm able to filter out the video sources from <code>MediaStreamTrack.getSources()</code>, but when I try to set a constraint to prefer the rear camera, I get the error <code>TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': Malformed constraints object.</code> Below I have the code I'm using to filter the video sources:</p>
  
  <pre><code>if (navigator.getUserMedia) {
    if (MediaStreamTrack.getSources) {
      MediaStreamTrack.getSources(function(sourceInfos) {
        var sources = [];
        _.forEach(sourceInfos, function(info) {
          if (info.kind === 'video') {
            sources.push(info);
          }              
        })
        handleSources(sources);
      })
    }
  }
  </code></pre>
  
  <p>Then I'm trying to select a source in the <code>handleSources</code> function mentioned above:</p>
  
  <pre><code>function handleSources(sources) {
    var constraints = {
      video: {
        facingMode: 'environment' // Yeah, this definitely doesn't work.
      }
    }
    getMedia(constraints); // This calls getUserMedia with the selected contraints
  }
  </code></pre>
  
  <p>I've tried tons of different formats for the constraints object, but none of them seem to work. I know I'd be able to loop through all the sources and select the environmental camera from there, but I'd love to know how the actual syntax for this works. Googling for the answer only brings up <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Parameters" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Parameters</a>, the syntax of which doesn't work.</p>