我正在实现 WebRTC 对等调用,它在所有浏览器中运行良好,除非 chrome 是调用初始化程序(调用邀请函数)。
如果 chrome 是呼叫初始值设定项,则 ICE 连接状态更改为已连接并且视频出现在另一个对等点中,则会发生错误“DOMException:“无法在稳定状态下创建答案””,并且视频停止传输到另一个对等点。
如果接收器也是 chrome,则错误显示“无法在 'RTCPeerConnection' 上执行 'createAnswer':PeerConnection 无法在 has-remote-offer 或 have-local-pranswer 以外的状态下创建答案。”
这些是 handleVideoOfferMsg 函数和 handleGetUserMediaError 函数(触发错误)代码:
function handleVideoOfferMsg(msg) {
// debugger;
// $("#ring")[0].play();
var localStream = null;
targetUsername = msg.from;
// Call createPeerConnection() to create the RTCPeerConnection.
log("Starting to accept invitation from " + targetUsername);
createPeerConnection();
// We need to set the remote description to the received SDP offer
// so that our local WebRTC layer knows how to talk to …Run Code Online (Sandbox Code Playgroud) 我希望逻辑上没有缺陷。
步骤1:呼叫者创建报价
步骤2:呼叫者设置localDescription
步骤3:呼叫者将描述发送给被呼叫者
// ------------------------------------------------ ------ //
步骤4:被叫方收到要约集的远程描述
步骤5:被叫方创建答案
步骤6:被叫方设置本地描述
步骤7:被呼叫者将说明发送给呼叫者
// ------------------------------------------------ ------ //
步骤8:呼叫者收到答案并设置远程描述
这是上面的代码
const socket = io();
const constraints = {
audio: true,
video: true
};
const configuration = {
iceServers: [{
"url": "stun:23.21.150.121"
}, {
"url": "stun:stun.l.google.com:19302"
}]
};
const selfView = $('#selfView')[0];
const remoteView = $('#remoteView')[0];
var pc = new RTCPeerConnection(configuration);
pc.onicecandidate = ({
candidate
}) => {
socket.emit('message', {
to: $('#remote').val(),
candidate: candidate
}); …Run Code Online (Sandbox Code Playgroud)