make Discord's auto gain control toggle actually work
This commit is contained in:
9
src/renderer/common.ts
Normal file
9
src/renderer/common.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
||||
* Copyright (c) 2025 Vendicated and Vesktop contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { findStoreLazy } from "@vencord/types/webpack";
|
||||
|
||||
export const MediaEngineStore = findStoreLazy("MediaEngineStore");
|
||||
@@ -7,7 +7,7 @@
|
||||
import "./screenSharePicker.css";
|
||||
|
||||
import { closeModal, Logger, Modals, ModalSize, openModal, useAwaiter } from "@vencord/types/utils";
|
||||
import { findStoreLazy, onceReady } from "@vencord/types/webpack";
|
||||
import { onceReady } from "@vencord/types/webpack";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
} from "@vencord/types/webpack/common";
|
||||
import { Node } from "@vencord/venmic";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { MediaEngineStore } from "renderer/common";
|
||||
import { addPatch } from "renderer/patches/shared";
|
||||
import { State, useSettings, useVesktopState } from "renderer/settings";
|
||||
import { classNameFactory, isLinux, isWindows } from "renderer/utils";
|
||||
@@ -30,8 +31,6 @@ const StreamFps = ["15", "30", "60"] as const;
|
||||
|
||||
const cl = classNameFactory("vcd-screen-picker-");
|
||||
|
||||
const MediaEngineStore = findStoreLazy("MediaEngineStore");
|
||||
|
||||
export type StreamResolution = (typeof StreamResolutions)[number];
|
||||
export type StreamFps = (typeof StreamFps)[number];
|
||||
|
||||
|
||||
51
src/renderer/patches/fixAutoGainToggle.ts
Normal file
51
src/renderer/patches/fixAutoGainToggle.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
||||
* Copyright (c) 2025 Vendicated and Vesktop contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { Logger } from "@vencord/types/utils";
|
||||
import { MediaEngineStore } from "renderer/common";
|
||||
|
||||
const logger = new Logger("FixAutoGain");
|
||||
|
||||
function fixTrackConstraints(constraint: MediaTrackConstraints) {
|
||||
const target = constraint.advanced?.find(opt => Object.hasOwn(opt, "autoGainControl")) ?? constraint;
|
||||
|
||||
target.autoGainControl = MediaEngineStore.getAutomaticGainControl();
|
||||
}
|
||||
|
||||
function fixStreamConstraints(constraints: MediaStreamConstraints | undefined) {
|
||||
if (!constraints?.audio) return;
|
||||
|
||||
if (typeof constraints.audio !== "object") {
|
||||
constraints.audio = {};
|
||||
}
|
||||
|
||||
fixTrackConstraints(constraints.audio);
|
||||
}
|
||||
|
||||
const originalGetUserMedia = navigator.mediaDevices.getUserMedia;
|
||||
navigator.mediaDevices.getUserMedia = function (constraints) {
|
||||
try {
|
||||
fixStreamConstraints(constraints);
|
||||
logger.debug("Fixed getUserMedia constraints", constraints);
|
||||
} catch (e) {
|
||||
logger.error("Failed to fix getUserMedia constraints", e);
|
||||
}
|
||||
|
||||
return originalGetUserMedia.call(this, constraints);
|
||||
};
|
||||
|
||||
const originalApplyConstraints = MediaStreamTrack.prototype.applyConstraints;
|
||||
MediaStreamTrack.prototype.applyConstraints = function (constraints) {
|
||||
if (constraints) {
|
||||
try {
|
||||
fixTrackConstraints(constraints);
|
||||
logger.debug("Fixed applyConstraints constraints", constraints);
|
||||
} catch (e) {
|
||||
logger.error("Failed to fix applyConstraints constraints", e);
|
||||
}
|
||||
}
|
||||
return originalApplyConstraints.call(this, constraints);
|
||||
};
|
||||
@@ -16,3 +16,4 @@ import "./windowsTitleBar";
|
||||
import "./streamerMode";
|
||||
import "./windowMethods";
|
||||
import "./hideDownloadAppsButton";
|
||||
import "./fixAutoGainToggle";
|
||||
|
||||
Reference in New Issue
Block a user