Last active
February 8, 2018 17:14
-
-
Save matt-mcalister/da36b8583475e042e87af965c6c3e4c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const videoPlayer = document.getElementById("video-player") // this is a <video> element | |
onSuccessWithSrcObject(stream) { | |
videoPlayer.srcObject = stream; | |
} | |
onSuccessWithSrc(stream) { | |
videoPlayer.src = window.URL.createObjectURL(stream); | |
} | |
navigator.mediaDevices.getUserMedia({ audio: true, video: true }) | |
.then(stream => { | |
if ("srcObject" in videoPlayer) { | |
onSuccessWithSrcObject(stream) | |
} else { | |
onSuccessWithSrc(stream) | |
} | |
}) | |
.catch( err => alert(`Bummer! ${err.name}.`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment