最近私はWebRTCを実験しています。私は本当にそれの周りに私の頭をラップしようとしていたと同時に、私はそれをテストすることができます参照してください。 WebRTC接続の問題
は、だから私は二つのこと- 接続は一貫性があるかどうかをチェックテストを書きましたか?
- ピアの数が接続を減速させますか?そうであれば、閾値が目立つ前にどのくらいですか?
私のテストで気づいたことは、(1)が真ではないということです。私が見つけたのは、このテスト結果の平均が100から10〜20回程度だったということでした。
誰かが見て、私がテストを間違って書いたかどうかを知らせたり、失敗の理由を特定したりすることです。
これはChrome 62でのみ実行しました。アイスサーバのリストはhttps://github.com/DamonOehlman/freeiceから取得しました。そこで、以下
は、私が書いたテストです:
const localStream = await navigator.mediaDevices.getUserMedia({video:true});
const iceServers = [{
urls: [
"stun:stun.l.google.com:19302",
"stun:stun1.l.google.com:19302",
"stun:stun2.l.google.com:19302",
"stun:stun3.l.google.com:19302",
"stun:stun4.l.google.com:19302",
"stun:stun.ekiga.net",
"stun:stun.ideasip.com",
"stun:stun.rixtelecom.se",
"stun:stun.schlund.de",
"stun:stun.stunprotocol.org:3478",
"stun:stun.voiparound.com",
"stun:stun.voipbuster.com",
"stun:stun.voipstunt.com",
"stun:stun.voxgratia.org"
]
}]
async function initExample(){
try{
// Init Local Connections
var localConnection = new RTCPeerConnection({iceServers});
var remoteConnection = new RTCPeerConnection({iceServers});
// Create Data Channels
var remoteDataChannel;// this is added later
var localDataChannel = localConnection.createDataChannel('DataChannel');
// Configure Stream
var remoteStream;// this is added later
localConnection.addStream(localStream)
// Catch DataChannel when it is sent from local to remote
remoteConnection.ondatachannel = dataChannelEvent => {
remoteDataChannel = dataChannelEvent.channel
}
// Catch MediaStream when it is sent from local to remote
remoteConnection.onaddstream = mediaStreamEvent => {
remoteStream = mediaStreamEvent.stream;
}
// Create Offer
var offer = await localConnection.createOffer();
await localConnection.setLocalDescription(offer);
await remoteConnection.setRemoteDescription(localConnection.localDescription);
// Create Answer
var answer = await remoteConnection.createAnswer();
await remoteConnection.setLocalDescription(answer);
await localConnection.setRemoteDescription(remoteConnection.localDescription);
// Return Results
return {
localConnection, remoteConnection,
localDataChannel, localStream,
get remoteDataChannel(){
return remoteDataChannel
},
get remoteStream(){
return remoteStream;
},
}
}catch(e){
console.error(e)
}
}
async function test(N=100){
const stats = {pass:0, fail: 0, N};
const results = [];
for (var i = 0; i < N; i++) {
console.log({...stats, i})
let conn = await initExample();
if(conn.remoteDataChannel){
stats.pass++;
}else{
stats.fail++;
}
results.push(conn);
}
return results;
}
var r = await test();
remoteDataChannelが正しく作成されている場合にのみチェックされています。また、あなたはストリーミングしていないので、ストリームが利用可能かどうかは分かりません。とにかく 'await'の代わりに、あなたの経験を改善するためにエラーをチェックすることができます。最後に、別のブラウザを使用してピア間の接続を正しく確認する仮想マシンを作成します。 – JTejedor
私のテストの問題は、データチャネルが他のピアに時折転送されないように見えることです。私が最初に気付いたのは、私が2人の仲間の間に同様の設定をしたときでした。だから私は試してみるためにこのテストを書きました。私はtry catchを削除してもそれを指摘したい。まだエラーは報告されていません。だから、同輩のように待機している – asosnovsky
あなたのテストでは、一度開いて、私はデータチャネルに送信されたメッセージは表示されません。私は正しいですか?それでも。接続設定にエラーがあり、氷の候補を交換していないかどうかわかりません... – JTejedor