Expose native API call to get desktop screen sources (#1881)

* Expose native API call to get screen sources

* Move eslint line to the bottom
This commit is contained in:
Claudio Costa 2021-11-29 10:18:49 +01:00 committed by GitHub
parent 5056ec7ace
commit 875a0f8bfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@
/* eslint-disable no-magic-numbers */
import {contextBridge, ipcRenderer, webFrame} from 'electron';
import {contextBridge, ipcRenderer, webFrame, desktopCapturer} from 'electron';
// I've filed an issue in electron-log https://github.com/megahertz/electron-log/issues/267
// we'll be able to use it again if there is a workaround for the 'os' import
@ -262,4 +262,18 @@ window.addEventListener('storage', (e) => {
}
});
contextBridge.exposeInMainWorld('desktopCapturer', {
getSources: async (options) => {
const sources = await desktopCapturer.getSources(options);
return sources.map((source) => {
return {
id: source.id,
name: source.name,
thumbnailURL: source.thumbnail.toDataURL(),
};
});
},
});
/* eslint-enable no-magic-numbers */