0

I am trying to set the getusermedia video constraints like setting min/max frame-rates and resolutions etc... in my peer.js webrtc application which is a simple peer to peer chat application. I have being trying to integrate it into my application but it seems to break it.Any help would be greatly appreciated other online tutorials look different to my app set up. Down at function 1 is where I have been trying to set the constraints it just doesn't show the video anymore. Is this the correct place?

Also will these constraints work on a video-file playing instead of the webcam?. I am using the Google chrome flags that plays a video file instead of a camera.

     navigator.getWebcam = (navigator.getUserMedia ||
                    navigator.webkitGetUserMedia ||
                    navigator.mozGetUserMedia ||
                    navigator.msGetUserMedia);

                // PeerJS object ** FOR PRODUCTION, GET YOUR OWN KEY at http://peerjs.com/peerserver **
                var peer = new Peer({
                    key: 'XXXXXXXXXXXXXXXX',
                    debug: 3,
                    config: {
                        'iceServers': [{
                            url: 'stun:stun.l.google.com:19302'
                        }, {
                            url: 'stun:stun1.l.google.com:19302'
                        }, {
                            url: 'turn:numb.viagenie.ca',
                            username: "XXXXXXXXXXXXXXXXXXXXXXXXX",
                            credential: "XXXXXXXXXXXXXXXXX"
                        }]
                    }
                });

                    // On open, set the peer id so when peer is on we display our peer id as text 
                    peer.on('open', function(){
                        $('#my-id').text(peer.id);
                    });

                    peer.on('call', function(call) {
                        // Answer automatically for demo
                        call.answer(window.localStream);
                        step3(call);
                    });

                    // Click handlers setup
                    $(function() {
                        $('#make-call').click(function() {
                            //Initiate a call!
                            var call = peer.call($('#callto-id').val(), window.localStream);
                            step3(call);
                        });
                        $('end-call').click(function() {
                            window.existingCall.close();
                            step2();
                        });

                        // Retry if getUserMedia fails
                        $('#step1-retry').click(function() {
                            $('#step1-error').hide();
                            step();
                        });

                        // Get things started
                        step1();
                    });







             function step1() {
//Get audio/video stream
navigator.getWebcam({audio: true, video: true}, function(stream){
    // Display the video stream in the video object
    $('#my-video').prop('src', URL.createObjectURL(stream));




                        // Displays error  
                        window.localStream = stream;
                        step2();
                    }, function(){ $('#step1-error').show(); });
                }

                function step2() { //Adjust the UI
                    $('#step1', '#step3').hide();
                    $('#step2').show();
                }

                function step3(call) {
                    // Hang up on an existing call if present
                    if (window.existingCall) {
                        window.existingCall.close();
                    }

                    // Wait for stream on the call, then setup peer video
                    call.on('stream', function(stream) {
                        $('#their-video').prop('src', URL.createObjectURL(stream));
                    });
                    $('#step1', '#step2').hide();
                    $('#step3').show();
                }
4

1 回答 1

2

您的 JavaScript 看起来无效。您不能在函数参数列表中声明 var。你贴错了吗?尝试:

var constraints = {
  audio: false,
  video: { mandatory: { minWidth: 1280, minHeight: 720 } }
};
navigator.getWebcam(constraints, function(stream){ etc. }

现在它至少是有效的 JavaScript。我对 PeerJS 不熟悉,但是您使用的约束看起来像 Chrome 的约束,所以如果您使用的是 Chrome,那么希望它们能够工作,除非 PeerJS 出于某种原因以不同的方式进行操作。

您的主题说“WebRTC 相机约束”,所以我应该提到 Chrome 约束是非标准的。请参阅此答案以获取解释。

于 2015-03-28T05:47:05.927 回答