简体   繁体   English

WebRTC视频流错误

[英]WebRTC video stream error

I'm trying to make a WebRTC video-conference service, and it seems to work, I've receive the other peer stream, but the video is not reproducing. 我正在尝试提供WebRTC视频会议服务,但似乎可以正常工作,我已经收到了其他对等流,但是视频无法复制。

This is the JavaScript code: 这是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); 
        });

    });

I don't know why this is happening. 我不知道为什么会这样。 The function createUser() is called to start the call. 调用函数createUser()开始调用。 The peer who start the call doesn't get the event onaddstream , maybe that's the problem. 发起呼叫的对等方没有在onaddstream获取事件,也许就是问题所在。 When the peer who answer the call, gets the onaddstream event, the function is called, and the stream which receives is the same that the other peer is generating. 当应答呼叫的对等方收到onaddstream事件时,将调用该函数,并且接收到的流与另一对等onaddstreamonaddstream的流相同。

Thank's advanced! 谢谢高级!

I don't see you are handling 'newConnection' on clientside. 我看不到您在客户端处理“ newConnection”。 You are just emitting that only. 您只是在散发出光。 I think 我认为

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

should be changed to 应该更改为

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM