连接不稳定

时间:2017-01-25 20:59:17

标签: javascript webrtc django-channels

我在Django频道的Python后端。在其中我有一个选择在线用户的方法,并将数据发送给另一个用户。

但是,当我要建立连接流程时,有些事情是错误的和不稳定的。有时它完美无缺,并且有时会发生错误。

似乎发送了" ICE Candidate"随机进入一切的前面,导致错误。有时它仅在响应后被调用。

这个初始序列在Javascript中来自我的WebRTC是否正确? (OnIceCandidate一直在拍摄)

function getUserMediaSuccess(stream) {
    window.localStream = localStream = stream;
    localVideo.srcObject = stream;
    // localVideo.src = window.URL.createObjectURL(stream);

    var iceServers = {
        'iceServers': [
            {'urls': 'stun:stun.services.mozilla.com'},
            {'urls': 'stun:stun.l.google.com:19302'},
        ]
    };


    //creating our RTCPeerConnection object

    peerConnection = new RTCPeerConnection(iceServers);
    console.log("RTCPeerConnection object was created");
    console.log(peerConnection);


    peerConnection.addStream(localStream);

    if ('ontrack' in peerConnection) {
        // WebRTC Spec, Firefox
        peerConnection.ontrack = function (event) {
          remoteVideo.srcObject = event.streams[0];
         };
     } else {
        // Chrome, etc. This can be removed once all browsers support `ontrack`
        peerConnection.onaddstream = function (event) {
          // remoteVideo.src = window.URL.createObjectURL(event.stream);
          remoteVideo.srcObject = event.stream;
        };
     }

    //setup ice handling
    //when the browser finds an ice candidate we send it to another peer
    peerConnection.onicecandidate = function (event) {

       if (event.candidate) {
          send("candidate", {candidate: event.candidate});
       }
    };

    peerConnection.ondatachannel = function(event) {
       var receiveChannel = event.channel;
       receiveChannel.onmessage = function(event) {
          console.log("ondatachannel message:", event.data);
       };
    };
    openDataChannel();
}
  1. 当您不连接时......
  2. 日志 - 用户1

    Websocket Connected
    RTCPeerConnection object was created
    Send: Notices that it is available...
    Received: Found peer
    Send: offer
    Send: candidate
    Received: candidate
    Uncaught (in promise) DOMException: Error processing ICE candidate
    Received: candidate
    Uncaught (in promise) DOMException: Error processing ICE candidate
    Received: answer
    Received: candidate
    

    日志 - 用户2

       Websocket Connected
       RTCPeerConnection object was created
       Send: Notices that it is available...
       Received: candidate
       Uncaught (in promise) DOMException: Error processing ICE candidate
       Uncaught (in promise) DOMException: Error processing ICE candidate
       Uncaught (in promise) DOMException: Error processing ICE candidate
       Received: offer
       Send: answer
       Received: candidate
       Send: candidate
       Received:  candidate
       Send: candidate
       Received: candidate
       Send: candidate
       Received: candidate
    
    1. 当您执行CONNECTED ...
    2. 日志 - 用户1

      Websocket Connected
      RTCPeerConnection object was created
      Send: Notices that it is available...
      Received: Found peer
      Send: offer
      Send: candidate
      Received: candidate
      Uncaught (in promise) DOMException: Error processing ICE candidate
      Received: candidate
      Uncaught (in promise) DOMException: Error processing ICE candidate
      Received: answer
      Received: candidate
      

      日志 - 用户2

      Websocket Connected
      RTCPeerConnection object was created
      Send: Notices that it is available...
      Received: candidate
      Uncaught (in promise) DOMException: Error processing ICE candidate
      Received: candidate
      Uncaught (in promise) DOMException: Error processing ICE candidate
      Received: candidate
      Uncaught (in promise) DOMException: Error processing ICE candidate
      Received: offer
      Send: answer
      Send: candidate
      Received: candidate
      Send: candidate
      Received: candidate
      

0 个答案:

没有答案