diff --git a/src/preload.js b/src/preload.js
index 85328a1..6e0d38e 100644
--- a/src/preload.js
+++ b/src/preload.js
@@ -23,6 +23,7 @@ window.ipcRenderer = ipcRenderer;
window.navigator.mediaDevices.getDisplayMedia = () => {
return new Promise(async (resolve, reject) => {
try {
+ // Get screen-sharing sources
const sources = await desktopCapturer.getSources({
types: ["screen", "window"],
});
@@ -32,16 +33,15 @@ window.navigator.mediaDevices.getDisplayMedia = () => {
const windows = sources.filter((source) => {
return source.id.startsWith("window");
});
- console.log(screens);
- console.log(windows);
- const selectionElem = document.createElement("div");
- selectionElem.classList = "desktop-capturer-selection";
- selectionElem.innerHTML = `
+ const streamSelector = document.createElement("div");
+ streamSelector.classList = "stream-selector";
+ streamSelector.innerHTML = `
+
Screens
+ Windows
+
`;
- document.body.appendChild(selectionElem);
+ document.body.appendChild(streamSelector);
document.querySelectorAll(".desktop-capturer-selection-button").forEach((button) => {
- button.addEventListener("click", async () => {
- console.log("Click");
+ button.addEventListener("click", async (ev) => {
+ ev.stopPropagation();
+
try {
const id = button.getAttribute("data-id");
const source = sources.find((source) => source.id === id);
- if (! source) {
- throw new Error(`Source with id ${id} does not exist`);
+ if (!source) {
+ streamSelector.remove();
+ reject(new Error(`Source with id ${id} does not exist`));
}
const stream = await window.navigator.mediaDevices.getUserMedia({
@@ -146,17 +168,22 @@ window.navigator.mediaDevices.getDisplayMedia = () => {
},
},
});
- resolve(stream);
- selectionElem.remove();
+ streamSelector.remove();
+ resolve(stream);
} catch (err) {
- console.error("Error selecting desktop capture source:", 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) {
- console.error("Error displaying desktop capture sources:", err);
reject(err);
}
});