Skip to content

Instantly share code, notes, and snippets.

@widyakumara
Created September 30, 2019 10:08
Show Gist options
  • Save widyakumara/044fe78616a4a57cf1deff9c74762199 to your computer and use it in GitHub Desktop.
Save widyakumara/044fe78616a4a57cf1deff9c74762199 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>webcam</title>
<style type="text/css">
body {
margin: 0;
}
.webcam {
overflow: hidden;
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.webcam-wrap {
flex: 1;
background-color: #900;
}
.webcam-control {
height: 80px;
background-color: #090;
}
#webcam-video {
width: 100%;
height: 100%;
object-fit: contain;
}
</style>
</head>
<body>
<div class="webcam">
<div class="webcam-wrap">
<video id="webcam-video" autoplay></video>
</div>
<div class="webcam-control">
<pre>show control here</pre>
</div>
</div>
<script>
const constraints = {
video: true
};
const video = document.querySelector('#webcam-video');
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
video.srcObject = stream
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment