title: How to use HTMLMediaElement.srcObject = stream
body: <p>I've been scouring the web and S/O for answers as to why the following code does not work, but so far no dice. It is supposed to simply stream the user's video and audio. I am viewing it in Chrome.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
    &lt;video width="400" height="400" id="userVideo"&gt;&lt;/video&gt;
  &lt;script&gt;
  var userStream;
  if(navigator.mediaDevices.getUserMedia) {
                  //both video and audio
                    navigator.mediaDevices.getUserMedia({
                      video: true,
                      audio: true,
                    }, function(stream) {
                        console.log("got the stream");
                        userStream = stream;
  
                        document.getElementById("userVideo").srcObject = userStream;
  
                    });
                }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  </code></pre>