Skip to content

Instantly share code, notes, and snippets.

@danhanfry
Created October 2, 2017 18:56
Show Gist options
  • Save danhanfry/fab90f328101bb0434218edaef56fdaa to your computer and use it in GitHub Desktop.
Save danhanfry/fab90f328101bb0434218edaef56fdaa to your computer and use it in GitHub Desktop.
I have found a solution. Read here: muaz-khan/RecordRTC#181
Here is a code that starts to record video+audio in Electron:
let recorder;
let blobs = [];
function captureScreenVideoWithAudio() {
navigator.webkitGetUserMedia({
audio: true
}, function(audioStream) {
navigator.webkitGetUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'screen',
minWidth: 1280,
minHeight: 720
}
}
}, handleVideoStream(audioStream), handleUserMediaError);
}, function() {});
}
function handleVideoStream(audioStream) {
return function(videoStream) {
if (audioStream) {
let audioTracks = audioStream.getAudioTracks();
if (audioTracks.length > 0) {
videoStream.addTrack(audioTracks[0]);
}
}
recorder = new MediaRecorder(videoStream);
blobs = [];
recorder.ondataavailable = function(event) {
blobs.push(event.data);
};
recorder.start();
};
}
function handleUserMediaError(e) {
console.error('handleUserMediaError', e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment