fix; wayland audio share

This commit is contained in:
smartfrigde 2024-04-28 16:48:50 +02:00
parent e1e472bde3
commit 4c1aeef220
9 changed files with 7 additions and 121 deletions

View file

@ -45,8 +45,6 @@
"settings-channel-desc4": "public test build. Receives features earlier than stable but is a bit older than Canary.",
"settings-invitewebsocket": "Rich Presence (Experimental)",
"settings-invitewebsocket-desc": "Uses <a target=\"_blank\" href=\"https://github.com/OpenAsar/arrpc\">arRPC</a> to support Discord RPC (Rich Presence) with local programs on your machine. Work in progress.",
"settings-altPaste": "Alternative Paste",
"settings-altPaste-desc": "If you're on Gnome on Linux or just simply can't paste images copied from other messages, then this is\n for you. This enables alternative module for pasting images. Only enable this when you're experiencing\n issues.",
"settings-mod": "Client mod",
"settings-mod-desc1": "Client mods are programs that allow you customize your Discord experience. They can change appearance of\n the client, modify behaviours or add new features!",
"settings-mod-vencord": "lightweight, and easy to use client mod. Features a built-in store for plugins.",

View file

@ -12,7 +12,7 @@
"start": "npm run build && electron ./ts-out/main.js",
"startThemeManager": "npm run build && electron ./ts-out/main.js themes",
"startKeybindManager": "npm run build && electron ./ts-out/main.js keybinds",
"startWayland": "npm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations",
"startWayland": "npm run build && electron ./ts-out/main.js --ozone-platform-hint=auto --enable-features=WebRTCPipeWireCapturer,WaylandWindowDecorations --disable-gpu",
"package": "npm run build && electron-builder",
"packageQuick": "npm run build && electron-builder --dir",
"format": "prettier --write src *.json",

View file

@ -13,9 +13,6 @@
.acMobileMode {
height: 11em !important;
}
.acAltPaste {
height: 11em !important;
}
.acChannel {
height: 21em !important;
}

View file

@ -1,65 +0,0 @@
navigator.mediaDevices.getDisplayMedia = getDisplayMedia;
// ==UserScript==
// @name Screenshare with Audio
// @namespace https://github.com/edisionnano
// @version 0.4
// @updateURL https://openuserjs.org/meta/samantas5855/Screenshare_with_Audio.meta.js
// @description Screenshare with Audio on Discord
// @author Guest271314 and Samantas5855
// @match https://*.discord.com/*
// @icon https://www.google.com/s2/favicons?domain=discord.com
// @grant none
// @license MIT
// ==/UserScript==
/* jshint esversion: 8 */
navigator.mediaDevices.chromiumGetDisplayMedia = navigator.mediaDevices.getDisplayMedia;
const getAudioDevice = async (nameOfAudioDevice) => {
await navigator.mediaDevices.getUserMedia({
audio: true
});
await new Promise((r) => setTimeout(r, 1000));
let devices = await navigator.mediaDevices.enumerateDevices();
let audioDevice = devices.find(({label}) => label === nameOfAudioDevice);
return audioDevice;
};
const getDisplayMedia = async () => {
var id;
try {
let myDiscordAudioSink = await getAudioDevice("screenshareAudio");
id = myDiscordAudioSink.deviceId;
} catch (error) {
id = "default";
}
let captureSystemAudioStream = await navigator.mediaDevices.getUserMedia({
audio: {
// We add our audio constraints here, to get a list of supported constraints use navigator.mediaDevices.getSupportedConstraints();
// We must capture a microphone, we use default since its the only deviceId that is the same for every Chromium user
deviceId: {
exact: id
},
// We want auto gain control, noise cancellation and noise suppression disabled so that our stream won't sound bad
autoGainControl: false,
echoCancellation: false,
noiseSuppression: false
// By default Chromium sets channel count for audio devices to 1, we want it to be stereo in case we find a way for Discord to accept stereo screenshare too
//channelCount: 2,
// You can set more audio constraints here, bellow are some examples
//latency: 0,
//sampleRate: 48000,
//sampleSize: 16,
//volume: 1.0
}
});
let [track] = captureSystemAudioStream.getAudioTracks();
const gdm = await navigator.mediaDevices.chromiumGetDisplayMedia({
video: true,
audio: true
});
gdm.addTrack(track);
return gdm;
};
navigator.mediaDevices.getDisplayMedia = getDisplayMedia;

View file

@ -12,33 +12,6 @@ function paste(contents: any): void {
contents.paste();
}
export async function setMenu(): Promise<void> {
if ((await getConfig("alternativePaste")) == true) {
mainWindow.on("focus", function () {
console.log("[Window state manager] Focus");
globalShortcut.register("CmdOrCtrl+V", function () {
if (mainWindow.isFocused()) {
paste(mainWindow.webContents);
}
});
});
mainWindow.on("show", function () {
console.log("[Window state manager] Show");
mainWindow.focus();
globalShortcut.register("CmdOrCtrl+V", function () {
if (mainWindow.isFocused()) {
paste(mainWindow.webContents);
}
});
});
mainWindow.on("blur", function () {
console.log("[Window state manager] Defocus");
globalShortcut.unregister("CmdOrCtrl+V");
});
mainWindow.on("hide", function () {
console.log("[Window state manager] Hide");
globalShortcut.unregister("CmdOrCtrl+V");
});
}
let template: Electron.MenuItemConstructorOptions[] = [
{
label: "ArmCord",

View file

@ -6,13 +6,6 @@ let capturerWindow: BrowserWindow;
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();
// }
// }
const sources = await desktopCapturer.getSources({
types: ["screen", "window"]
});
@ -20,7 +13,7 @@ function registerCustomHandler(): void {
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}});
callback({video: sources[0], audio: "loopbackWithMute"});
} else {
capturerWindow = new BrowserWindow({
width: 800,
@ -40,8 +33,9 @@ function registerCustomHandler(): void {
//console.log(sources[id]);
//console.log(id);
capturerWindow.close();
let result = {id, name, width: 9999, height: 9999};
if (process.platform === "linux") {
let result = {id, name};
if (process.platform === "linux" || process.platform === "win32") {
console.log("audio screenshare");
callback({video: result, audio: "loopbackWithMute"});
} else {
callback({video: result});

View file

@ -100,14 +100,6 @@
</div>
<br />
<div class="switch acAltPaste">
<label class="header" data-string="settings-altPaste"></label>
<input id="alternativePaste" class="tgl tgl-light left" data-setting="alternativePaste" type="checkbox" />
<label class="tgl-btn left" for="alternativePaste"></label>
<p class="description" data-string="settings-altPaste-desc"></p>
</div>
<br />
<div class="switch acAutogain">
<label class="header" data-string="settings-disableAutogain"></label>
<input id="disableAutogain" class="tgl tgl-light left" data-setting="disableAutogain" type="checkbox" />

View file

@ -143,7 +143,6 @@
useLegacyCapturer: false,
tray: /true/i.test(document.getElementById("tray").value),
startMinimized: false,
alternativePaste: false,
performanceMode: "none",
trayIcon: "default",
inviteWebsocket: true,

View file

@ -58,7 +58,6 @@ export function setup(): void {
armcordCSP: true,
minimizeToTray: true,
keybinds: [],
alternativePaste: false,
multiInstance: false,
mods: "none",
spellcheck: true,
@ -139,11 +138,11 @@ export async function injectElectronFlags(): Promise<void> {
switch (await getConfig("performanceMode")) {
case "performance":
console.log("Performance mode enabled");
app.commandLine.appendSwitch(presets.performance);
app.commandLine.appendArgument(presets.performance);
break;
case "battery":
console.log("Battery mode enabled");
app.commandLine.appendSwitch(presets.battery);
app.commandLine.appendArgument(presets.battery);
break;
default:
console.log("No performance modes set");
@ -270,7 +269,6 @@ export interface Settings {
channel: string;
armcordCSP: boolean;
minimizeToTray: boolean;
alternativePaste: boolean;
multiInstance: boolean;
spellcheck: boolean;
mods: string;