我想用 nodejs 和 webrtc 进行语音通话。当我打电话给其他用户时,出现错误“ICE 失败,请参阅 about:webrtc 了解更多详细信息”。HTML 仅包含一个调用 offer() 的按钮。
我可以确认报价和 SessionDescriptions 成功地从一个客户转移到另一个客户。请帮我
Client Side Javasrcipt:
navigator.getUserMedia({video:false, audio:true}, function(stream) {
document.getElementById("localvideo").mozSrcObject = stream;
document.getElementById("localvideo").play();
document.getElementById("localvideo").muted = true;
// var pc = new mozRTCPeerConnection();
var pc = new PeerConnection(iceServers, options);
pc.addStream(stream);
pc.onaddstream = function(obj) {
log("Got onaddstream of type " + obj.type);
document.getElementById("remotevideo").mozSrcObject = obj.stream;
document.getElementById("remotevideo").play();
document.getElementById("dialing").style.display = "none";
document.getElementById("hangup").style.display = "block";
};
pc.createOffer(function(offer) {
console.log("Created offer" + JSON.stringify(offer));
pc.setLocalDescription(offer, function() {
// Send offer to remote end.
pc.iceCandidate = new RTCIceCandidate();
console.log(pc.iceCandidate);
peerc = pc;
jQuery.post(
"offer", {
to: user,
from: document.getElementById("user").innerHTML,
offer: JSON.stringify(offer)
},
function() { console.log("Offer sent!"); }
).error(error);
}, error);
}, error);
});
还有我的服务器端脚本-
app.post("/offer", function(req, res) {
var channel = users[req.body.to];
channel.write("event: offer\n");
channel.write("data: " + JSON.stringify(req.body));
channel.write("\n\n");
res.send(200);
});