WebRTC を簡素化するhttps://github.com/HenrikJoreteg/RTCPeerConnectionを使用していますが、それでも動作しません。WebRTC ピア接続 (offer、answer、ice) は確立されますが、onaddstream は呼び出されません。
(次のコードを使用する同じ html で 2 つのブラウザー タブを開き、start 関数を実行してビデオを取得し、peer を実行して接続を開始してコードを実行します。)
このコードのバグを指摘してくれる人はいますか?
var local_stream;
var localvid = document.getElementById('localvid');
var remotevid = document.getElementById('remotevid');
var servers= {iceServers: [{"url": "stun:stun.l.google.com:19302"}]};
var constraints = {optional: [{"DtlsSrtpKeyAgreement": true}]};
var peerConn = new PeerConnection(servers,constraints);
function start(){
navigator.getUserMedia ||
(navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia || navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia({
video: true,
audio: false
}, onSuccess, function(){});
} else {
alert('getUserMedia is not supported in this browser.');
}
}
function onSuccess(stream){
localvid.src = window.webkitURL.createObjectURL(stream);
local_stream = stream;
localvid.autoplay = true;
}
function peer(){
peerConn.addStream(local_stream);
peerConn.offer({ mandatory: { OfferToReceiveAudio:false, OfferToReceiveVideo: true} },
function( err, offer){
if(!err){
console.log("Creating an offer...");
socket.emit('offer',offer);
}
}
);
}
peerConn.on('ice', function(candidate){
if(candidate){
console.log("Sending ice...");console.log(candidate);
socket.emit('ice',candidate);
}else { console.log("End of candidates.");}
});
peerConn.on('streamAdded',function(stream){
console.log("Adding stream..");
remotevid.src = window.webkitURL.createObjectURL(stream);
remotevid.autoplay = true;
});
socket.on('offer',function(offer){
peerConn.answer(offer,function (err,answer){
if(!err){
console.log("Creating the answer...");console.log(answer);
socket.emit('answer',answer);
}
});
});
socket.on('answer', function(answer){
console.log("Got the answer...");
peerConn.handleAnswer(answer);
});
socket.on('ice', function (candidate){
console.log("Processing ice...");
peerConn.processIce(candidate);
console.log(candidate);
});