【问题标题】:webrtc onicecandidate event triggerwebrtc onicecandidate 事件触发器
【发布时间】: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


    【解决方案1】:

    一个可能的答案可能是在第一种情况下没有连接到连接的 MediaStreamTracks

    【讨论】:

      猜你喜欢
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多