2017-02-10 40 views
0

我讀了很多關於webrtc的例子,但我不明白如何聊天A和B之間的視頻P2P,但只需要一個發送流視頻到B使用p2p連接,如何做到這一點? 我試圖在B {video:false}中禁用本地視頻,但它有錯誤,無法正常工作。webrtc每個視頻聊天,但只需要一方發送視頻到另一個

我的腳本

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <script src="https://simplewebrtc.com/latest-v2.js"></script> 
 
     <script type="text/javascript"> 
 

 
      var webrtc = new SimpleWebRTC({ 
 
       // the id/element dom element that will hold "our" video 
 

 
       localVideoEl: 'localVideo', 
 

 
       // the id/element dom element that will hold remote videos 
 
       remoteVideosEl: 'remotesVideos', 
 
       // immediately ask for camera access 
 
       autoRequestMedia: true, 
 
       //https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia 
 
       //https://github.com/andyet/signalmaster/blob/master/README.md 
 
       media: { 
 
         audio: false, 
 
         video: { 
 
          //width: 720, 
 
          width: {ideal: 640}, 
 
          // height: 1280, 
 
          height: {ideal: 480}, 
 
          frameRate: {ideal: 15} 
 
         } 
 
       }, 
 
       receiveMedia: { 
 
        offerToReceiveAudio: 0, 
 
        offerToReceiveVideo: 1 
 
       } 
 
      }); 
 

 

 
      // we have to wait until it's ready 
 
      webrtc.on('readyToCall', function() { 
 
       // you can name it anything 
 
       webrtc.joinRoom('zika ghe vl'); 
 
      }); 
 

 

 
     </script> 
 
    </head> 
 
    <body> 
 
     <div id="remotesVideos"></div> 
 
    </body> 
 
</html>
我的例子從這裏得到: https://github.com/andyet/SimpleWebRTC 那麼,如何在B(觀察者)禁止發送localVideo B與A,只是發送流視頻到B

+0

您可以包括'你的努力在問題javascript'? – guest271314

回答

1

在發送方啓用視頻,禁用音頻。在接收器禁用兩個。 嘗試下面的代碼

<!DOCTYPE html> 
<html> 
    <head> 
     <script src="https://simplewebrtc.com/latest-v2.js"></script> 
     <button onclick="start(false)">Receive video</button> 
      <button onclick="start(true)"">Send video</button> 
     <script type="text/javascript"> 
      function start (e) { 

       /** 
        have separate settings to get the trigger form UI 
       */ 
       var videoSettings = { 
          //width: 720, 
          width: {ideal: 640}, 
          // height: 1280, 
          height: {ideal: 480}, 
          frameRate: {ideal: 15} 
         } 
       if(!e) videoSettings = e; 
       new SimpleWebRTC({ 
       // the id/element dom element that will hold "our" video 

        localVideoEl: 'localVideo', 

        // the id/element dom element that will hold remote videos 
        remoteVideosEl: 'remotesVideos', 
        // immediately ask for camera access 
        autoRequestMedia: true, 
        //https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia 
        //https://github.com/andyet/signalmaster/blob/master/README.md 
        media: { 
          audio: false, 
          video: videoSettings 
        }, 
        receiveMedia: { 
         offerToReceiveAudio: 0, 
         offerToReceiveVideo: 1 
        } 
       }).on('readyToCall', function() { 
        // you can name it anything 
        this.joinRoom('zika ghe vl'); 
       }); 
      }  

     </script> 
    </head> 
    <body> 
     <div id="remotesVideos"></div> 
    </body> 
</html> 
+0

不,我只想發送從A到B的視頻直播流,從A到B只有一個方向,不需要音頻。你能做到嗎? (通過p2p連接一對一) –

+0

非常感謝,非常簡單,但我之前無法理解^^ –