title: Using AttachMediaStream with React Render Method?
body: <p>I'm working on integrating AttachMediaStream into a program that uses React.</p>
  
  <p>I can attach a media stream to an element like so:</p>
  
  <pre><code>var vid = document.getElementById("myVideo");
  attachMediaStream(vid, stream);
  </code></pre>
  
  <p>But that's outside of the React Render method, where I <em>think</em> something like this should happen. </p>
  
  <p>If I put it, as is, <em>inside</em> the React Render method, it would run every time the Render method runs. </p>
  
  <p>Here's one approach that occurs to me:</p>
  
  <ul>
  <li>Add two variable to the component: 
  
  <ul>
  <li>this.mediaStreamNeedsToBeAttached</li>
  <li>this.props.mediaStream</li>
  </ul></li>
  <li>Note that <code>this.mediaStreamNeedsToBeAttached</code> is not part of <code>this.state</code> or <code>this.props</code>. If it was, it wouldn't be legal to toggle it inside the Render method.</li>
  <li>When a mediastream is obtained, the component:
  
  <ul>
  <li>sets <code>this.mediaStreamNeedsToBeAttached</code> to true;</li>
  <li>runs <code>this.setProps({ mediaStream: newlyObtainedMediaStream });</code> causing the Render method to run.</li>
  </ul></li>
  <li>The Render method:
  
  <ul>
  <li>Checks to see if <code>this.mediaStreamNeedsToBeAttached</code> is true</li>
  <li>If so, runs <code>attachMediaStream(vid, this.props.mediaStream)</code> and toggles <code>this.mediaStream</code></li>
  </ul></li>
  </ul>
  
  <p>I <em>guess</em> that will work, but I thought I'd check here to see if anyone else has a more elegant solution. </p>
  
  <p>Any thoughts or input would be appreciated!</p>