2

我正在添加tracks到我的同行,第一次onnegotiationneeded触发就好了。但是,在添加更多时tracks onnegotiationneeded不会触发,因此新tracks的不会显示任何效果。这是我正在使用的代码的主要部分:

  const { id } = req.params
  peer[id] = new webrtc.RTCPeerConnection()
  const guest = { id, name: '', tracks: [], room }
  guest.tracks.forEach(t => peer[host.id].addTrack(t))

  const createNegotiation = async (peerID) => {
    peer[peerID].onnegotiationneeded = async () => {
      console.log('onnegotiationneededonnegotiationneeded')
      const offer = await peer[peerID].createOffer()
      await peer[peerID].setLocalDescription(offer)
      dc.send(JSON.stringify({ type: 'onnegotiationneeded', "sdp": peer[peerID].localDescription }))
    }
  }
4

1 回答 1

-2

事实证明,它只会在或onnegotiationneeded处触发一次,并且无法检测到更多的额外轨迹。因此,我最终通过removeTrackaddTrack

  const reNew = async (peerID) => {
      console.log('RENEW WITH PEER ID '  , peerID)
      const offer = await peer[peerID].createOffer()
      await peer[peerID].setLocalDescription(offer)
      peer[peerID].dcm.send(JSON.stringify({ type: 'RENEW', "sdp": peer[peerID].localDescription }))
  }
于 2021-08-03T19:57:45.347 回答