WEBRTC视频流错误



我正在尝试制作一个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事件时,该功能被调用,并且接收的流与另一个对等式生成的流相同。

谢谢的高级!

我看不到您在客户端处理'newconnection'。您只是散发出来。我认为

socket.on('newUser', function ( description ) {

应该更改为

 socket.on('newConnection', function ( description ) {

相关内容

  • 没有找到相关文章

最新更新