pc.removeStream(stream) 未实现 Firefox + WebRTC

pc.removeStream(stream) not implemented Firefox + WebRTC

如何从 Firefox 的对等连接中删除 MediaStream? API 说方法 pc.removeStream(stream) 存在但是当我使用它时,我收到错误:"removeStream not implemented"

我查了一个解决方案但是我不明白replaceTrack()函数的用法。我不想将一个音轨替换为另一个音轨,而且我不知道如何让它工作..

我的理解是 Firefox 尚未实现从 PeerConnection 添加/删除流,但您可以添加/删除曲目(RTCRtpSender in this case) from within a single mediastream, so when you look at jib's 从输入媒体流中获取所有曲目,检查 peerconnection 的媒体流是否包含这些曲目,删除它们(如果存在):

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

或者基本上你可以只用他的 polyfill:

window.mozRTCPeerConnection.prototype.removeStream = function(stream) {
  this.getSenders().forEach(sender =>
      stream.getTracks().includes(sender.track) && this.removeTrack(sender));
}