我阅读了很多有关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。

最佳答案

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

<!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>

关于javascript - webrtc对等视频聊天,但仅需将视频发送到另一侧,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42151183/

10-17 02:53