2016-06-13 12 views
5

WebRTC kullanarak görüntülü arama web uygulaması yapmaya çalışıyorum. Ben angularjs kullanarak ve bu hatayı alıyorumDOMException: Uzak teklif sdp ayarlanamadı: Yanlış durum çağrıldı: STATE_SENTOFFER

express.io am: DOMException: yanlış durumda Aranan: Uzaktan teklif SDP ayarlanamadı STATE_SENTOFFER

benim kod bazıları ise:

// in controller (socket is already defined in controller) 
var videolocal = document.getElementById('videolocal'); 
var videoremote = document.getElementById('videoremote'); 
var streamlocal = null; 
var pc = null; 
window.URL = window.URL || window.webkitURL; 
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; 
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; 

var configuration = {'iceServers': [ 
     // {'url': 'stun:stun.services.mozilla.com'}, 
     {'url': 'stun:stun.l.google.com:19302'} 
    ]}; 

// run start(true) to initiate a call 
$scope.start = function() { 
    console.log('start'); 

    // get the local stream, show it in the local video element and send it 
    navigator.getUserMedia({ "audio": true, "video": true }, function (stream) { 
     videolocal.src = URL.createObjectURL(stream); 
     pc = new RTCPeerConnection(configuration); 
     pc.addStream(stream); 

     // once remote stream arrives, show it in the remote video element 
     pc.onaddstream = function (evt) { 
      console.log('onaddstream'); 
      videoremote.src = URL.createObjectURL(evt.stream); 
     }; 

     // send any ice candidates to the other peer 
     pc.onicecandidate = function (evt) { 
      console.log('onicecandidate'); 
      if(evt.candidate){ 
       socket.emit('video_call',{user:2, type: 'candidate', candidate: evt.candidate}); 
      }      
     };       

     // create an offer 
     pc.createOffer(function (offer) { 
      socket.emit('video_call', {user:2, type: "offer", offer: offer}); 
      pc.setLocalDescription(offer); 
     }, function (error) { 
      alert("Error when creating an offer"); 
     }); 
    }, function() {alert('error in start')}); 
} 
$scope.start(); 

socket.on('video_call', function (data) { 
    console.log(data); 
    //when somebody sends us an offer 
    function handleOffer(offer) { 
     // this line is giving error 
     pc.setRemoteDescription(new RTCSessionDescription(offer), function(){alert('success')}, function(e){ console.log(e); alert(e)}); 

     //create an answer to an offer 
     pc.createAnswer(function (answer) { 
      pc.setLocalDescription(answer); 
      socket.emit('video_call', {user:2, type: "answer", answer: answer});        
     }, function (error) { 
      console.log(error); 
      alert("Error when creating an answer"); 
     }); 
    }; 

    //when we got an answer from a remote user 
    function handleAnswer(answer) { 
     pc.setRemoteDescription(new RTCSessionDescription(answer)); 
    }; 

    //when we got an ice candidate from a remote user 
    function handleCandidate(candidate) { 
     pc.addIceCandidate(new RTCIceCandidate(candidate)); 
    }; 

    switch(data['type']) { 
     case "offer": 
      handleOffer(data["offer"]); 
      break; 
     case "answer": 
      handleAnswer(data['answer']); 
      break; 
     //when a remote peer sends an ice candidate to us 
     case "candidate": 
      handleCandidate(data['candidate']); 
      break; 
     default: 
      break; 
    } 
}); 
sunucuda

:

// this function is called on video_call event 
video_call: function (data) { 
    var id = data.user; 

    // if user is active 
    // users is dict of users (user_id as key) 
    if(Object.keys(users).indexOf(id.toString()) > -1){ 
     // for each device of the user 
     users[id].forEach(function(user_socket){ 
      console.log(data); 
      user_socket.emit('video_call', data);    
     }); 
    } 
} 

herkes bu kod ile sorun nedir söyleyebilir edin. Yerel akış düzgün bir şekilde yakalanıyor. Chromium tarayıcı kullanıyorum. sunucuda

veri: enter image description here

+0

JS'de bu hatayı üreten kesin satır nedir? –

+0

Bir teklif alındığında, bu satır "pc.setRemoteDescription (yeni RTCSessionDescription (teklif), işlev() {alert ('başarı')}, işlev (e) {console.log (e); alert (e)}) ;" uyarılıyor (ve ayrıca konsolda yazdırılıyor): DOMException: Uzak teklif sdp ayarlanamadı: Yanlış durumda çağrıldı: STATE_SENTOFFER. Sonra yazdırır: Yakalanmadı (vaat) DOMException: ICE adayı işlenirken hata oluştu –

cevap

2

Sorun senin handleOffer() işlevinde başka PeerConnection'ı oluşturabilir ve bu pc setRemoteDescription() aramak gerektiğini düşünüyorum.

Kodumda sahip olduğum şey budur.

DÜZENLEME: Inofficial link Eğer bölüm 11.7 gidip (teklif gönderilir ve diğer akran bunu alır) 15 sonrası adımları kontrol edebilirsiniz.

+0

Şimdi bu hatayı alıyorum: Yakalanmadı (sözde) DOMException: ICE adayı işlenirken hata oluştu. Lütfen çalışma örneğinin en basit ön uç kodunu paylaşabilirsiniz. –

+0

Tüm kodları paylaşamıyorum çünkü şirketimin sahibi ... 'pc.addIceCandidate()' 'remote_pc' olarak değiştirdiniz mi? Bu 2 eş Bağlantılar arasında ayrım yapmanız gerekir. –

+0

remote_pc ve videoremote (uzaktan eleman için video etiketi) bağlantısına nasıl sahipsiniz? –

İlgili konular