fix wayland screenshare

This commit is contained in:
smartfrigde 2023-08-05 14:07:42 +02:00
parent ce1170178e
commit 8e43e5abcc
4 changed files with 44 additions and 88 deletions

View file

@ -36,7 +36,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.2", "@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2", "@typescript-eslint/parser": "^5.59.2",
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"electron": "^25.3.2", "electron": "26.0.0-beta.11",
"electron-builder": "^24.6.3", "electron-builder": "^24.6.3",
"eslint": "^8.40.0", "eslint": "^8.40.0",
"eslint-config-dmitmel": "github:dmitmel/eslint-config-dmitmel", "eslint-config-dmitmel": "github:dmitmel/eslint-config-dmitmel",

View file

@ -41,8 +41,8 @@ devDependencies:
specifier: ^2.4.1 specifier: ^2.4.1
version: 2.4.1 version: 2.4.1
electron: electron:
specifier: ^25.3.2 specifier: 26.0.0-beta.11
version: 25.3.2 version: 26.0.0-beta.11
electron-builder: electron-builder:
specifier: ^24.6.3 specifier: ^24.6.3
version: 24.6.3 version: 24.6.3
@ -1024,8 +1024,8 @@ packages:
- supports-color - supports-color
dev: true dev: true
/electron@25.3.2: /electron@26.0.0-beta.11:
resolution: {integrity: sha512-xiktJvXraaE/ARf2OVHFyTze1TksSbsbJgOaBtdIiBvUduez6ipATEPIec8Msz1n6eQ+xqYb6YF8tDuIZtJSPw==} resolution: {integrity: sha512-QejgSimxMxl4C3oOVGqKPn9T50PHt//i9JZPN3mOKviyawpfA3yI8SbtDhXW0d+6f+GGHIg0Eo7deppki3be/Q==}
engines: {node: '>= 12.20.55'} engines: {node: '>= 12.20.55'}
hasBin: true hasBin: true
requiresBuild: true requiresBuild: true
@ -1453,7 +1453,7 @@ packages:
es6-error: 4.1.1 es6-error: 4.1.1
matcher: 3.0.0 matcher: 3.0.0
roarr: 2.15.4 roarr: 2.15.4
semver: 7.3.8 semver: 7.5.4
serialize-error: 7.0.1 serialize-error: 7.0.1
dev: true dev: true
optional: true optional: true

View file

@ -60,26 +60,11 @@ if (!app.requestSingleInstanceLock()) {
} else { } else {
// Your data now belongs to CCP // Your data now belongs to CCP
crashReporter.start({uploadToServer: false}); crashReporter.start({uploadToServer: false});
/* Using appendSwitch properly causes ArmCord to segfault, // enable webrtc capturer for wayland
So we will leave the responsibility of enabling Wayland
And PipeWire video capture to packagers.
// We use toLowerCase to account for desktops where XDG_SESSION_TYPE might be Wayland and not wayland.
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") { if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
// Just using the native Wayland backend doesn't enable PipeWire capture, we need to enable it explicitly.
app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer"); app.commandLine.appendSwitch("enable-features=WebRTCPipeWireCapturer");
console.log("Wayland detected, using PipeWire for video capture."); console.log("Wayland detected, using PipeWire for video capture.");
// Some people might want to disable the Wayland backend for one reason or another, such as for Wayland-specific bugs.
if (process.env.USE_WAYLAND === "0") {
console.log("Wayland backend disabled.");
} else {
console.log("Using native Wayland, not Xwayland. Disable with USE_WAYLAND=0 if you find issues.");
app.commandLine.appendSwitch("ozone-platform=auto");
// The Wayland spec doesn't require SSDs, so lets enable self-drawn window decorations.
// If SSDs are supported on the compositor, Electron will let the compositor handle the decorations.
app.commandLine.appendSwitch("enable-features=UseOzonePlatform,WaylandWindowDecorations");
} }
}
*/
// work around chrome 66 disabling autoplay by default // work around chrome 66 disabling autoplay by default
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required"); app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");

View file

@ -1,10 +1,27 @@
import {BrowserWindow, MessageBoxOptions, desktopCapturer, ipcMain, session, dialog} from "electron"; import {BrowserWindow, desktopCapturer, ipcMain, session} from "electron";
import path from "path"; import path from "path";
import {iconPath} from "../main"; import {iconPath} from "../main";
import {getSinks, isAudioSupported} from "./audio";
let capturerWindow: BrowserWindow; let capturerWindow: BrowserWindow;
var sources: Electron.DesktopCapturerSource[]; function registerCustomHandler(): void {
function openPickerWindow() { session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
console.log(request);
// if (process.platform == "linux") {
// let isAudio = isAudioSupported();
// if (isAudio) {
// console.log("audio supported");
// getSinks();
// }
// }
const sources = await desktopCapturer.getSources({
types: ["screen", "window"]
});
console.log(sources);
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({video: {id: sources[0].id, name: sources[0].name}});
callback({video: {id: sources[0].id, name: sources[0].name}});
} else {
capturerWindow = new BrowserWindow({ capturerWindow = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
@ -19,54 +36,6 @@ function openPickerWindow() {
preload: path.join(__dirname, "preload.js") preload: path.join(__dirname, "preload.js")
} }
}); });
function waitForElement() {
if (sources == undefined) {
setTimeout(waitForElement, 250);
console.log(sources);
} else {
capturerWindow.loadURL(`file://${__dirname}/picker.html`);
capturerWindow.webContents.send("getSources", sources);
}
}
waitForElement();
}
function registerCustomHandler(): void {
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
console.log(request);
// if (process.platform == "linux") {
// let isAudio = isAudioSupported();
// if (isAudio) {
// console.log("audio supported");
// getSinks();
// }
// }
if (process.platform == "linux") {
const options: MessageBoxOptions = {
type: "question",
buttons: ["My screen", "An app"],
defaultId: 1,
title: "ArmCord Screenshare",
message: `What would you like to screenshare?`
};
dialog.showMessageBox(options).then(async ({response}) => {
if (response == 0) {
sources = await desktopCapturer.getSources({
types: ["screen"]
});
} else {
sources = await desktopCapturer.getSources({
types: ["window"]
});
}
});
} else {
sources = await desktopCapturer.getSources({
types: ["screen", "window"]
});
}
ipcMain.once("selectScreenshareSource", (_event, id, name) => { ipcMain.once("selectScreenshareSource", (_event, id, name) => {
//console.log(sources[id]); //console.log(sources[id]);
//console.log(id); //console.log(id);
@ -78,7 +47,9 @@ function registerCustomHandler(): void {
callback({video: result}); callback({video: result});
} }
}); });
openPickerWindow(); capturerWindow.loadURL(`file://${__dirname}/picker.html`);
capturerWindow.webContents.send("getSources", sources);
}
}); });
} }
registerCustomHandler(); registerCustomHandler();