title: WebRTC - addStream() to host connection
body: <p>I am trying to play audio from a file to a remote webrtc peer. I can get the peers connected and mic audio flows back and forth between them, no problem. However when I add an audio stream to the remote peer then the audio from the stream doesn't play on the remote peer's system. </p>
  
  <p>This is on Linux using Chrome 56 for the local system and Firefox 51 for the remote peer. </p>
  
  <p>The file loads into the buffer fine, I tested this by attaching a MediaRecorder and monitoring its ondataavailable() event, data is definitely going into buffer and on to the source_dest below.</p>
  
  <p>Here's the basic flow below. What am I doing wrong? </p>
  
  <p><strong>pc1</strong> is the localhost system's AudioContext already set up. The <strong>mic_stream</strong> below is the stream from pc1 calling getUserMedia(), which  gets the local mic. </p>
  
  <pre><code>// create a new stream source from the pc1 stream
  mic_patch = pc1.context.createMediaStreamSource( mic_stream );
  
  // create a new destination from the mic stream
  source_dest = pc1.context.createMediaStreamDestination();
  
  // create a new filter, we need this so that source_dest
  // creates a stream that we can add to pc2.
  biquadfilter = pc1.context.createBiquadFilter();
  biquadfilter.type = 'highpass';
  biquadfilter.frequency.value = 1500;
  
  // connect the mic_patch to the filter
  mic_patch.connect( biquadfilter );
  
  // connect the filter to the new source dest
  biquadfilter.connect( source_dest );
  </code></pre>
  
  <p>After <strong>pc2</strong> connects successfully to pc1, mic audio works between pc1 and pc2, all is good. Then I add the source_dest stream to pc2 (RTCPeerConnection), and when I examine pc2 via pc2.getLocalStreams() I see that the source_dest stream is connected. </p>
  
  <pre><code>pc2.addStream( source_dest.stream );
  </code></pre>
  
  <p>Then I load a file from disk into a buffer.</p>
  
  <p>At this point <strong>file</strong> in the code below is a File object loaded by using a HTML &lt;input type="file"&gt; field. When the file is selected that triggers the code below. </p>
  
  <p>I convert that to an AudioBuffer using FileReader and decode it to a buffer using createBufferSource() which is connected to the source_dest so buffer_source feeds its output into source_dest, then I start playing immediately via buffer_source.start(0)</p>
  
  <pre><code>reader = new FileReader(); 
  
  buffer_source = source_dest.context.createBufferSource();
  
  buffer_source.connect( source_dest );
  
  reader.onload = function(e) {
      var arrayBuffer = reader.result;
      Webcaster.node.context.decodeAudioData( arrayBuffer, function(buffer) {
  
          buffer_source.buffer = buffer;
  
          buffer_source.start(0);
  
          /** For testing to ensure the buffer data makes it into source_dest
          mediaRecorder = new MediaRecorder( source_dest.stream );
          mediaRecorder.ondataavailable = function(evt) {
              // push each chunk (blobs) in an array
              chunks.push(evt.data);
              // dump out the chunks array to ensure it receives buffer data successfully
              console.log( 'CHUNKS', chunks );
          };
          mediaRecorder.start();
          //stop recording after 10 seconds, no need to record longer,
          //this is only to test the source_dest connect and data flow
          //when recorders stop ondataavailable() will be triggered
          setTimeout( function() { mediaRecorder.stop() }, 10000 )
          **/
      })
  }
  
  reader.readAsArrayBuffer( file );
  </code></pre>
  
  <p>So all of that works, except that the audio data put into source_dest does not get played on the remote pc2. I've spent many hours trying to sort out why, so far no luck.</p>
  
  <p>Anybody have clues why? </p>