2017-12-05 3 views
0

最近私はWebRTCを実験しています。私は本当にそれの周りに私の頭をラップしようとしていたと同時に、私はそれをテストすることができます参照してください。 WebRTC接続の問題

は、だから私は二つのこと

  1. 接続は一貫性があるかどうかをチェックテストを書きましたか?
  2. ピアの数が接続を減速させますか?そうであれば、閾値が目立つ前にどのくらいですか?

私のテストで気づいたことは、(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(); 
+0

remoteDataChannelが正しく作成されている場合にのみチェックされています。また、あなたはストリーミングしていないので、ストリームが利用可能かどうかは分かりません。とにかく 'await'の代わりに、あなたの経験を改善するためにエラーをチェックすることができます。最後に、別のブラウザを使用してピア間の接続を正しく確認する仮想マシンを作成します。 – JTejedor

+0

私のテストの問題は、データチャネルが他のピアに時折転送されないように見えることです。私が最初に気付いたのは、私が2人の仲間の間に同様の設定をしたときでした。だから私は試してみるためにこのテストを書きました。私はtry catchを削除してもそれを指摘したい。まだエラーは報告されていません。だから、同輩のように待機している – asosnovsky

+0

あなたのテストでは、一度開いて、私はデータチャネルに送信されたメッセージは表示されません。私は正しいですか?それでも。接続設定にエラーがあり、氷の候補を交換していないかどうかわかりません... – JTejedor

答えて

0

ので@JTejedorコメントや提案をした後、私は私の接続テストが誤って設定したことに気づきました。この問題を抱えている人は、同僚が登録した氷の候補をお互いに送っていることを確認する必要があります。

これが行われ、私のオフライン版で

次のように:

// Map Ice Candidate 
remoteConnection.onicecandidate = evt => { 
    if(evt.candidate) { 
     localConnection.addIceCandidate(evt.candidate) 
    } 
} 
localConnection.onicecandidate = evt => { 
    if(evt.candidate) { 
     remoteConnection.addIceCandidate(evt.candidate) 
    } 
} 

を使用すると、このソケット(または他のサーバー側の溶液)で作業している場合は、他のピアにソケットを介してこれらを送信してください。ここで

は(常に渡し)の作業テストです:

// Ice Servers 
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" 
    ] 
}] 

// Run the test once 
async function initExample(){ 
    // Init Local Connections 
    var localConnection = new RTCPeerConnection({iceServers}); 
    var remoteConnection = new RTCPeerConnection({iceServers});//this is really "remote" its simulated 

    // Map Ice Candidate 
    remoteConnection.onicecandidate = evt => { 
     if(evt.candidate) { 
      localConnection.addIceCandidate(evt.candidate) 
     } 
    } 
    localConnection.onicecandidate = evt => { 
     if(evt.candidate) { 
      remoteConnection.addIceCandidate(evt.candidate) 
     } 
    } 

    // Create Data Channels 
    var remoteDataChannel;// this is added later 
    var localDataChannel = localConnection.createDataChannel('DataChannel'); 

    // Tie end of promise to getting the datachannel 
    return new Promise(async res => { 
     // Catch DataChannel when it is sent from local to remote 
     remoteConnection.ondatachannel = dataChannelEvent => { 
      console.log('GOT CHANNEL', dataChannelEvent) 
      remoteDataChannel = dataChannelEvent.channel 
      res(remoteDataChannel); 
     } 

     // 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); 

    }) 
} 

// A Promisified Timeout 
const promisedTimeout = (timeout = 10000) => new Promise((resolve, reject) => { 
    let wait = window.setTimeout(() => { 
    window.clearTimeout(wait); 
    resolve(false); 
    }, timeout) 
}) 

// Run the test N times 
async function test(N=100){ 
    // Init variables 
    const stats = {pass:0, fail: 0, N}; 
    const results = []; 

    // Loop 
    for (var i = 0; i <= N; i++) { 
     // log 
     console.log({...stats, i}); 

     // This will each example against a timeout, 
     // if the timeout finishes first, then this test will be marked as fail 
     let pass = await Promise.race([ 
      initExample(), 
      promisedTimeout() 
     ]); 
     if(pass) { 
      stats.pass ++; 
     }else{ 
      stats.fail ++; 
     } 
     results.push(pass); 
    } 
    return {results,stats}; 
} 

// Run the test 
test()