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