协商完成后,远程上的WebRTC调用仍不工作

协商完成后,远程上的WebRTC调用仍不工作,webrtc,rtcpeerconnection,Webrtc,Rtcpeerconnection,我已经编写了在Web上接收WebRTC调用的代码,该调用由mobile(Android/IOS)发起。当我在同一个网络中使用手机和笔记本电脑时,它可以正常工作,但当它们在不同的网络上时,对等连接大部分时间都会失败,有时对等连接的信令状态也会失败 这是我的密码 getPeerConnection() { //RTCPeerConnection const servers = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }]

我已经编写了在Web上接收WebRTC调用的代码,该调用由mobile(Android/IOS)发起。当我在同一个网络中使用手机和笔记本电脑时,它可以正常工作,但当它们在不同的网络上时,对等连接大部分时间都会失败,有时对等连接的信令状态也会失败

这是我的密码

 getPeerConnection() { //RTCPeerConnection
const servers = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }] }
this.peerConnection=null;
this.peerConnection = new RTCPeerConnection(servers);
this.dataChannelService.createDataChannel(this.peerConnection)
console.log(this.peerConnection);
this.addMediaToPeerConnection();

this.peerConnection.addEventListener('connectionstatechange', (event) => {
  console.log(this.peerConnection);
  console.log(event);
  
  if (this.peerConnection.connectionState == "connected")
    this.callStatus = CallStatus.CONNECTED;
  if (this.peerConnection.connectionState  == "failed" || this.peerConnection.connectionState  == "closed" ){this.disconnectCall();
  }
})

//set local description & create offer
this.peerConnection.addEventListener('negotiationneeded', (event) => {
  let offerOptions = { 'offerToReceiveVideo': true, 'offerToReceiveAudio': true };
  this.peerConnection
    .createOffer(offerOptions)
    .then((sdp: RTCSessionDescription) => {
      return this.peerConnection
        .setLocalDescription(sdp)
        .then(() => {
          let localSDP = sdp.sdp;
          console.log(sdpTransform.parse(localSDP));
          this.sendOffer(localSDP)
        })
    }, (e) => {
      console.error(e);
    })
})

this.peerConnection.addEventListener('icecandidate', (event) => {
  let iceCandidate = event.candidate;
  if (iceCandidate != null) {
    let sdpMid = iceCandidate.sdpMid;
    let sdpMLineIndex = iceCandidate.sdpMLineIndex;
    let candidate = iceCandidate.candidate;
    this.sendICECandidate(this.callerUserId, sdpMid, sdpMLineIndex, candidate)
  }
});

this.peerConnection.addEventListener('renegotiationneeded', () => {
  console.log("renagotiation needed");
})

this.peerConnection.addEventListener('addstream', async (event) => {
  console.log(event);
  this.remoteVideoService.setRemoteMedia(event.stream);
  this.dialog.open(VideoCallComponent, { panelClass: 'videoCallDialog', disableClose: true, data: { "callerName": this.callerName } }).afterClosed().subscribe(response => {
    if(response && response.data=="hangUp"){
      this.disconnectCall();
    }
  });
});
**为了接收ICE候选人,我们使用了类似webSocket的**

   handleIceCandidate(data) {
if (data) {
  let candidate = { candidate: data.data.candidate, sdpMid: data.data.id, sdpMLineIndex: data.data.label }
  var iceCandidate: RTCIceCandidateInit = candidate;
  console.log(iceCandidate);
  this.peerConnection.addIceCandidate(iceCandidate);
}
}