我正在尝试制作一个WebRTC视频会议服务,它似乎有效,我收到了其他对等流,但视频没有再现。
这是JavaScript代码:
var localStream, localPeerConnection, remotePeerConnection;
localPeerConnection = new RTCPeerConnection( null );
localPeerConnection.onaddstream = function ( event ) {
// Here is where I receive the other Peer stream
remote.src = URL.createObjectURL( event.stream );
remote.play();
};
var local = document.getElementById('person1'),
remote = document.getElementById('person2');
navigator.getUserMedia({ video: true, audio: false }, function ( stream ) {
local.src = URL.createObjectURL( stream );
localPeerConnection.addStream( stream );
localStream = stream;
}, function ( error ) {
alert("Error getting your data");
console.log( "ERROR OCURRED: " + error );
});
function createUser () {
localPeerConnection.createOffer( function ( desc ){
localPeerConnection.setLocalDescription( desc );
socket.emit('newConnection', { description: desc });
});
};
socket.on('newUser', function ( description ) {
localPeerConnection.setRemoteDescription( new RTCSessionDescription( description.description ), function () {
localPeerConnection.createAnswer( function ( desc ) {
localPeerConnection.setLocalDescription( desc );
}, function ( err ) {
console.log( err )
});
}, function ( err ) {
console.log(err);
});
});
我不知道为什么会这样。调用函数createUser()来启动调用。启动呼叫的对等方没有得到事件onaddstream
,也许这就是问题所在。当接听呼叫的对等方获取onaddstream
事件时,将调用该函数,并且接收的流与另一个对等方生成的流相同。
感谢先进!
答案 0 :(得分:0)
我没有看到你在客户端处理'新连接'。你只是发射它。我想
socket.on('newUser', function ( description ) {
应改为
socket.on('newConnection', function ( description ) {