Skip to content

Instantly share code, notes, and snippets.

@tbhaxor
Created April 10, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbhaxor/c4b826f856414f5d9829e7444ebaa003 to your computer and use it in GitHub Desktop.
Save tbhaxor/c4b826f856414f5d9829e7444ebaa003 to your computer and use it in GitHub Desktop.
Capture Video and Audio in Single Browser via WebRTC Media API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Capture Video and Audio</title>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
</head>
<body>
<video autoplay></video>
<p>Working</p>
<script>
navigator.mediaDevices
.getUserMedia({
audio: true,
video: true
})
.then((stream) => {
document.querySelector("p").textContent = "Connected";
console.log("connected audio");
let video = document.querySelector("video");
video.srcObject = stream;
video.play();
})
.catch((e) => {
alert(e);
document.querySelector("p").textContent = "Not Connected";
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment