Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.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
Javascript WebRTC:在错误状态下调用:state\u SENTOFFER_Javascript_Webrtc_Simplewebrtc - Fatal编程技术网

Javascript WebRTC:在错误状态下调用:state\u SENTOFFER

Javascript WebRTC:在错误状态下调用:state\u SENTOFFER,javascript,webrtc,simplewebrtc,Javascript,Webrtc,Simplewebrtc,下面是WebRTC的一个简单示例。但远程视频不会出现在任何浏览器中,Chrome也不会显示错误: 未捕获(承诺中)DomeException:处理ICE候选项时出错 我创建了一个日志而不是setRemoteDescription方法: peerConn.setRemoteDescription(new RTCSessionDescription(signal.sdp), function(){ alert('success') }, function(e){ console

下面是WebRTC的一个简单示例。但远程视频不会出现在任何浏览器中,Chrome也不会显示错误:

未捕获(承诺中)DomeException:处理ICE候选项时出错

我创建了一个日志而不是setRemoteDescription方法:

peerConn.setRemoteDescription(new RTCSessionDescription(signal.sdp), function(){
       alert('success')
    }, function(e){ console.log(e); alert(e)});
然后我得到以下错误:

OperationError:无法设置远程提供sdp:在错误状态下调用: 州政府

在讨论中的教程中,作者声称他能够把一切都做好,错误应该在我这边。有人经历过这种情况吗

(对我的英语感到抱歉)


编辑:(包括代码)

在这个问题上,我仍然是一个门外汉,一开始引用的教程链接是我发现的最干净的开始玩的链接。我会把来源放在我认为很重要的地方:

后端-server.js

/** successful connection */
wss.on('connection', function (client) {
  console.log("A new WebSocket client was connected.");
  /** incomming message */
  client.on('message', function (message) {
    /** broadcast message to all clients */
    wss.broadcast(message, client);
  });
});
// broadcasting the message to all WebSocket clients.
wss.broadcast = function (data, exclude) {
  var i = 0, n = this.clients ? this.clients.length : 0, client = null;
  if (n < 1) return;
  console.log("Broadcasting message to all " + n + " WebSocket clients.");
  for (; i < n; i++) {
    client = this.clients[i];
    // don't send the message to the sender...
    if (client === exclude) continue;
    if (client.readyState === client.OPEN) client.send(data);
    else console.error('Error: the client state is ' + client.readyState);
  }
};
wsc.onmessage = function (evt) {
  var signal = null;
  if (!peerConn) answerCall();
  signal = JSON.parse(evt.data);
  if (signal.sdp) {
    console.log("Received SDP from remote peer.");
    peerConn.setRemoteDescription(new RTCSessionDescription(signal.sdp), 
      function(){}, 
      function(e){ console.log(e); 
    });
  }
  else if (signal.candidate) {
    console.log("Received ICECandidate from remote peer.");
    peerConn.addIceCandidate(new RTCIceCandidate(signal.candidate));
  } else if ( signal.closeConnection){
    console.log("Received 'close call' signal from remote peer.");
    endCall();
  }
};

所有字体:

如果看不到代码,很难回答,但从两个错误判断,您至少有两个问题:

未捕获(承诺中)DomeException:处理ICE候选项时出错

这是来自
peerConn.addIceCandidate(候选者)
的,候选者输入有问题,表明它不正确或被损坏。您应该通过信号通道从另一端的
peerConn.onicecandidate
发送信号。如果需要更多帮助,请显示代码

它是“未捕获的”,因为它返回一个承诺,而您缺少一个
。catch

peerConn.addIceCandidate(candidate).catch(e => console.log(e));
OperationError:无法设置远程提供sdp:在错误状态下调用:状态\u SENTOFFER

这表明两个同行试图同时发送报价,这是对称的,也是错误的


提供/应答交换本质上是不对称的。一方必须以要约开始,另一方接收要约,执行SetRemote、createAnswer,并将应答发送回执行SetRemote的第一个对等方。这个舞蹈是一种舞蹈。任何错误都会出现如下错误。

添加到catch:“addIceCandidate:OperationError:error processing ICE候选者”。PS:包括主题中的源代码。我发现使用localhost是可行的,当我尝试使用网络时会出现错误。当然,随着SSL端口的释放,@LuísDeMarchi,这表明你的ice候选者被搞砸了。尝试将它们记录到控制台发送方和接收方。非常感谢,我使用了原始API和两个webRTC库,出现了第二个错误,我已将第二个对等报价转移到了
onAnswer
,解决了问题。
answerCall()
做了什么?注意:在调用
createAnswer()
之前,必须
setRemoteDescription(offer)
。报价是答案的基础。