Can Electron capture a window as a video stream?


#1

I want to create an app to capture one window as a video source, so far I am using desktopCapturer get the sources info and using getUserMedia to put it in a . but the video is like a still picture not show any changes on the window, just a mouse moving around. Could any one help me with this problem. thank you so much.

here is my code:

getAllScreenInfo: () => {
let st = new Date();
return new Promise((resolve, reject) => {
desktopCapturer.getSources({types: [‘window’, ‘screen’]}, (error, sources) => {
console.info('screen source get end at ', (new Date() - st) / 1000);
if (error) {
reject(error);
} else {
resolve(sources);
}
})
})
},

getScreen: (id, obj, rf) => {
return new Promise((resolve, reject) => {
let w = 1920;
let h = 1080;

  navigator.webkitGetUserMedia({
        audio: false,
        video: {
          mandatory: {
            chromeMediaSource: 'desktop',
            chromeMediaSourceId: id,
            minWidth: w,
            maxWidth: w,
            minHeight: h,
            maxHeight: h
          }
        }
      }, (stream) => {
        obj.src = URL.createObjectURL(stream);
        resolve();
      }, (e) => {
        reject(e);
      });
});

},

VideoSources.getAllScreenInfo().then(sources => {
console.info(‘all sources’, sources);
sources = sources.filter(source => {
return (source.name === ‘Screen 1’ || source.name.indexOf(‘Word’) >= 0);
})
this.setState({sources: sources});
});


#2

When posting code, please make sure that all of it is wrapped in code tags so that it’s easily readable.


#3

Sorry for the mess, new here and cannot find where to edit my. Should I deleted this one and post a new one?


#4

Is there not a little pencil at the bottom of the post? If not, you can make a new reply with the code properly indented.

Also, I don’t have any basis to help with this. I’m just making sure that your question is readable.


#5

Can’t find pencil, I got answer from here: https://github.com/electron/electron/issues/8278
Hope will help someone who has the same issue.