2014-02-07 112 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) {