I've been exploring the implementation of the electron recording method into my electron and angularJS desktop application.
Since I am using angularJS to maintain services, controllers, and views, I have a button in one of my views (HTML file) that is supposed to trigger screen recording from a function inside the controller. This function is called startRecord.
The complete code for the controller is as follows:
(function () {
'use strict';
var { desktopCapturer } = require('electron')
angular
.module('app')
.controller('loggedScreen', Controller);
Controller.$inject = ['$scope', 'recorderService'];
function Controller($scope, recorderService) {
function handleStream (stream) {
console.log('success ? ');
document.querySelector('video').src = URL.createObjectURL(stream)
}
function handleError (e) {
console.log('error ? ');
console.log(e)
}
$scope.startRecord = function () {
desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => {
if (error) throw error;
// record when window title is Electron
// just record electron window
for (let i = 0; i < sources.length; ++i) {
if (sources[i].name === 'Electron') {
// console log to check if it goes inside the loop and the if statement
console.log('started');
navigator.mediaDevices.getUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sources[i].id,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
}, handleStream, handleError)
return
}
}
});
};
}
})();
When I click the button in the view to execute this function, nothing seems to happen. There are no 'success ?' or 'error ?' logs in the console, however, 'started' is logged indicating that it's inside the loop.
I'm unsure if the recording is actually taking place. No errors are appearing in the console. It seems like the recording starts but never ends, which may explain why the success or error callback logs don't show up.
Due to the limited information provided in the Electron documentation, I'm quite confused about how to proceed. Some questions that come to mind are:
- How can I confirm that the recording has actually started?
- What is the process for stopping the screen recording? The electron docs linked above do not mention this.
- Is there a way to save or upload the recorded movie to storage (such as Amazon S3)? The line
in the handle stream function makes me wonder if it's uploading, but I'm uncertain.document.querySelector('video').src = URL.createObjectURL(stream)
If anyone knows of another reliable source of information regarding this recording process, please share it with me. I need more insights to effectively use it.