ScreenRecord.js
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
(function() { | |
// Download locally | |
function download(blob) { | |
var url = window.URL.createObjectURL(blob); | |
var a = document.createElement('a'); | |
a.style.display = 'none'; | |
a.href = url; | |
a.download = 'test.webm'; | |
document.body.appendChild(a); | |
a.click(); | |
setTimeout(function() { | |
document.body.removeChild(a); | |
window.URL.revokeObjectURL(url); | |
}, 100); | |
} | |
const successCallback = (stream) => { | |
// Set up the recorder | |
let blobs = []; | |
let recorder = new MediaRecorder(stream, {mimeType: 'video/webm; codecs=vp9'}); | |
recorder.ondataavailable = e => { if (e.data && e.data.size > 0) blobs.push(e.data)}; | |
recorder.onstop = (e) => download(new Blob(blobs, {type: 'video/webm'})); | |
// Record for 10 seconds. | |
setTimeout(()=> recorder.stop(), 10000); | |
// Start recording. | |
recorder.start(10); // collect 10ms chunks of data | |
}; | |
const errorCallback = () => { | |
// We don't have access to the API | |
}; | |
navigator.getUserMedia({ | |
audio: false, | |
video: {'mandatory': {'chromeMediaSource':'screen'}} | |
}, successCallback, errorCallback); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment