VolumeBooster: Support browser and Vesktop (#2730)
This commit is contained in:
parent
273981deb7
commit
e07a4e19e6
3 changed files with 68 additions and 6 deletions
9
src/plugins/volumeBooster/README.md
Normal file
9
src/plugins/volumeBooster/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Volume Booster
|
||||||
|
|
||||||
|
Allows you to boost the volume over 200% on desktop and over 100% on other clients.
|
||||||
|
|
||||||
|
Works on users, bots, and streams!
|
||||||
|
|
||||||
|
![the volume being moved up to 270% on vesktop](https://github.com/user-attachments/assets/793e012e-c069-4fa4-a3d5-61c2f55edd3e)
|
||||||
|
|
||||||
|
![the volume being moved up to 297% on a stream](https://github.com/user-attachments/assets/77463eb9-2537-4821-a3ab-82f60633ccbc)
|
|
@ -31,10 +31,27 @@ const settings = definePluginSettings({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface StreamData {
|
||||||
|
audioContext: AudioContext,
|
||||||
|
audioElement: HTMLAudioElement,
|
||||||
|
emitter: any,
|
||||||
|
// added by this plugin
|
||||||
|
gainNode?: GainNode,
|
||||||
|
id: string,
|
||||||
|
levelNode: AudioWorkletNode,
|
||||||
|
sinkId: string,
|
||||||
|
stream: MediaStream,
|
||||||
|
streamSourceNode?: MediaStreamAudioSourceNode,
|
||||||
|
videoStreamId: string,
|
||||||
|
_mute: boolean,
|
||||||
|
_speakingFlags: number,
|
||||||
|
_volume: number;
|
||||||
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "VolumeBooster",
|
name: "VolumeBooster",
|
||||||
authors: [Devs.Nuckyz],
|
authors: [Devs.Nuckyz, Devs.sadan],
|
||||||
description: "Allows you to set the user and stream volume above the default maximum.",
|
description: "Allows you to set the user and stream volume above the default maximum",
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
|
@ -45,12 +62,28 @@ export default definePlugin({
|
||||||
].map(find => ({
|
].map(find => ({
|
||||||
find,
|
find,
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=maxValue:\i\.\i)\?(\d+?):(\d+?)(?=,)/,
|
match: /(?<=maxValue:)\i\.\i\?(\d+?):(\d+?)(?=,)/,
|
||||||
replace: (_, higherMaxVolume, minorMaxVolume) => ""
|
replace: (_, higherMaxVolume, minorMaxVolume) => `${higherMaxVolume}*$self.settings.store.multiplier`
|
||||||
+ `?${higherMaxVolume}*$self.settings.store.multiplier`
|
|
||||||
+ `:${minorMaxVolume}*$self.settings.store.multiplier`
|
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
|
// Patches needed for web/vesktop
|
||||||
|
{
|
||||||
|
find: "streamSourceNode",
|
||||||
|
predicate: () => IS_WEB,
|
||||||
|
group: true,
|
||||||
|
replacement: [
|
||||||
|
// Remove rounding algorithm
|
||||||
|
{
|
||||||
|
match: /Math\.max.{0,30}\)\)/,
|
||||||
|
replace: "arguments[0]"
|
||||||
|
},
|
||||||
|
// Patch the volume
|
||||||
|
{
|
||||||
|
match: /\.volume=this\._volume\/100;/,
|
||||||
|
replace: ".volume=0.00;$self.patchVolume(this);"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
// Prevent Audio Context Settings sync from trying to sync with values above 200, changing them to 200 before we send to Discord
|
// Prevent Audio Context Settings sync from trying to sync with values above 200, changing them to 200 before we send to Discord
|
||||||
{
|
{
|
||||||
find: "AudioContextSettingsMigrated",
|
find: "AudioContextSettingsMigrated",
|
||||||
|
@ -83,4 +116,20 @@ export default definePlugin({
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
patchVolume(data: StreamData) {
|
||||||
|
if (data.stream.getAudioTracks().length === 0) return;
|
||||||
|
|
||||||
|
data.streamSourceNode ??= data.audioContext.createMediaStreamSource(data.stream);
|
||||||
|
|
||||||
|
if (!data.gainNode) {
|
||||||
|
const gain = data.gainNode = data.audioContext.createGain();
|
||||||
|
data.streamSourceNode.connect(gain);
|
||||||
|
gain.connect(data.audioContext.destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.gainNode.gain.value = data._mute
|
||||||
|
? 0
|
||||||
|
: data._volume / 100;
|
||||||
|
}
|
||||||
});
|
});
|
|
@ -534,6 +534,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
name: "Joona",
|
name: "Joona",
|
||||||
id: 297410829589020673n
|
id: 297410829589020673n
|
||||||
},
|
},
|
||||||
|
sadan: {
|
||||||
|
name: "sadan",
|
||||||
|
id: 521819891141967883n,
|
||||||
|
},
|
||||||
Kylie: {
|
Kylie: {
|
||||||
name: "Cookie",
|
name: "Cookie",
|
||||||
id: 721853658941227088n
|
id: 721853658941227088n
|
||||||
|
|
Loading…
Reference in a new issue