I'm trying to implement electron recording method into my electron + anuglarJS desktop app.
I'm using angularJS so I use services/controllers/views across to maintain application. In one view (html file) I have button which should start recording screen from function in controller. This function is named startRecord.
Full code of controller is:
(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 go inside loop and if statemant
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
}
}
});
};
}
})();
I execute this function on button click in view. After button click nothing really happen. It doesn't console.log this string 'success ?' or 'error ?' from success and error callbacks. However it console.log string 'started' so it is inside loop.
I don't even know if it's actually recording something. There is no errors in console. I think that recording starts but never ends and that is why I don't have console.log from success or errors callback.
Electron documentation is very weak, that's why I'm confused very much about it. I would love to know:
- How to detect that recording actually started?
- What is methodology for stoping recording screen? I couldn't find this information in electron docs which I linked at the top of question.
- How to save or/and upload recorded movie into some storage (may be amazon S3 or some build in option), I see this
document.querySelector('video').src = URL.createObjectURL(stream)
in handle stream, in docs, maybe it's uploading to some storage like I want, is it?
Maybe you guys know some other source of information about this recording? I need more info to use it.