2014-02-07 84 views
0

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

谢谢先进!

回答

0

我没有看到你正在处理客户端的'newConnection'。你只是散发而已。我认为

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

应改为

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