【发布时间】:2021-05-18 22:14:17
【问题描述】:
我想知道为什么 webrtc 有这种行为: 创建对等连接后,我声明了 onicecandidate 事件处理程序,它将 conosle 记录连接的本地描述。然后我创建一个报价并将返回的 sdp 设置为连接的本地描述。事件处理程序被触发,但是本地描述永远不会被控制台记录。但是,每当我在创建报价之前创建数据通道时,控制台都会返回本地描述。有人可以向我解释为什么会这样吗?
没有数据通道的例子
const lc = new RTCPeerConnection();
lc.onicecandidate = e => console.log(JSON.stringify(lc.localDescription));
lc.createOffer().then(o=>lc.setLocalDescription(o)).then(console.log('offer set'))
控制台返回: 承诺{}
数据通道示例
const lc = new RTCPeerConnection();
lc.onicecandidate = e => console.log(JSON.stringify(lc.localDescription));
lc.createDataChannel("xan")
lc.createOffer().then(o=>lc.setLocalDescription(o)).then(console.log('offer set'))
控制台返回:Promise {},localDescription
【问题讨论】:
标签: javascript networking connection webrtc peer