WebRTC onicecandidate НИКОГДА не срабатывает в хроме - PullRequest
0 голосов
/ 26 мая 2019

Мое веб-приложение webrtc никогда не выдвигает своих кандидатов. Когда я смотрю на свой локальный объект (объект Webrtc), устанавливаются localdescription и remotedescription. В Firefox он запускает onicecandidate, но event.candidate имеет значение null

Я пытался решить эту проблему в течение нескольких часов, но не смог

Кто-нибудь может решить эту проблему?

Как сделать так, чтобы событие onicecandidate было запущено?

  let local = new RTCPeerConnection();
  let remote = new RTCPeerConnection();
  try {
    local.createOffer().then(function(sdp) {
      console.log("Offer Created by Local: " + sdp.sdp);
      local.setLocalDescription(sdp);
      remote.setRemoteDescription(sdp);

      remote.createAnswer().then(function(sdp){
        console.log("Answer Created by Remote: " + sdp.sdp);
        remote.setLocalDescription(sdp);
        local.setRemoteDescription(sdp);
        local.onicecandidate = localicecandidate;
        remote.onicecandidate = remoteicecandidate;

        let channel = local.createDataChannel("channel");
        channel.onopen = function(event) {
          console.log("Channel opened");
        }
        channel.onmessgae = function(event) {
          console.log(event.data);
        }

        remote.ondatachannel = function(event) {
          let channel = event.channel;
          channel.onopen = function(event) {
            channel.send("Hi!");
          }
        }

        function localicecandidate (event) {
          console.log("Local got new Ice Candidate: " + event.candidate);
          remote.addIceCandidate(new RTCIceCandidate(event.candidate));
        }
        function remoteicecandidate (event) {
          console.log("Remote got new Ice Candidate: " + event);
          local.addIceCandidate(new RTCIceCandidate(event.candidate));
        }

      }); 
    })
  }

  catch (e) {
    console.log("Got Error" + e);
  }

1 Ответ

1 голос
/ 26 мая 2019

Вы не вызываете createDataChannel перед вызовом createOffer, поэтому ваш SDP не содержит m = строк. Без m-линий ICE не сможет договориться.

Переместить let channel = local.createDataChannel("channel"); перед созданием предложения.

...