小编874*_*236的帖子

参数为 null 的 addIceCandidate 导致错误

我正在尝试学习 WebRTC,我已经实现了在同一页面中连接两个 RTCPeerConnection,现在我试图将它们分成两个单独的页面并连接它们。但是,在编写代码并交换报价和​​答案后,我注意到initiator.html 上的 addIceCandidate() 将始终使用 null 参数抛出此问题

Error at addIceCandidate from queue: TypeError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': Candidate missing values for both sdpMid and sdpMLineIndex at processCandidateQueue (initiator.html:69)

经过一些阅读,我了解到 null 用于表示 ICE Candidate 收集完成,示例如下:https : //webrtc.github.io/samples/src/content/peerconnection/pc1/ 收集完成时也执行带有参数 null 的“addIceCandidate” . 但我不明白为什么我会看到我此时看到的错误。

我试过的:

  1. 我曾试图写一个检查,如果候选人为空,跳过 addIceCandidate。
  2. 将所有连接逻辑放在较少的按钮中以减少函数调用之间的延迟
  3. 将adapter-latest.js 添加到每个页面

结果:

  1. 发起方连接状态为“失败”,接收方连接状态为“新建”。无法流式传输到接收器页面。
  2. 抛出了同样的错误
  3. 错误消失了,但连接仍然失败

发起者.html

<!doctype html>
<html lang="en">
  <head>
    <title>First WebRTC Project</title>
        <link href="common.css" rel="stylesheet" />
  </head>
  <body>
        <div class="log-display"></div>
        <div class="func-list">
            Initiating host
            <div class="func">
                <button onclick="onPrepareMedia(this)">Prepare …
Run Code Online (Sandbox Code Playgroud)

javascript webrtc rtcpeerconnection

3
推荐指数
1
解决办法
3539
查看次数

标签 统计

javascript ×1

rtcpeerconnection ×1

webrtc ×1