diff --git a/src/preload.js b/src/preload.js
index 6e0d38e..3978fac 100644
--- a/src/preload.js
+++ b/src/preload.js
@@ -19,172 +19,7 @@ const { ipcRenderer, desktopCapturer } = require('electron');
// expose ipcRenderer to the renderer process
window.ipcRenderer = ipcRenderer;
-// This is a fix for screen-sharing in Electron
-window.navigator.mediaDevices.getDisplayMedia = () => {
- return new Promise(async (resolve, reject) => {
- try {
- // Get screen-sharing sources
- const sources = await desktopCapturer.getSources({
- types: ["screen", "window"],
- });
- const screens = sources.filter((source) => {
- return source.id.startsWith("screen");
- });
- const windows = sources.filter((source) => {
- return source.id.startsWith("window");
- });
-
- const streamSelector = document.createElement("div");
- streamSelector.classList = "stream-selector";
- streamSelector.innerHTML = `
-
Screens
-
- Windows
-
-
-
- `;
- document.body.appendChild(streamSelector);
-
- document.querySelectorAll(".desktop-capturer-selection-button").forEach((button) => {
- button.addEventListener("click", async (ev) => {
- ev.stopPropagation();
-
- try {
- const id = button.getAttribute("data-id");
- const source = sources.find((source) => source.id === id);
- if (!source) {
- streamSelector.remove();
- reject(new Error(`Source with id ${id} does not exist`));
- }
-
- const stream = await window.navigator.mediaDevices.getUserMedia({
- audio: false,
- video: {
- mandatory: {
- chromeMediaSource: "desktop",
- chromeMediaSourceId: source.id,
- },
- },
- });
-
- streamSelector.remove();
- resolve(stream);
- } catch (err) {
- streamSelector.remove();
- reject(err);
- }
- });
- });
-
- const background = document.querySelector(".stream-selector");
- background.addEventListener("click", async (ev) => {
- streamSelector.remove();
- reject(new Error("No source selected"));
- });
- } catch (err) {
- reject(err);
- }
- });
-};
+// expose desktopCapturer to the render process to make screen-sharing work
+process.once('loaded', () => {
+ global.desktopCapturer = desktopCapturer;
+});