【发布时间】:2014-02-07 15:20:01
【问题描述】:
我正在尝试制作 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事件时,调用该函数,接收到的流与其他对等方正在生成的流相同。
非常感谢!
【问题讨论】:
标签: javascript video stream webrtc