为什么 onnegotiationneeded 只触发一次?

时间:2021-08-01 17:17:38

标签: javascript webrtc simple-peer

我正在将 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 }))
    }
  }

1 个答案:

答案 0 :(得分:0)

事实证明,swift build -Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphonesimulator --show-sdk-path)" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator" 仅在 onnegotiationneededremoveTrack 处触发一次,并且无法检测到更多其他轨道。因此我最终通过一个

重新建立了连接
addTrack