WebRTC。不显示视频

WebRTC. Not showing video

我决定研究WebRTC,但不显示视频。请帮忙。 我究竟做错了什么?使用 Chrome 我的代码:

<html>

<head>
    <meta charset="UTF-8">
</head>

<body>
    <script>
        window.onload = function () {
            navigator.webkitGetUserMedia({ video: true }, getStream, noStream);
        };

        function getStream(stream) {
            var url = window.webkitURL.createObjectURL(stream);            
            var video = document.getElementById('video');
            video.src = url;
        }

        function noStream(faild) {

        }
    </script>
    <video id="video" autoplay="autoplay" width="400"></video>
</body>

</html>

工作代码:

<head>
    <meta charset="UTF-8"></script>
</head>

<body>
    <script>
        window.onload = function () {
            var constraints = { audio: true, video: { width: 1280, height: 720 } }; 

navigator.mediaDevices.getUserMedia(constraints)
.then(function(mediaStream) {
  var video = document.querySelector('video');
  video.srcObject = mediaStream;
  video.onloadedmetadata = function(e) {
    video.play();
  };
})
.catch(function(err) { console.log(err.name + ": " + err.message); });
        };
    </script>
    <video id="video" autoplay="autoplay" width="400"></video>
</body>

</html>