Skip to content

Commit

Permalink
fix regression breaking venmic (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve authored Apr 21, 2024
1 parent ab9e857 commit 2733727
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
25 changes: 25 additions & 0 deletions src/renderer/patches/hideVenmicInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import { addPatch } from "./shared";

addPatch({
patches: [
{
find: 'setSinkId"in',
replacement: {
// eslint-disable-next-line no-useless-escape
match: /return (\i)\?navigator\.mediaDevices\.enumerateDevices/,
replace: "return $1 ? $self.filteredDevices"
}
}
],

async filteredDevices() {
const original = await navigator.mediaDevices.enumerateDevices();
return original.filter(x => x.label !== "vencord-screen-share");
}
});
1 change: 1 addition & 0 deletions src/renderer/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import "./enableNotificationsByDefault";
import "./platformClass";
import "./hideSwitchDevice";
import "./hideVenmicInput";
import "./screenShareFixes";
import "./spellCheck";
import "./windowsTitleBar";
12 changes: 3 additions & 9 deletions src/renderer/patches/screenShareFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@ import { isLinux } from "renderer/utils";
const logger = new Logger("VesktopStreamFixes");

if (isLinux) {
const originalMedia = navigator.mediaDevices.getDisplayMedia;
const originalDevices = navigator.mediaDevices.enumerateDevices;
const original = navigator.mediaDevices.getDisplayMedia;

async function getVirtmic() {
try {
const devices = await originalDevices();
const devices = await navigator.mediaDevices.enumerateDevices();
const audioDevice = devices.find(({ label }) => label === "vencord-screen-share");
return audioDevice?.deviceId;
} catch (error) {
return null;
}
}

navigator.mediaDevices.enumerateDevices = async function () {
const result = await originalDevices.call(this);
return result.filter(x => x.label !== "vencord-screen-share");
};

navigator.mediaDevices.getDisplayMedia = async function (opts) {
const stream = await originalMedia.call(this, opts);
const stream = await original.call(this, opts);
const id = await getVirtmic();

const frameRate = Number(currentSettings?.fps);
Expand Down

0 comments on commit 2733727

Please sign in to comment.