0

nodejsとwebrtcで音声通話をしたいのですが、他のユーザーに電話すると「ICEに失敗しました。詳細についてはwebrtcを参照してください」というエラーが表示されます。HTML には、offer() を呼び出すボタンが含まれているだけです。

オファーと SessionDescriptions が 1 つのクライアントから別のクライアントに正常に転送されていることを確認できます。私を助けてください

 Client Side Javasrcipt: 
    navigator.getUserMedia({video:false, audio:true}, function(stream)                 {
document.getElementById("localvideo").mozSrcObject = stream;
document.getElementById("localvideo").play();
document.getElementById("localvideo").muted = true;

// var pc = new mozRTCPeerConnection();
var pc = new PeerConnection(iceServers, options);
pc.addStream(stream);

pc.onaddstream = function(obj) {
log("Got onaddstream of type " + obj.type);
document.getElementById("remotevideo").mozSrcObject = obj.stream;
document.getElementById("remotevideo").play();
document.getElementById("dialing").style.display = "none";
document.getElementById("hangup").style.display = "block";
};

pc.createOffer(function(offer) {
console.log("Created offer" + JSON.stringify(offer));
pc.setLocalDescription(offer, function() {
// Send offer to remote end.       
pc.iceCandidate = new RTCIceCandidate();      
console.log(pc.iceCandidate);
    peerc = pc;
    jQuery.post(
      "offer", {
        to: user,
        from: document.getElementById("user").innerHTML,
        offer: JSON.stringify(offer)
      },
      function() { console.log("Offer sent!"); }
    ).error(error);
  }, error);
}, error);

});

そして私のサーバーサイドスクリプト -

        app.post("/offer", function(req, res) { 
          var channel = users[req.body.to];
           channel.write("event: offer\n");
          channel.write("data: " + JSON.stringify(req.body));
          channel.write("\n\n");
          res.send(200);
        });
4

3 に答える 3

2

完全なアプリコードを提供していないか、適切な webrtc 接続のためのアプリコードが不完全であるかのどちらかです。

手始めに、webrtc がビデオ チャットを簡素化したのと同様に、オファー sdp を送信するだけではうまくいきません (反対側で回答 sdp を作成して送信したと想定しています)。ICE 候補も交換する必要があります。 . ピアのアイス候補は、コーリング カードのようなもので、到達方法を示します。そのため、それらを交換しないと通信できません。

ここに画像の説明を入力

通常、ブラウザはイベントで氷の候補を提供します。これonIceCandidateをピアに送信すると、ピアに追加されpeerConnection.addIceCandidate(candidate)ます.

于 2015-07-16T03:18:27.537 に答える
1

受信側を追加し、ICE 候補を処理する必要があります。は見えますcreateOfferが、そうcreateAnswerではありません。ICE の失敗は、おそらく ICE 候補に信号を送っていないことが原因です (Trickle ICE と呼ばれる手法が現在必要とされています)。

Firefox を使用しているようですので、このローカル ループ デモ (シグナリングなし) を実行できるはずです。明白な理由 (フィードバック) により、オーディオがローカル ループでひどく機能するため、私はビデオを使用します。

var pc1 = new mozRTCPeerConnection(), pc2 = new mozRTCPeerConnection();

pc1.onicecandidate = e => !e.candidate ||
    pc2.addIceCandidate(e.candidate).catch(failed);
pc2.onicecandidate = e => !e.candidate ||
    pc1.addIceCandidate(e.candidate).catch(failed);
pc2.onaddstream = e => v2.mozSrcObject = e.stream;

function start() {
  navigator.mediaDevices.getUserMedia({ video: true })
  .then(stream => pc1.addStream(v1.mozSrcObject = stream))
  .then(() => pc1.createOffer())
  .then(offer => pc1.setLocalDescription(offer))
  .then(() => pc2.setRemoteDescription(pc1.localDescription))
  .then(() => pc2.createAnswer())
  .then(answer => pc2.setLocalDescription(answer))
  .then(() => pc1.setRemoteDescription(pc2.localDescription))
  .then(() => log("Connected!"))
  .catch(failed);
}

var log = msg => div.innerHTML += "<p>" + msg + "</p>";
var failed = e => log(e +", line "+ e.lineNumber);
<video id="v1" height="120" width="160" autoplay></video>
<video id="v2" height="120" width="160" autoplay></video><br>
<button onclick="start()">Start!</button><div id="div"></div>

于 2015-07-16T05:44:03.573 に答える
0

相手側で回答を生成し、それを最初のパーティに送り返して処理していますか?

于 2015-07-16T04:22:03.077 に答える