WOAH SCREENAUDIO WORKS
This commit is contained in:
parent
865531868d
commit
2e21a54bae
4 changed files with 41 additions and 44 deletions
|
@ -4,7 +4,6 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getAudioFromVirtmic } from "./screenShareAudio";
|
|
||||||
import { desktopCapturer, session, Streams } from "electron";
|
import { desktopCapturer, session, Streams } from "electron";
|
||||||
import type { StreamPick } from "renderer/components/ScreenSharePicker";
|
import type { StreamPick } from "renderer/components/ScreenSharePicker";
|
||||||
import { IpcEvents } from "shared/IpcEvents";
|
import { IpcEvents } from "shared/IpcEvents";
|
||||||
|
@ -30,8 +29,7 @@ export function registerScreenShareHandler() {
|
||||||
width: 176,
|
width: 176,
|
||||||
height: 99
|
height: 99
|
||||||
}
|
}
|
||||||
}).catch(() => null);
|
});
|
||||||
if (sources === null) return callback({});
|
|
||||||
|
|
||||||
const isWayland =
|
const isWayland =
|
||||||
process.platform === "linux" &&
|
process.platform === "linux" &&
|
||||||
|
@ -45,7 +43,6 @@ export function registerScreenShareHandler() {
|
||||||
|
|
||||||
if (isWayland) {
|
if (isWayland) {
|
||||||
const video = data[0];
|
const video = data[0];
|
||||||
getAudioFromVirtmic();
|
|
||||||
callback(video ? { video } : {});
|
callback(video ? { video } : {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { createVirtmic } from "./createVirtmic";
|
|
||||||
export function getAudioFromVirtmic() {
|
|
||||||
const getAudioDevice = async (deviceName: string|undefined) => {
|
|
||||||
await new Promise(r => setTimeout(r, 1000));
|
|
||||||
let devices = await navigator.mediaDevices.enumerateDevices();
|
|
||||||
let audioDevice = devices.find(({
|
|
||||||
label
|
|
||||||
}) => label === deviceName);
|
|
||||||
|
|
||||||
return audioDevice;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDisplayMedia = async () => {
|
|
||||||
var id: string|undefined;
|
|
||||||
try {
|
|
||||||
let myDiscordAudioSink = await getAudioDevice('virtmic');
|
|
||||||
id = myDiscordAudioSink?.deviceId;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
id = 'default';
|
|
||||||
}
|
|
||||||
|
|
||||||
const constraints = {
|
|
||||||
deviceId: {
|
|
||||||
exact: id
|
|
||||||
},
|
|
||||||
autoGainControl: false,
|
|
||||||
echoCancellation: false,
|
|
||||||
noiseSuppression: false,
|
|
||||||
channelCount: 2
|
|
||||||
};
|
|
||||||
|
|
||||||
await navigator.mediaDevices.getUserMedia({
|
|
||||||
audio: true
|
|
||||||
}).then((MediaStream) => {
|
|
||||||
const audioTrack = MediaStream.getAudioTracks()[0];
|
|
||||||
let captureSystemAudioStream = audioTrack.applyConstraints(constraints);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -8,3 +8,4 @@
|
||||||
import "./spellCheck";
|
import "./spellCheck";
|
||||||
import "./platformClass";
|
import "./platformClass";
|
||||||
import "./windowsTitleBar";
|
import "./windowsTitleBar";
|
||||||
|
import "./screenShareAudio";
|
39
src/renderer/patches/screenShareAudio.ts
Normal file
39
src/renderer/patches/screenShareAudio.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
const original = navigator.mediaDevices.getDisplayMedia;
|
||||||
|
async function getVirtmic() {
|
||||||
|
const getAudioDevice = async (deviceName: string|undefined) => {;
|
||||||
|
let devices = await navigator.mediaDevices.enumerateDevices();
|
||||||
|
let audioDevice = devices.find(({
|
||||||
|
label
|
||||||
|
}) => label === deviceName);
|
||||||
|
console.log(audioDevice);
|
||||||
|
return audioDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
var id: string|undefined;
|
||||||
|
try {
|
||||||
|
let myDiscordAudioSink = await getAudioDevice('virtmic');
|
||||||
|
id = myDiscordAudioSink?.deviceId;
|
||||||
|
console.log(id, "connected");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
id = 'default';
|
||||||
|
console.log("virtmic failed to connect");
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
navigator.mediaDevices.getDisplayMedia = async function() {
|
||||||
|
const id = await getVirtmic();
|
||||||
|
const stream = await original.apply(this);
|
||||||
|
|
||||||
|
const audio = await navigator.mediaDevices.getUserMedia({
|
||||||
|
audio: {
|
||||||
|
deviceId: {
|
||||||
|
exact: id
|
||||||
|
},
|
||||||
|
autoGainControl: false,
|
||||||
|
echoCancellation: false,
|
||||||
|
noiseSuppression: false
|
||||||
|
} });
|
||||||
|
audio.getAudioTracks().forEach(t => stream.addTrack(t));
|
||||||
|
return stream;
|
||||||
|
}
|
Reference in a new issue