dimanche 1 mars 2020

Webcam doesn't work on WebServer, but local it does

i have two files in a directory on my Webserver. A HTML-File called "index.html" with the following code:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="UTF-8">
    <script defer src="webcam.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 100vw;
            height: 100vh;
        }

        video {
            object-fit: fill;
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>
<body>
    <div>
        <video id="video" autoplay muted></video>
    </div>
</body>
</html>

And a JavaScript-File named "webcam.js" with the following code:

const video = document.getElementById('video')

function startVideo() {
    navigator.getUserMedia(
        { video: {} },
        stream => video.srcObject = stream,
        err => console.error(err)
    )
}

startVideo()

When you open the HTML-File locally, the two are working as intended and you see yourself on the Website. But if you upload them on a Webserver, then it doesn't work. Does anyone know why?




Aucun commentaire:

Enregistrer un commentaire