简体   繁体   English

webrtc数据通道不起作用

[英]webrtc data channel not workinig

I am trying to setup a text chat using webrtc data channel. 我正在尝试使用webrtc数据通道设置文本聊天。 my network his a private network so i can't use any dependencies or frameworks like peerjs or similar. 我的网络是一个专用网络,因此我不能使用任何依赖项或框架(例如peerjs或类似框架)。 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. 我在Java Play服务器上发布了项目,因此我有一个webrtsPeerConnection对象,用户可以选择该对象来发起连接或接受来自其他人的连接。 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. 但对于加入呼叫数据通道的用户,请不要激活它,并且永远不会触发onDataChannel事件。 any suggestions?? 有什么建议么??

Thanks in advance! 提前致谢!

my code java script: 我的代码Java脚本:

// 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; 它是在数据通道上,带有“ n”,小写字母“ c”和“ =”以定义函数和回调,以便在传递消息时执行某些操作; 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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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