I am trying to create peerconnection between two chrome(ver 20.0.1132.57) windows on a windows system. I am hosting my application on a node.js server on a linux machine and using socket.io. These two machines are on same internal network. I am not using stun server. Is it required to use STUN for this scenario as both the machines are part of same internal network? If not, then why onSignal callback is not being called?

  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);
   }

///server side

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

I have used this demo http://html5videoguide.net/presentations/WebDirCode2012/websocket/webrtc.html

I tried to understand peer connection working by going through this http://www.html5rocks.com/en/tutorials/webrtc/basics/#toc-sans where on one page itself both caller and callee are implemented. It didn't work for me as it is throwing error in new RTCIceCandidate(candidate), error "ReferenceError: RTCIceCandidate is not defined" . Is there any other syntax for creating Ice Candidate?

Thanks in advance.

有帮助吗?

解决方案

You should try to look at this application code, it's pretty easy to grasp what's going on in there if you go through the code with the Google Chrome JavaScript Debugging Tool:

https://apprtc.appspot.com/

You also have to install a newer Chrome Dev Version from http://dev.chromium.org/getting-involved/dev-channel . The version you are using is still using the old signaling protocol ROAP without ICE Agents etc.

其他提示

webkitPeerConnection00 passes IceCandidates to callback, it does not passes message. So to make this work, an offer has to be sent to other client and from there answer is received.

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.");
}

}

//Offer from 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();
}

//on receiving offer from client1 on client2, set offer as remoteDescription, create answer, send to client1 and set answer as 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();
    }

//on receiving answer from client2 on client1, set answer as remoteDescription

//on receiving candidate, var candidate = new IceCandidate(label, candidate);

// pc.processIceMessage(candidate);

Note: this code snippet will not work with RTCPeerConnection (new specification) see http://dev.w3.org/2011/webrtc/editor/webrtc.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top