title: WebRTC: Switch camera
body: <p>I want to be able to switch the camera while in the middle of a conversation with WebRTC, without <strong>renegotiating</strong> the call.</p>
  
  <p>Suppose we have 2 "mediaSources" objects using the <code>MediaStreamTrack.getSources</code> method:</p>
  
  <pre><code>{
      id: "id_source_1" | "id_source_2",
      facing: "user" | "environment",
      kind: "kind_1" | "kind_2",
      label: "label_1" | "label_2"
   }
  </code></pre>
  
  <p>We start the call with "source_1" (facing the "user"), and we want the user to be able to switch to "source_2" (facing the "environment").</p>
  
  <p>In my current code when the user clicks the "switch camera" button the following is executed: (<code>callingSession</code> is the current WebRTC session)</p>
  
  <pre><code>var mediaParams = {
         audio: true,
         video: { deviceId : source_2.id},
         options: {
             muted: true,
             mirror: true
         },
         elemId: 'localVideo'
  };
  
  callingSession.getUserMedia(mediaParams, function (error, stream) {
  if (error) {
     console.error('error getting user media');
  } else {
            var oldVideoTracks = callingSession.localStream.getVideoTracks();      
            var newVideoTracks = stream.getVideoTracks();
  
            if (oldVideoTracks.length &gt; 0 &amp;&amp; newVideoTracks.length &gt; 0) {
                 callingSession.localStream.removeTrack(oldVideoTracks[0]);
                 callingSession.localStream.addTrack(newVideoTracks[0]);
            } 
         }
   });
  </code></pre>
  
  <p>As you can see the <code>mediaParams</code> constraints is now set to the "source_2", we pass this <code>mediaParams</code> with new constraints to the <code>getUserMedia</code> method. Then we get the video tracks from both the old and the new stream.</p>
  
  <p>The main problem in this code, is that the old stream is still exactly the same as the new stream, even with the new constraints passed to the <code>getUserMedia</code> method, so obviously the same video tracks, and of course nothing happens, and the camera is not switched !!!</p>
  
  <p>Am I doing something wrong in this code ? is there any way to switch the camera without without <strong>renegotiating</strong> the call in WebRTC ? what about the experimental method <code>applyConstraint()</code> I am not able to see it in chrome ?</p>
  
  <p>Thank you.</p>
  
  <p><strong>UPDATE</strong>
  My WebRTC app is an ionic app with crosswalk => the webview is chrome</p>