title: How to automatically stream remote cam in WebRTC?
body: <p>So far I have successfully established (running node.js server) an RTC connection between two peers with a datachannel. I can send data back and forth.</p>
  
  <p>I have also successfully streamed the webcam from one peer to another and vice versa. 
  How exactly am I doing this? </p>
  
  <p>Both peers do this:</p>
  
  <pre><code>function handleRemoteStreamAdded(event) {
    console.log('Remote stream added.');
    remoteStream = event.stream;
    remoteVideo.srcObject = remoteStream;
  }
  
  function gotStream(stream){
   ...
   pc.addStream(stream);
   ...
  }
  
  navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(err);
   ...
  pc = new RTCPeerConnection();
   ...
  pc.onaddstream = handleRemoteStreamAdded;
  </code></pre>
  
  <p>So I basically say that whenever I add my own stream (pc.addStream) then go to handleRemoteStreamAdded. It all works fine.</p>
  
  <p>But what I really want to do as a next step is to add a button to each client and give each of them the option whether or not they want to stream their cam to the other side. If they want to, then the stream should start automatically on the other end. Unfortunately, I just can't figure out how to.</p>
  
  <p>Theoretically, what I thought is to add an Eventlistener to a button and then the event triggers:</p>
  
  <pre><code>navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(err);
  </code></pre>
  
  <p>By doing this I basically also did <code>pc.addStream(stream);</code> via <code>function gotStream</code>. Then I send a message to the other end like "display my cam" and by receiving this message on the other end, that other peer should somehow trigger <code>handleRemoteStreamAdded</code>. But within this function there is the pre-defined <code>event</code> that I can only "access" locally via <code>pc.onaddstream = handleRemoteStreamAdded;</code></p>
  
  <p>How can I automatically start streaming the other side's cam as soon as I either get a message like "display my cam" or by some event?</p>