Skip to content

Commit

Permalink
Merge pull request #879 from jijojosephk/issue-664
Browse files Browse the repository at this point in the history
  • Loading branch information
jijojosephk authored Jul 3, 2023
2 parents 3245bf2 + 9837c06 commit 1bbf766
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ function initializeModules(config, ipcRenderer) {
require('./tools/zoom').init(config);
require('./tools/shortcuts').init(config);
require('./tools/chromeApi');
if (config.disableAutogain) {
require('./tools/disableAutogain')();
}
require('./tools/settings').init(config, ipcRenderer);
require('./tools/customBackgrounds')(config, ipcRenderer);
}
Expand Down
80 changes: 80 additions & 0 deletions app/browser/tools/disableAutogain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
let disableAutogain = function () {
function setLegacyChromeConstraint(constraint, name, value) {
if (constraint.mandatory && name in constraint.mandatory) {
constraint.mandatory[name] = value;
return;
}
if (constraint.optional) {
const element = constraint.optional.find(opt => name in opt);
if (element) {
element[name] = value;
return;
}
}
// `mandatory` options throw errors for unknown keys, so avoid that by
// setting it under optional.
if (!constraint.optional) {
constraint.optional = [];
}
constraint.optional.push({ [name]: value });
}
function setConstraint(constraint, name, value) {
if (constraint.advanced) {
const element = constraint.advanced.find(opt => name in opt);
if (element) {
element[name] = value;
return;
}
}
constraint[name] = value;
}
function disableAutogain(constraints) {
console.log('Automatically unsetting gain!', constraints);
if (constraints && constraints.audio) {
if (typeof constraints.audio !== 'object') {
constraints.audio = {};
}
if (constraints.audio.optional || constraints.audio.mandatory) {
setLegacyChromeConstraint(constraints.audio, 'googAutoGainControl', false);
setLegacyChromeConstraint(constraints.audio, 'googAutoGainControl2', false);
} else {
setConstraint(constraints.audio, 'autoGainControl', false);
}
}
}

function patchFunction(object, name, createNewFunction) {
if (name in object) {
var original = object[name];
object[name] = createNewFunction(original);
}
}

patchFunction(navigator.mediaDevices, 'getUserMedia', function (original) {
return function getUserMedia(constraints) {
disableAutogain(constraints);
return original.call(this, constraints);
};
});
function patchDeprecatedGetUserMedia(original) {
return function getUserMedia(constraints, success, error) {
disableAutogain(constraints);
return original.call(this, constraints, success, error);
};
}
patchFunction(navigator, 'getUserMedia', patchDeprecatedGetUserMedia);
patchFunction(navigator, 'mozGetUserMedia', patchDeprecatedGetUserMedia);
patchFunction(navigator, 'webkitGetUserMedia', patchDeprecatedGetUserMedia);
patchFunction(MediaStreamTrack.prototype, 'applyConstraints', function (original) {
return function applyConstraints(constraints) {
disableAutogain(constraints);
return original.call(this, constraints);
};
});
console.log(
'Disable Autogain by Joey Watts!',
navigator.mediaDevices.getUserMedia
);
};

module.exports = disableAutogain;
1 change: 1 addition & 0 deletions app/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Here is the list of available arguments and its usage:
| customBGServiceIgnoreMSDefaults | A flag indicates whether to ignore Microsoft provided images or not | false |
| customBGServiceConfigFetchInterval | A numeric value in seconds as poll interval to download custom background service configuration. If 0, it will be downloaded only at application start | 0 |
| menubar | A value controls the menu bar behaviour (auto/visible/hidden) | auto |
| disableAutogain | A flag indicates whether to disable mic auto gain or not | false |



Expand Down
5 changes: 5 additions & 0 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ function argv(configPath) {
describe: 'A value controls the menu bar behaviour',
type: 'string',
choices: ['auto', 'visible', 'hidden']
},
disableAutogain: {
default: false,
describe: 'A flag indicates whether to disable mic auto gain or not',
type: 'boolean'
}
})
.parse(process.argv.slice(1));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.1.9",
"version": "1.1.10",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down

0 comments on commit 1bbf766

Please sign in to comment.