9

シナリオ: TURN サーバーが特定の通話に使用されているかどうか、および PeerConnection の作成中に指定した TURN サーバーの配列のどれが使用されているかを知りたいと考えています。現在、次の 2 つのオプションがあります。

  • Wireshark: ただし、企業プロキシの背後にあり、TURN サーバーがその外部にある場合、wireshark はプロキシ IP を宛先として表示します (バックグラウンドで実行する不便さについても言及しません)。
  • 統計ページを調べて、chrome --> chrome://webrtc-internals と Firefox --> about:webrtc を調べます。

上記の 2 つの代替手段を使用して、プログラムでこれを決定し、アプリケーション ページを離れる必要がないようにしたいと考えています。

4

2 に答える 2

4

以下のコードを書いてテストしました。Firefox と Chrome の両方の最新バージョンで動作し、getConnectionDetails接続の詳細を解決する promise を返します。

function getConnectionDetails(peerConnection){


  var connectionDetails = {};   // the final result object.

  if(window.chrome){  // checking if chrome

    var reqFields = [   'googLocalAddress',
                        'googLocalCandidateType',   
                        'googRemoteAddress',
                        'googRemoteCandidateType'
                    ];
    return new Promise(function(resolve, reject){
      peerConnection.getStats(function(stats){
        var filtered = stats.result().filter(function(e){return e.id.indexOf('Conn-audio')==0 && e.stat('googActiveConnection')=='true'})[0];
        if(!filtered) return reject('Something is wrong...');
        reqFields.forEach(function(e){connectionDetails[e.replace('goog', '')] = filtered.stat(e)});
        resolve(connectionDetails);
      });
    });

  }else{  // assuming it is firefox
    return peerConnection.getStats(null).then(function(stats){
        var selectedCandidatePair = stats[Object.keys(stats).filter(function(key){return stats[key].selected})[0]]
          , localICE = stats[selectedCandidatePair.localCandidateId]
          , remoteICE = stats[selectedCandidatePair.remoteCandidateId];
        connectionDetails.LocalAddress = [localICE.ipAddress, localICE.portNumber].join(':');
        connectionDetails.RemoteAddress = [remoteICE.ipAddress, remoteICE.portNumber].join(':');
        connectionDetails.LocalCandidateType = localICE.candidateType;
        connectionDetails.RemoteCandidateType = remoteICE.candidateType;
        return connectionDetails;
    });

  }
}

1 つのことを指摘したいと思います。これら 3 つの方法はすべて、1 つのシナリオで失敗します。異なるポートで同じマシンから実行されている 2 つのターン サーバー。私が見つけた唯一の信頼できる方法は、ターン サーバーのログを確認することでした。

于 2015-08-21T09:38:23.423 に答える