feat: add audio share confirmation

This commit is contained in:
smartfrigde 2024-04-29 11:19:22 +02:00
parent 22412c3e46
commit 6a2f05b0d1

View file

@ -1,8 +1,27 @@
import {BrowserWindow, desktopCapturer, ipcMain, session} from "electron"; import {BrowserWindow, MessageBoxOptions, desktopCapturer, dialog, ipcMain, session} from "electron";
import path from "path"; import path from "path";
import {iconPath} from "../main"; import {iconPath} from "../main";
let capturerWindow: BrowserWindow; let capturerWindow: BrowserWindow;
function showAudioDialog(): boolean {
const options: MessageBoxOptions = {
type: "question",
buttons: ["Yes", "No"],
defaultId: 1,
title: "Screenshare audio",
message: `Would you like to screenshare audio?`,
detail: "Selecting yes will make viewers of your stream hear your entire system audio."
};
dialog.showMessageBox(capturerWindow, options).then(({response}) => {
if (response == 0) {
return true;
} else {
return false;
}
});
return true;
}
function registerCustomHandler(): void { function registerCustomHandler(): void {
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => { session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
console.log(request); console.log(request);
@ -12,8 +31,9 @@ function registerCustomHandler(): void {
console.log(sources); console.log(sources);
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") { if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
console.log("WebRTC Capturer detected, skipping window creation."); //assume webrtc capturer is used console.log("WebRTC Capturer detected, skipping window creation."); //assume webrtc capturer is used
console.log({video: {id: sources[0].id, name: sources[0].name}}); var options: Electron.Streams = {video: sources[0]};
callback({video: sources[0], audio: "loopbackWithMute"}); if (showAudioDialog() == true) options = {video: sources[0], audio: "loopbackWithMute"};
callback(options);
} else { } else {
capturerWindow = new BrowserWindow({ capturerWindow = new BrowserWindow({
width: 800, width: 800,
@ -35,8 +55,9 @@ function registerCustomHandler(): void {
capturerWindow.close(); capturerWindow.close();
let result = {id, name}; let result = {id, name};
if (process.platform === "linux" || process.platform === "win32") { if (process.platform === "linux" || process.platform === "win32") {
console.log("audio screenshare"); var options: Electron.Streams = {video: sources[0]};
callback({video: result, audio: "loopbackWithMute"}); if (showAudioDialog() == true) options = {video: sources[0], audio: "loopbackWithMute"};
callback(options);
} else { } else {
callback({video: result}); callback({video: result});
} }