【问题标题】:webrtc per to per video chat but only need one side to send video to anotherwebrtc 点对点视频聊天,但只需要一侧将视频发送到另一侧
【发布时间】:2017-02-17 16:26:36
【问题描述】:

我阅读了很多关于 webrtc 的示例,但我不明白如何在 A 和 B 之间进行视频 p2p 聊天,但只需要 A 使用 p2p 连接向 B 发送流视频,如何做到这一点? 我尝试在 B {video : false} 中禁用本地视频,但出现错误,无法正常工作。

我的脚本

<!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(观察者)如何禁用将B的localVideo发送给A,只是A将流视频发送给B。

【问题讨论】:

  • 您能否包含您在 Question 中尝试过的javascript

标签: javascript video-streaming webrtc simplewebrtc


【解决方案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>

【讨论】:

  • 不不,我只想从 A 发送视频直播到 B,只是从 A 到 B 的一个方向,不需要音频。你能做到吗? (通过 p2p 连接一对一)
  • 非常感谢,这么简单但是之前看不懂^^
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
  • 1970-01-01
  • 2013-07-23
  • 1970-01-01
  • 2011-04-22
  • 2013-11-17
相关资源
最近更新 更多