0

How can I remove a MediaStream from a peer connection in Firefox? The API says that the method pc.removeStream(stream) exists but when I use it, I receive the error: "removeStream not implemented"

I checked a solution here but I didn't understand the usage of the replaceTrack() function. I wan't to replace one audio track with another, and I can't figure out how to make it work ..

Community
  • 1
  • 1
power.ponch
  • 43
  • 1
  • 7
  • 1
    Follow this link, might solve your problem. http://stackoverflow.com/questions/31338235/webrtc-renegotiation-in-firefox – Karthik Oct 22 '15 at 07:31
  • Thanks. I've already checked it but I didn't understand the arguments to pass to the replaceTrack() function. I haven't found it in any API, though – power.ponch Oct 22 '15 at 23:23

1 Answers1

1

my understanding is Firefox is yet to implement adding/ removing streams from an PeerConnection, but you can add/ remove tracks( RTCRtpSender in this case) from within a single mediastream, so when you look at jib's answer takes all the tracks from input mediastream, checks if peerconnection's mediastream contains those tracks, removes them if present:

function removeTrack(pc, stream){
  pc.getSenders().forEach(function(sender){
    stream.getTracks.forEach(function(track){
      if(track == sender.track){
        pc.removeTrack(sender);
      }
    })
  });
}

or basically you can just his polyfill:

window.mozRTCPeerConnection.prototype.removeStream = function(stream) {
  this.getSenders().forEach(sender =>
      stream.getTracks().includes(sender.track) && this.removeTrack(sender));
}
Community
  • 1
  • 1
mido
  • 24,198
  • 15
  • 92
  • 117
  • 1
    Firefox does support `addStream` for backwards compatibility, but will probably [never](http://stackoverflow.com/a/31356795/918910) implement `removeStream`, as these methods are longer in the spec. Streams are out, tracks are in. – jib Jan 13 '17 at 21:27