Javascript WebRTC在Nightly(22)和Chrome(25)中出现问题
我正在使用RTPeerConnection和我自己的长轮询实现在两个浏览器之间试验WebRTC。我已经创建了一个演示应用程序,它成功地与Mozilla Nightly(22)配合使用,但是在Chrome(25)中,我无法获得任何远程视频,只能显示“空的黑色视频”。我的JS代码有什么问题吗 函数sendMessage(message)通过长轮询将消息发送到服务器,另一方面,使用onMessage()接受该消息Javascript WebRTC在Nightly(22)和Chrome(25)中出现问题,javascript,html,webrtc,Javascript,Html,Webrtc,我正在使用RTPeerConnection和我自己的长轮询实现在两个浏览器之间试验WebRTC。我已经创建了一个演示应用程序,它成功地与Mozilla Nightly(22)配合使用,但是在Chrome(25)中,我无法获得任何远程视频,只能显示“空的黑色视频”。我的JS代码有什么问题吗 函数sendMessage(message)通过长轮询将消息发送到服务器,另一方面,使用onMessage()接受该消息 我最好的猜测是您的STUN服务器配置有问题。要确定这是否是问题所在,请尝试使用googl
我最好的猜测是您的STUN服务器配置有问题。要确定这是否是问题所在,请尝试使用google的公共stun服务器
stun:stun.l.google.com:19302
(在Firefox中不起作用,但在Chrome中肯定可以起作用)或在未配置stun服务器的本地网络上进行测试
此外,请验证您的ice候选者是否正确交付。Firefox实际上并没有生成“icecandidate”事件(它在提供/回答中包含候选人),因此传递候选人消息的问题也可以解释这种差异。确保您的视频标签属性autoplay设置为“autoplay”。如果您有任何资源帮助您,我也对WebRTC感兴趣,你能和我分享一下吗,我现在找不到太多。不幸的是,很难找到一些最新的资源,甚至是一些howto教程。如果我发现了什么,我会把它贴在这里。恐怕这取决于连接步骤的顺序,对吗?我忘了提到,为了方便起见,我使用了简单的适配器,所以我不必解决Chrome和Nightly之间的前缀差异。我找到了一个非常有用的资源,它使用信号器发送消息,并使它工作起来。以下帖子帮助了我:。希望它也能帮助你。目前我看不出代码中有任何错误。@p谢谢您的链接,我会尽快尝试。作为浏览器之间的握手消息传递,我实际上使用了异步Javaservlet提供的长轮询技术。在夜间,它工作正常,在Chrome中,只有视频元素上的黑色背景出现在被叫方,而呼叫者没有收到任何远程视频流。无论如何,我会再做一些测试。谢谢你的回复。
var peerConnection;
var peerConnection_config = {"iceServers": [{"url": "stun:23.21.150.121"}]};
// when message from server is received
function onMessage(evt) {
if (!peerConnection)
call(false);
var signal = JSON.parse(evt);
if (signal.sdp) {
peerConnection.setRemoteDescription(new RTCSessionDescription(signal.sdp));
} else {
peerConnection.addIceCandidate(new RTCIceCandidate(signal.candidate));
}
}
function call(isCaller) {
peerConnection = new RTCPeerConnection(peerConnection_config);
// send any ice candidates to the other peer
peerConnection.onicecandidate = function(evt) {
sendMessage(JSON.stringify({"candidate": evt.candidate}));
};
// once remote stream arrives, show it in the remote video element
peerConnection.onaddstream = function(evt) {
// attach media stream to local video - WebRTC Wrapper
attachMediaStream($("#remote-video").get("0"), evt.stream);
};
// get the local stream, show it in the local video element and send it
getUserMedia({"audio": true, "video": true}, function(stream) {
// attach media stream to local video - WebRTC Wrapper
attachMediaStream($("#local-video").get("0"), stream);
$("#local-video").get(0).muted = true;
peerConnection.addStream(stream);
if (isCaller)
peerConnection.createOffer(gotDescription);
else {
peerConnection.createAnswer(gotDescription);
}
function gotDescription(desc) {
sendMessage(JSON.stringify({"sdp": desc}));
peerConnection.setLocalDescription(desc);
}
}, function() {
});
}