Skip to content

Instantly share code, notes, and snippets.

@hakobyansen
Last active July 25, 2020 10:55
Show Gist options
  • Select an option

  • Save hakobyansen/3584881fb399e7feb502959cf0bbbb60 to your computer and use it in GitHub Desktop.

Select an option

Save hakobyansen/3584881fb399e7feb502959cf0bbbb60 to your computer and use it in GitHub Desktop.
A simple script to stream a video in the browser.
window.onload = function() {
navigator.getUserMedia({
video: true,
audio: false
}, function(localMediaStream) {
console.log(localMediaStream)
var video = document.querySelector('.camera');
video.srcObject = localMediaStream;
video.onloadedmetadata = function(e) {
};
video.play();
}, function(error) {
if(error === PERMISSION_DENIED) {
//
} else {
alert(error);
}
})
document.querySelector('.full-screen').onclick = function () {
if (!document.fullscreenElement) {
document.querySelector('.camera').requestFullscreen().catch(err => {
alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
});
} else {
document.exitFullscreen();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment