Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WebRTC在本地连接上连接,但在internet上失败,存在消息交换_Php_Mysql_Webrtc - Fatal编程技术网

Php WebRTC在本地连接上连接,但在internet上失败,存在消息交换

Php WebRTC在本地连接上连接,但在internet上失败,存在消息交换,php,mysql,webrtc,Php,Mysql,Webrtc,希望你一切顺利 我已经在两台电脑之间实现了一个WebRTC视频(仅视频)会议,它可以在本地网络(chrome和opera)上完美工作,尽管它不能在Firefox上工作。而且,在chrome和Firefox上,它不能在互联网上工作。两个对等方(一个进入我家,另一个在屋外)之间交换信号消息,但视频不会在屋外的PC上播放(通过互联网连接到进入屋内的PC) 使用以下变量 navigator.getUserMedia = navigator.getUserMedia || navigator.mozGet

希望你一切顺利

我已经在两台电脑之间实现了一个WebRTC视频(仅视频)会议,它可以在本地网络(chrome和opera)上完美工作,尽管它不能在Firefox上工作。而且,在chrome和Firefox上,它不能在互联网上工作。两个对等方(一个进入我家,另一个在屋外)之间交换信号消息,但视频不会在屋外的PC上播放(通过互联网连接到进入屋内的PC)

使用以下变量

navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
window.RTCPeerConnection = window.RTCPeerConnection ||  window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
window.RTCIceCandidate = window.RTCIceCandidate || window.mozRTCIceCandidate ||  window.webkitRTCIceCandidate;
window.RTCSessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
var peerConnectionConfig = {'iceServers': [{'url': 'stun:stun.services.mozilla.com'}, {'url': 'stun:stun.l.google.com:19302'}]};            
var pcOptions = {optional: [{DtlsSrtpKeyAgreement: false}]
我通过调用函数创建了peerconnection:

function createPeerConnection(strdata){
//  strdata contains the descreption receved frome the signalings server
  log('createPeerConnection');
  peerConnection = new RTCPeerConnection(peerConnectionConfig,pcOptions);
  peerConnection.onicecandidate = gotIceCandidate;
  peerConnection.onaddstream = gotRemoteStream;
  peerConnection.onsignalingstatechange = function(ev){ 
     log('============================ '+JSON.stringify(ev));
  }
  data=data.replace(/@/gi, "\\r\\n"); 
  /*
    I use '@' to replace '\r\n'  to avaoid probleme with SQL requests, I 
     replaced all ocurences of '\r\n' by '@' (str.replace(/\\r\\n/gi, "@");
    ), I used the same things for answer, offer and candidates.I use PHP and
     MySQL to store all messages: candidates, offer and answer, 
  */

   var description= JSON.parse(data);
   try{
      log('createPeerConnectionDD');
      peerConnection.setRemoteDescription(new RTCSessionDescription(description), function() {
          log('set remote description success');
           //offere=true;
          for(i=0;i<msgss.length;i++){
             var data=msgss[i].data.replace(/@/gi, "\\r\\n");
             var candidate= JSON.parse(data);
             log('cand= '+JSON.stringify(candidate));
             peerConnection.addIceCandidate(new RTCIceCandidate(candidate));
          }
          peerConnection.createAnswer(gotDescription, createAnswerError);
       },function(err) {
          log('set remote description fail');
    });
  }catch(e){
    log(e);
  }
}
函数createPeerConnection(strdata){
//strdata包含从信号服务器接收的描述
日志(“createPeerConnection”);
peerConnection=新的RTCPeerConnection(peerConnectionConfig,pcOptions);
peerConnection.onicecandidate=gotIceCandidate;
peerConnection.onaddstream=gotmotestream;
peerConnection.onsignalingstatechange=函数(ev){
日志('==============================='+JSON.stringify(ev));
}
data=data.replace(/@/gi,“\\r\\n”);
/*
我使用“@”替换“\r\n”以避免SQL请求出现问题,我
将“\r\n”的所有内容替换为“@”(str.replace(/\\r\\n/gi,“@”);
),我对答案、报价和候选人使用相同的东西。我使用PHP和
MySQL存储所有消息:候选人、提议和回答,
*/
var description=JSON.parse(数据);
试一试{
日志('createPeerConnectionDD');
setRemoteDescription(新的RTCSessionDescription(描述),函数(){
日志(“设置远程描述成功”);
//报价=真;

对于(i=0;i变量数据中包含哪些内容?
data=data.replace(/@/gi,“\\r\\n”)中的rhs是否应
包含strdata?此外,代码段中的事件流不清楚,您应该提供事件日志或更全面的代码段。数据是strdata,它包含从其他对等方收到的报价。在文本中,我在函数createPeerConnection的参数中用strdata替换了数据(数据){//strdata包含从信号服务器收到的描述您似乎是在以某种方式捆绑ice候选者,而不是将其滴入。这是怎么回事?这很可能解释了为什么它只在lan上工作(我猜,因为您没有显示它的另一半)。另外,您在Firefox(web控制台)中看到了哪些错误?是的,当然,我正在捆绑消息,特别是由生成要约的同一对等方生成的要约和候选人。这是因为我使用XMLHTTPRequest作为底层信令协议。现在它在firefox上运行良好。Hilo亲爱的Jib,addIcecandidate以错误结尾。错误名称为“InvalidStateError”,消息是:“无法在statehave-local_报价中添加ICE候选人”。