我正在尝试学习 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” . 但我不明白为什么我会看到我此时看到的错误。
我试过的:
结果:
发起者.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)