1

Windows システムで 2 つのクロム (ver 20.0.1132.57) ウィンドウ間にピア接続を作成しようとしています。Linux マシンの node.js サーバーでアプリケーションをホストし、socket.io を使用しています。これら 2 台のマシンは同じ内部ネットワーク上にあります。私はスタンサーバーを使用していません。両方のマシンが同じ内部ネットワークの一部であるため、このシナリオでは STUN を使用する必要がありますか? そうでない場合、なぜ onSignal コールバックが呼び出されないのでしょうか?

  var stun=null;

  function connect(){
  createPeer();
  pc.addStream(localstream);
  }

  function createPeer(){ 
  pc = new webkitPeerConnection00(stun, onSignal);

  pc.onadddstream=onRemoteStreamAdded;
  pc.onremovestream=onRemoteStreamRemoved;
  }

  function onSignal(message){   
  socket.send(message)//sending this to server
  }

  //on receiving message 
  socket.on('message',onMessage);
  function onMessage(message){
   if(pc==null){
             createPeer();
             pc.addStream(localstream);
                }
   pc.processSignallingMessage(message);
   }

///サーバ側

     socket.on('message', function(message){
     socket.broadcast.send(message);//broadcasting received message to other peers
     });

このデモhttp://html5videoguide.net/presentations/WebDirCode2012/websocket/webrtc.htmlを使用しました

このhttp://www.html5rocks.com/en/tutorials/webrtc/basics/#toc-sansを使用して、ピア接続の動作を理解しようとしました。1 つのページ自体に呼び出し元と呼び出し先の両方が実装されています。new RTCIceCandidate(candidate) でエラー "ReferenceError: RTCIceCandidate is not defined" がスローされるため、うまくいきませんでした。Ice Candidate を作成するための他の構文はありますか?

前もって感謝します。

4

2 に答える 2

1

webkitPeerConnection00はIceCandidatesをコールバックに渡しますが、メッセージは渡しません。したがって、これを機能させるには、オファーを他のクライアントに送信する必要があり、そこから回答を受け取ります。

pc =new webkitPeerConnection00(stun, onIceCandidate);

function onIceCandidate(candidate, moreToFollow) {
if (candidate) {
   //send candidate.toSdp() to other client with candidate.label 
}

if (!moreToFollow) {
  console.log("End of candidates.");
}

}

//client1からのオファー

  function makeOffer()
{
  var offer = pc.createOffer({'has_audio':true, 'has_video':true});
  pc.setLocalDescription(pc.SDP_OFFER, offer);
  //send offer.toSdp() to peer
  pc.startIce();
}

// client2のclient1からオファーを受信したら、offerをremoteDescriptionとして設定し、回答を作成し、client1に送信し、回答をlocalDescriptionとして設定します

   function doAnswer(){
    var offer = pc.remoteDescription;
    var answer = pc.createAnswer(offer.toSdp(), {'has_audio':true, 'has_video':true});
    pc.setLocalDescription(pc.SDP_ANSWER, answer);
    //send answer.toSdp() 
    pc.startIce();
    }

// client1のclient2から回答を受信したら、回答をremoteDescriptionとして設定します

//候補を受け取ると、var候補= new IceCandidate(label、candidate);

// pc.processIceMessage(candidate);

注:このコードスニペットはRTCPeerConnection(新しい仕様)では機能しません。http://dev.w3.org/2011/webrtc/editor/webrtc.htmlを参照してください

于 2012-10-11T07:13:52.330 に答える
1

このアプリケーション コードを確認してみてください。Google Chrome JavaScript Debugging Tool を使用してコードを調べれば、そこで何が起こっているかを簡単に把握できます。

https://apprtc.appspot.com/

また、 http: //dev.chromium.org/getting-involved/dev-channel から新しい Chrome Dev バージョンをインストールする必要があります。使用しているバージョンは、ICE エージェントなどのない古いシグナリング プロトコル ROAP をまだ使用しています。

于 2012-10-05T15:22:57.177 に答える