为什么此JavaScript和WebRTC代码不起作用?

问题描述 投票:0回答:2
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <meta charset="utf-8">
    <title>Vid Chat</title>
</head>

<body>
    <video autoplay>

    </video>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript">
        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
        var constrainsts = {
            audio: true,
            video: true
        };
        var videoArea = $("video");
        navigator.getUserMedia(constrainsts, results, error);

        function results(stream) {
            videoArea.srcObject = stream;
            videoArea[0].play();
        }

        function error() {
            console.log("we messed up");
        }
    </script>
</body>

</html>

我正在使用express将此作为ejs文件。为什么不起作用?我正在使用node.js,express和ejs。我做错什么了吗?它也不会给出任何错误。

javascript node.js express webrtc ejs
2个回答

0
投票
getUserMedia需要安全的上下文,即https。参见here
© www.soinside.com 2019 - 2024. All rights reserved.