Web RTC 连接未建立

Web RTC connection is not established

当我运行此代码连接未建立时,

您需要一个用于对等连接上的 ICE 候选者的侦听器,并将其应用于另一个对等点。

localconn.onicecandidate = function(event) {
  if (event.candidate) {
    remoteconn.addIceCandidate(event.candidate);
  } else {
    // All ICE candidates have been sent
  }
}

remoteconn.onicecandidate = function(event) {
  if (event.candidate) {
    localconn.addIceCandidate(event.candidate);
  } else {
    // All ICE candidates have been sent
  }
}

另见 https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onicecandidate