简体   繁体   中英

webrtc data channel not workinig

I am trying to setup a text chat using webrtc data channel. my network his a private network so i can't use any dependencies or frameworks like peerjs or similar. I published my project on java play server so i have one webrtsPeerConnection object that user can choose to initiate connection or to accept connection from someone else. the problem : data channel is setup and active for the user who initiate the call. but for the user who joined the call data channel don't activate and onDataChannel event never fires. any suggestions??

Thanks in advance!

my code java script:

// init peer connection and data channel objects  

 var pc = new RTCpeerConnection(null,null);
 var DC,DCnam;
 function InitConnection(){
 //created RTCpeerConnection
 createDataChannel();

 pc.createOffer(function(desc){

 pc.setLocalDescripyion(desc,function(){},function(){})

    enter code here

  })
 }
 //create data channel

 function createDataChannel(){

 DC = pc.createDataChannel(DCname,{
 reliable:true
  });
 }
 //when user A call user B set remote description and create answer  
 function CheckCalls(){

 &http.get("/checkCslls").success(function(data){

 if(data[0])
 {

 //get offer and offerer 
 offerer = data[0].offerer;

 pc.odataChannel function(e){

 console.log(e);
 }
 pc.setRemoteDescription(new sessionDescription()data[0].offer));

 pc.createAnswer(function(answerDesc){

 pc.setLocalDescripyion(answerDesc);

    })
   }
 })
}
//when user B send answer 
(onDataChannel event fires on user A object).

function checkAnswers(){

$http.get("/checkAnswers").success(function(data){

if(data.answer){

pc.setRemoteDescription(new sessionDescription(data.answer));
  }

})

It can be that you misspelled the callback:

pc.odataChannel function(e){

console.log(e);
}

it is ondatachannel with an "n" and lower case "c" and a "=" to define the function and callbacks to do something when messages are delivered; something like:

var receiveChannel;
pc.ondatachannel = function (event) {
      console.log('Receive Channel Callback');
      receiveChannel = event.channel;
      receiveChannel.onmessage = gotCMessage;
      receiveChannel.onopen = dcOpen;
      receiveChannel.onclose = dcClose;
       console.log(event);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM