This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
StereoSound.plugin.js
121 lines (112 loc) · 5.58 KB
/
StereoSound.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @name StereoSound
* @version 0.1.1
* @authorLink https://github.com/riolubruh
* @source https://raw.githubusercontent.com/riolubruh/StereoSoundFixed/main/StereoSound.plugin.js
*/
/*@cc_on
@if (@_jscript)
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\\BetterDiscord\\plugins");
var pathSelf = WScript.ScriptFullName;
// Put the user at ease by addressing them in the first person
shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)", 0, "I'm a plugin for BetterDiscord", 0x30);
if (fs.GetParentFolderName(pathSelf) === fs.GetAbsolutePathName(pathPlugins)) {
shell.Popup("I'm in the correct folder already.", 0, "I'm already installed", 0x40);
} else if (!fs.FolderExists(pathPlugins)) {
shell.Popup("I can't find the BetterDiscord plugins folder.\nAre you sure it's even installed?", 0, "Can't install myself", 0x10);
} else if (shell.Popup("Should I copy myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
fs.CopyFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)), true);
// Show the user where to put plugins in the future
shell.Exec("explorer " + pathPlugins);
shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
}
WScript.Quit();
@else@*/
module.exports = (() => {
const config = {"main":"index.js","info":{"name":"StereoSound","authors":[{"name":"Riolubruh","discord_id":"359063827091816448","github_username":"Riolubruh"}],"authorLink":"https://github.com/riolubruh","version":"0.1.1","description":"Adds stereo sound to your own microphone's output. Requires a capable stereo microphone.","github":"https://github.com/riolubruh","github_raw":"https://raw.githubusercontent.com/riolubruh/StereoSoundFixed/main/StereoSound.plugin.js"},"changelog":[{"title":"Changes","items":["Fixed after SWC update"]}],"defaultConfig":[{"type":"switch","id":"enableToasts","name":"Enable Toasts","note":"Allows the plugin to warn you about voice settings","value":true}]};
return !global.ZeresPluginLibrary ? class {
constructor() {this._config = config;}
getName() {return config.info.name;}
getAuthor() {return config.info.authors.map(a => a.name).join(", ");}
getDescription() {return config.info.description;}
getVersion() {return config.info.version;}
load() {
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (error, response, body) => {
if (error) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
start() {}
stop() {}
} : (([Plugin, Api]) => {
const plugin = (Plugin, Library) => {
const { WebpackModules, Patcher, Toasts } = Library;
return class StereoSound extends Plugin {
onStart() {
this.settingsWarning();
const voiceModule = WebpackModules.getModule(BdApi.Webpack.Filters.byPrototypeFields("updateVideoQuality"));
BdApi.Patcher.after("StereoSound", voiceModule.prototype, "updateVideoQuality", (thisObj, _args, ret) => {
if(thisObj){
const setTransportOptions = thisObj.conn.setTransportOptions;
thisObj.conn.setTransportOptions = function (obj) {
if (obj.audioEncoder) {
obj.audioEncoder.params = {
stereo: "2",
};
obj.audioEncoder.channels = 2;
}
if (obj.fec) {
obj.fec = false;
}
if (obj.encodingVoiceBitRate < 512000 ) { //128
obj.encodingVoiceBitRate = 512000
}
setTransportOptions.call(thisObj, obj);
};
return ret;
}});
}
settingsWarning() {
const voiceSettingsStore = WebpackModules.getByProps("getEchoCancellation");
if (
voiceSettingsStore.getNoiseSuppression() ||
voiceSettingsStore.getNoiseCancellation() ||
voiceSettingsStore.getEchoCancellation()
) {
if (this.settings.enableToasts) {
Toasts.show(
"Please disable echo cancellation, noise reduction, and noise suppression for StereoSound",
{ type: "warning", timeout: 5000 }
);
}
// This would not work, noise reduction would be stuck to on
// const voiceSettings = WebpackModules.getByProps("setNoiseSuppression");
// 2nd arg is for analytics
// voiceSettings.setNoiseSuppression(false, {});
// voiceSettings.setEchoCancellation(false, {});
// voiceSettings.setNoiseCancellation(false, {});
return true;
} else return false;
}
onStop() {
Patcher.unpatchAll();
}
getSettingsPanel() {
const panel = this.buildSettingsPanel();
return panel.getElement();
}
};
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();
/*@end@*/