首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webrtc按每次视频聊天,但只需要一方发送视频到另一方

webrtc按每次视频聊天,但只需要一方发送视频到另一方
EN

Stack Overflow用户
提问于 2017-02-10 03:48:38
回答 1查看 1.9K关注 0票数 0

我读过很多关于webrtc的例子,但是我不知道如何在A和B之间聊天视频p2p,但是只需要A用p2p连接发送流视频到B,怎么做呢?我试图在B{视频: false}中禁用视频本地,但它有错误,不能工作。

我的脚本

代码语言:javascript
复制
<!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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-10 12:24:45

在发送方启用视频,禁用音频。在接收器上将两者都禁用。试试下面的代码

代码语言:javascript
复制
<!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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42151183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档