2016-05-04 4 views
2

WebRTC - ソースからレシーバへのブラウザプロキシビデオを持つことは可能ですか?たとえば

  • ブラウザAが放送されているビデオ
  • ブラウザBは
  • ブラウザCが

はそれが可能な場合は、ブラウザのように何かをされているビデオを受信して​​いる途中の男ですBはAとCとの間の仲介役を果たすか?

第2に、BがA のブロードキャストされたビデオを両方ともCに転送することは可能でしょうか?

答えて

3

確かに正常です。 (クローム用https fiddleを使用してください):

function Hop() { 
 
    this.pc1 = new RTCPeerConnection(); 
 
    this.pc2 = new RTCPeerConnection(); 
 

 
    var add = (pc, can) => can && pc.addIceCandidate(can).catch(log); 
 
    this.pc1.onicecandidate = e => add(this.pc2, e.candidate); 
 
    this.pc2.onicecandidate = e => add(this.pc1, e.candidate); 
 
    this.pc2.oniceconnectionstatechange = e => log(this.pc2.iceConnectionState); 
 
}; 
 
Hop.prototype.send = function(stream) { 
 
    this.pc1.addStream(stream); 
 
    return Promise.all([ 
 
    new Promise(resolve => this.pc2.onaddstream = resolve), 
 
    this.pc1.createOffer() 
 
     .then(offer => this.pc1.setLocalDescription(offer)) 
 
     .then(() => this.pc2.setRemoteDescription(this.pc1.localDescription)) 
 
     .then(() => this.pc2.createAnswer()) 
 
     .then(answer => this.pc2.setLocalDescription(answer)) 
 
     .then(() => this.pc1.setRemoteDescription(this.pc2.localDescription)) 
 
    ]) 
 
    .then(results => results[0].stream); 
 
}; 
 

 
var AtoB = new Hop(), BtoC = new Hop(); 
 

 
navigator.mediaDevices.getUserMedia({ video: true }) 
 
    .then(stream => AtoB.send(v1.srcObject = stream)) 
 
    .then(stream => BtoC.send(v2.srcObject = stream)) 
 
    .then(stream => v3.srcObject = stream) 
 
    .catch(e => log(e)); 
 

 
var log = msg => div.innerHTML += msg + "<br>";
<video id="v1" height="120" width="160" autoplay muted></video> 
 
<video id="v2" height="120" width="160" autoplay></video> 
 
<video id="v3" height="120" width="160" autoplay></video><br> 
 
<div id="div"></div> 
 
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>

あなたが好きなようにあなたはできるだけ多くのホップを作成することができます。

+2

ジブ、それについてのサンプルもあります: https://webrtc.github.io/samples/src/content/peerconnection/multiple-relay/ –

+0

品質が低下するのはなぜですか?再エンコードされているのか、パケットがドロップされていますか? – transistor09

+0

私たちはリモートストリームを送信することが許されていますか?damnit、それを知らなかった – mido

関連する問題