webrtc:始终在远程视频中获取本地视频
下面是我使用WebRTC进行视频聊天的代码。问题是我总是在remoteVideo元素(在两个对等点中)中获得localStream,为什么会这样 我没有管理员权限访问我要上传网站的主机,所以我应该首先使用免费的STUN/TURN服务器。我不确定我的iceServers使用是否正确,这有问题吗 我真的受够了!感谢您的帮助:)webrtc:始终在远程视频中获取本地视频,webrtc,Webrtc,下面是我使用WebRTC进行视频聊天的代码。问题是我总是在remoteVideo元素(在两个对等点中)中获得localStream,为什么会这样 我没有管理员权限访问我要上传网站的主机,所以我应该首先使用免费的STUN/TURN服务器。我不确定我的iceServers使用是否正确,这有问题吗 我真的受够了!感谢您的帮助:) 为什么你有两个peerconnection对象?如果你想在两台不同的计算机之间建立连接,那你就错了。如果你想测试一个peerconnection,这样本地视频就可以被设置为远
为什么你有两个peerconnection对象?如果你想在两台不同的计算机之间建立连接,那你就错了。如果你想测试一个peerconnection,这样本地视频就可以被设置为远程和本地视频,并且可以这样显示,那么你的代码就可以了……你想要哪一个呢?我想在internet上的两台不同的计算机之间使用它。我想我应该有两种不同的PeerConnection:一种是给调用者的(打开页面的第一台计算机),另一种是给被调用者的(打开页面的第二台计算机)。这是错误的吗?你一直认为两个人必须“访问同一个页面”。应该只创建一个peerconnection,一个页面将用于呼叫者,另一个页面用于被呼叫者。您的信令服务器将处理谁连接到谁。你需要一个来连接两个不同的人。网页是无状态的。。。。peerconnections的逻辑是基本的,但应该能让您了解如何处理信号。
$(function () {
var localVideo = document.getElementById('localVideo');
var remoteVideo = document.getElementById('remoteVideo');
var iceServers = {
'iceServers': [
{ 'url': 'stun:stun4.l.google.com:19302' },
{ 'url': 'stun:stunserver.org' },
{ 'url': 'stun:stun.softjoys.com' },
{ 'url': 'stun:stun.voiparound.com' },
{ 'url': 'stun:stun.voipbuster.com' },
{ 'url': 'stun:stun.voipstunt.com' },
{ 'url': 'stun:stun.voxgratia.org' },
{ 'url': 'stun:stun.xten.com' },
{
'url': 'turn:numb.viagenie.ca',
'credential': 'muazkh',
'username': 'webrtc@live.com'
},
{
'url': 'turn:192.158.29.39:3478?transport=udp',
'credential': 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
'username': '28224511:1379330808'
},
{
'url': 'turn:192.158.29.39:3478?transport=tcp',
'credential': 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
'username': '28224511:1379330808'
}
]};
var localStream, pc1, pc2;
var sdpConstraints = {
'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': true
}
};
getUserMedia({
audio: true,
video: true
}, gotLocalStream, function (error) {
alert('error: ' + error.name);
});
$('button').click(function () {
pc1 = new RTCPeerConnection(iceServers);
pc1.onicecandidate = function (event) {
if (event.candidate)
pc2.addIceCandidate(new RTCIceCandidate(event.candidate));
};
pc2 = new RTCPeerConnection(iceServers);
pc2.onicecandidate = function (event) {
if (event.candidate)
pc1.addIceCandidate(new RTCIceCandidate(event.candidate));
};
pc2.onaddstream = gotRemoteStream;
pc1.addStream(localStream);
pc1.createOffer(offer_success, offer_error);
});
function gotLocalStream(stream) {
attachMediaStream(localVideo, stream);
localStream = stream;
}
function gotRemoteStream(event) {
attachMediaStream(remoteVideo, event.stream);
}
function offer_success(desc) {
pc1.setLocalDescription(desc);
pc2.setRemoteDescription(desc);
//pc2.createAnswer(answer_success, answer_error, sdpConstraints);
pc2.createAnswer(answer_success, answer_error);
}
function offer_error(error) {
alert(error.toString());
}
function answer_success(desc) {
pc2.setLocalDescription(desc);
pc1.setRemoteDescription(desc);
}
function answer_error(error) {
alert('error: ' + error.toString());
}
});