Compare commits
1 Commits
94b27f5b6a
...
autogain
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd2aca55c7 |
@@ -1,12 +1,14 @@
|
|||||||
navigator.mediaDevices.chromiumGetDisplayMedia =
|
navigator.mediaDevices.chromiumGetDisplayMedia =
|
||||||
navigator.mediaDevices.getDisplayMedia;
|
navigator.mediaDevices.getDisplayMedia;
|
||||||
|
navigator.mediaDevices.chromiumGetUserMedia =
|
||||||
|
navigator.mediaDevices.getUserMedia;
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAudioDevice = async (nameOfAudioDevice) => {
|
const getAudioDevice = async (nameOfAudioDevice) => {
|
||||||
await navigator.mediaDevices.getUserMedia({
|
await navigator.mediaDevices.chromiumGetUserMedia({
|
||||||
audio: true,
|
audio: true,
|
||||||
});
|
});
|
||||||
let audioDevice;
|
let audioDevice;
|
||||||
@@ -23,6 +25,16 @@ const getAudioDevice = async (nameOfAudioDevice) => {
|
|||||||
return audioDevice;
|
return audioDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setGetUserMedia() {
|
||||||
|
const getUserMedia = async (constraints) => {
|
||||||
|
return await navigator.mediaDevices.chromiumGetUserMedia({
|
||||||
|
video: constraints?.video || false,
|
||||||
|
audio: { ...constraints?.audio, autoGainControl },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
navigator.mediaDevices.getUserMedia = getUserMedia;
|
||||||
|
}
|
||||||
|
|
||||||
function setGetDisplayMedia(video = true, overrideArgs = undefined) {
|
function setGetDisplayMedia(video = true, overrideArgs = undefined) {
|
||||||
const getDisplayMedia = async (...args) => {
|
const getDisplayMedia = async (...args) => {
|
||||||
var id;
|
var id;
|
||||||
@@ -34,26 +46,27 @@ function setGetDisplayMedia(video = true, overrideArgs = undefined) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
id = "default";
|
id = "default";
|
||||||
}
|
}
|
||||||
let captureSystemAudioStream = await navigator.mediaDevices.getUserMedia({
|
let captureSystemAudioStream =
|
||||||
audio: {
|
await navigator.mediaDevices.chromiumGetUserMedia({
|
||||||
// We add our audio constraints here, to get a list of supported constraints use navigator.mediaDevices.getSupportedConstraints();
|
audio: {
|
||||||
// We must capture a microphone, we use default since its the only deviceId that is the same for every Chromium user
|
// We add our audio constraints here, to get a list of supported constraints use navigator.mediaDevices.getSupportedConstraints();
|
||||||
deviceId: {
|
// We must capture a microphone, we use default since its the only deviceId that is the same for every Chromium user
|
||||||
exact: id,
|
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
|
||||||
},
|
},
|
||||||
// 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();
|
let [track] = captureSystemAudioStream.getAudioTracks();
|
||||||
const gdm = await navigator.mediaDevices.chromiumGetDisplayMedia(
|
const gdm = await navigator.mediaDevices.chromiumGetDisplayMedia(
|
||||||
...(overrideArgs
|
...(overrideArgs
|
||||||
@@ -68,6 +81,7 @@ function setGetDisplayMedia(video = true, overrideArgs = undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setGetDisplayMedia();
|
setGetDisplayMedia();
|
||||||
|
setGetUserMedia();
|
||||||
|
|
||||||
let userscript;
|
let userscript;
|
||||||
let muteBtn;
|
let muteBtn;
|
||||||
@@ -76,6 +90,7 @@ let streamStartBtn;
|
|||||||
let streamStartBtnInitialDisplay;
|
let streamStartBtnInitialDisplay;
|
||||||
let streamStartBtnClone;
|
let streamStartBtnClone;
|
||||||
let resolutionString;
|
let resolutionString;
|
||||||
|
let autoGainControl = true;
|
||||||
const clonedElements = [];
|
const clonedElements = [];
|
||||||
const hiddenElements = [];
|
const hiddenElements = [];
|
||||||
let wasStreamActive = false;
|
let wasStreamActive = false;
|
||||||
@@ -159,6 +174,10 @@ function main() {
|
|||||||
streamStartBtnClone.remove();
|
streamStartBtnClone.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
userscript.getPref("disableAutomaticGain", false).then((disabled) => {
|
||||||
|
autoGainControl = !disabled;
|
||||||
|
});
|
||||||
|
|
||||||
function updateUserstyles() {
|
function updateUserstyles() {
|
||||||
userscript.log("Loading userstyles...");
|
userscript.log("Loading userstyles...");
|
||||||
userscript.loadingMessage = "Loading userstyles...";
|
userscript.loadingMessage = "Loading userstyles...";
|
||||||
@@ -368,5 +387,29 @@ function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const el of document.getElementsByClassName("sensitivity-3A7Gs9")) {
|
||||||
|
if (
|
||||||
|
el.getElementsByTagName("div").length > 0 &&
|
||||||
|
!document.getElementById("discord-screenaudio-gaintoggle")
|
||||||
|
) {
|
||||||
|
const toggle = createSwitch(
|
||||||
|
"Disable automatic gain",
|
||||||
|
await userscript.getPref("disableAutomaticGain", false),
|
||||||
|
async (disabled) => {
|
||||||
|
await userscript.setPref("disableAutomaticGain", disabled);
|
||||||
|
autoGainControl = !disabled;
|
||||||
|
setGetUserMedia();
|
||||||
|
if (disabled)
|
||||||
|
userscript.showInformation(
|
||||||
|
"discord-screenaudio",
|
||||||
|
"If you are currently in a call, this setting may only take effect after you rejoin the call or restart discord-screenaudio."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
toggle.id = "discord-screenaudio-gaintoggle";
|
||||||
|
el.getElementsByTagName("div")[0].appendChild(toggle);
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QShortcut>
|
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -32,8 +31,6 @@ MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
|
|||||||
setCentralWidget(m_centralWidget);
|
setCentralWidget(m_centralWidget);
|
||||||
setupTrayIcon();
|
setupTrayIcon();
|
||||||
setMinimumSize(800, 300);
|
setMinimumSize(800, 300);
|
||||||
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this),
|
|
||||||
&QShortcut::activated, this, &MainWindow::toggleOrCloseWindow);
|
|
||||||
if (m_settings->contains("geometry")) {
|
if (m_settings->contains("geometry")) {
|
||||||
restoreGeometry(m_settings->value("geometry").toByteArray());
|
restoreGeometry(m_settings->value("geometry").toByteArray());
|
||||||
} else {
|
} else {
|
||||||
@@ -82,7 +79,12 @@ void MainWindow::setupTrayIcon() {
|
|||||||
|
|
||||||
connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) {
|
connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) {
|
||||||
if (reason == QSystemTrayIcon::Trigger) {
|
if (reason == QSystemTrayIcon::Trigger) {
|
||||||
toggleOrCloseWindow();
|
if (isVisible()) {
|
||||||
|
hide();
|
||||||
|
} else {
|
||||||
|
show();
|
||||||
|
activateWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -129,15 +131,3 @@ MainWindow *MainWindow::instance() { return m_instance; }
|
|||||||
CentralWidget *MainWindow::centralWidget() {
|
CentralWidget *MainWindow::centralWidget() {
|
||||||
return instance()->m_centralWidget;
|
return instance()->m_centralWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
void MainWindow::toggleOrCloseWindow() {
|
|
||||||
if (isVisible()) {
|
|
||||||
if (m_trayIcon == nullptr)
|
|
||||||
QApplication::quit();
|
|
||||||
else
|
|
||||||
hide();
|
|
||||||
} else {
|
|
||||||
show();
|
|
||||||
activateWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -36,5 +36,4 @@ private:
|
|||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setTrayIcon(bool enabled);
|
void setTrayIcon(bool enabled);
|
||||||
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
|
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
|
||||||
void toggleOrCloseWindow();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -182,3 +182,7 @@ void UserScript::showThemeDialog() {
|
|||||||
void UserScript::installUserStyles(QString url) {
|
void UserScript::installUserStyles(QString url) {
|
||||||
emit shouldInstallUserStyles(url);
|
emit shouldInstallUserStyles(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UserScript::showInformation(QString title, QString message) {
|
||||||
|
QMessageBox::information(MainWindow::instance(), title, message);
|
||||||
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public Q_SLOTS:
|
|||||||
void showShortcutsDialog();
|
void showShortcutsDialog();
|
||||||
void showHelpMenu();
|
void showHelpMenu();
|
||||||
void showStreamDialog();
|
void showStreamDialog();
|
||||||
|
void showInformation(QString title, QString message);
|
||||||
void stopVirtmic();
|
void stopVirtmic();
|
||||||
void startVirtmic(QString target);
|
void startVirtmic(QString target);
|
||||||
void showThemeDialog();
|
void showThemeDialog();
|
||||||
|
|||||||
Reference in New Issue
Block a user