Last active
July 26, 2017 19:44
-
-
Save dtipson/4ff1f55fb194f1024a445a0c457a1ead to your computer and use it in GitHub Desktop.
Can run in console on any https site on Chrome/Firefox
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
document.body.innerHTML = ''; | |
const delay = milliseconds => x => new Promise(resolve => setTimeout(resolve, milliseconds, x)); | |
//requestRecord :: Object (optional) -> Promise Stream | |
const requestRecord = (config={video:true, audio:true}) => { | |
return navigator.mediaDevices && navigator.mediaDevices.getUserMedia ? | |
navigator.mediaDevices.getUserMedia(config).then(delay(1400)) : // delay avoid startup flash | |
Promise.reject('no support for getUserMedia'); | |
}; | |
const createVideo = videoURL => { | |
console.log('creating video w/', videoURL); | |
var video = document.createElement('video'); | |
video.addEventListener('error', e => { | |
console.log('video play error', e, video.error); | |
}, true); | |
video.controls = false; | |
video.className = 'grid-video'; | |
video.autoplay = false; | |
video.muted = true; | |
video.loop = true; | |
video.style.maxWidth = '100vw'; | |
video.style.maxHeight = '99.7vh'; | |
video.style.width = '100%'; | |
video.style.objectFit = 'cover'; | |
video.src = videoURL; | |
video.onloadedmetadata = function(e) { | |
video.play(); | |
} | |
return video; | |
}; | |
const streamToBlobUrl = stream => { | |
return window.URL.createObjectURL(stream); | |
}; | |
const appendToBody = el => { | |
document.body.appendChild(el); | |
return el; | |
} | |
requestRecord() | |
.then(streamToBlobUrl) | |
.then(createVideo) | |
.then(appendToBody) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment