-
Notifications
You must be signed in to change notification settings - Fork 13
/
edoStereo.plugin.js
296 lines (278 loc) · 11.4 KB
/
edoStereo.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/**
* @name edoStereo
* @version 0.0.6
* @description Adds stereo sound to Discord with some extra stuff. Better Discord v1.10.2
* @authorLink https://github.com/edoderg
* @website https://edoderg.github.io/
* @source https://github.com/edoderg/edoStereo
* @invite fgMC6SetXk
* @updateUrl https://github.com/edoderg/edoStereo/blob/main/edoStereo.plugin.js
*/
module.exports = (() => {
const config = {
// configuration object for the plugin
main: "index.js",
info: {
name: "edoStereo",
authors: [
{ name: "ed.o", discord_id: "269831113919299584" }
],
version: "0.0.6",
description:
"Adds stereo sound to your Discord Client with some extra stuff. Better Discord v1.10.2",
},
changelog: [
{
title: "Changelog",
items: [
"Integrated Spotify Pause Blocker functionality",
"Added more bitrate options",
"Now shows current settings when joining a voice channel / In the settings panel",
"General improvements and optimizations"
]
}
],
defaultConfig: [
{
type: "switch",
id: "enableToasts",
name: "Enable notifications",
note: "Warning for Discord Audio Features",
value: true,
},
{
type: "dropdown",
id: "stereoChannelOption",
name: "Stereo Channel Option",
note: "Select your preferred channel option",
value: "2.0",
options: [
{ label: "1.0 Mono Sound", value: "1.0" },
{ label: "2.0 Normal Stereo Sound (Default)", value: "2.0" },
{ label: "7.1 Surround Sound", value: "7.1" },
],
},
{
type: "dropdown",
id: "bitrateOption", // removed 8kbps option
name: "Bitrate Option",
note: "Select your preferred bitrate",
value: "384000",
options: [
{ label: "48kbps", value: "48000" },
{ label: "64kbps", value: "64000" },
{ label: "96kbps", value: "96000" },
{ label: "128kbps", value: "128000" },
{ label: "256kbps", value: "256000" },
{ label: "384kbps (Default)", value: "384000" },
{ label: "512kbps", value: "512000" },
],
},
{
type: "category",
id: "otherSettings",
name: "Miscellaneous",
shown: true,
settings: [
{
type: "switch",
id: "enableSpotifyPauseBlocker", // added
name: "Spotify Pause Blocker",
note: "Prevents Discord from pausing Spotify after 30 seconds of constant mic input",
value: false,
},
],
},
],
};
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(
"[edoStereo] Library Missing",
`ZeresPluginLibrary is missing. Click "Install Now" to download it.`,
{
confirmText: "Install Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get(
"https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js",
async (error, response, body) => {
if (error) {
console.error("Error downloading ZeresPluginLibrary:", error);
BdApi.showConfirmationModal(
"Download Error",
"An error occurred while downloading ZeresPluginLibrary. Please try again later or download it manually from the official website.",
{
confirmText: "OK",
cancelText: "Cancel",
}
);
return;
}
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 edoStereo extends Plugin {
onStart() {
BdApi.UI.showNotice("[edoStereo v.0.0.6] You can now use edoStereo 😉", { type: "info", timeout: 5000 });
this.settingsWarning();
this.justJoined = false;
// patch discord's voice module to enable stereo sound
const voiceModule = WebpackModules.getModule(BdApi.Webpack.Filters.byPrototypeFields("updateVideoQuality"));
BdApi.Patcher.after("edoStereo", voiceModule.prototype, "updateVideoQuality", (thisObj, _args, ret) => {
if (thisObj) {
const setTransportOptions = thisObj.conn.setTransportOptions;
const channelOption = this.settings.stereoChannelOption;
const selectedBitrate = this.settings.bitrateOption;
thisObj.conn.setTransportOptions = (obj) => {
if (obj.audioEncoder) {
obj.audioEncoder.params = {
stereo: channelOption,
};
obj.audioEncoder.channels = parseFloat(channelOption);
obj.encodingVoiceBitRate = parseInt(selectedBitrate);
}
if (obj.fec) {
obj.fec = false; // disable forward error correction (fec)
}
if (obj.encodingVoiceBitRate < selectedBitrate) {
obj.encodingVoiceBitRate = selectedBitrate;
}
setTransportOptions.call(thisObj.conn, obj);
if (!this.justJoined) {
const spotifyStatus = this.settings.otherSettings.enableSpotifyPauseBlocker ? "Enabled" : "Disabled";
this.showCustomToast(`edoStereo: Channel ${channelOption}, Bitrate ${parseInt(selectedBitrate)/1000}kbps, Spotify Blocker: ${spotifyStatus}`, { type: "info", timeout: 5000 });
this.justJoined = true;
}
};
return ret;
}
});
this.showCustomToast = (content, options) => { // added
const toastElement = BdApi.UI.showToast(content, options);
if (toastElement) {
toastElement.style.position = 'fixed';
toastElement.style.top = '20px';
toastElement.style.right = '20px';
toastElement.style.left = 'auto';
toastElement.style.bottom = 'auto';
}
};
const voiceConnectionModule = WebpackModules.getByProps("hasVideo", "disconnect", "isConnected");
this.disconnectPatcher = BdApi.Patcher.after("edoStereo", voiceConnectionModule, "disconnect", () => {
this.justJoined = false;
});
if (this.settings.otherSettings.enableSpotifyPauseBlocker) {
this.enableSpotifyPauseBlocker();
}
}
enableSpotifyPauseBlocker() { // added
XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;
const myOpen = function(method, url, async, user, password) {
if (url === "https://api.spotify.com/v1/me/player/pause") {
url = "https://api.spotify.com/v1/me/player/play";
}
this.realOpen(method, url, async, user, password);
};
XMLHttpRequest.prototype.open = myOpen;
const hidePopup = () => {
const popup = document.querySelector('.popup-container.popup-show');
if (popup) {
popup.style.display = 'none';
}
};
this.hidePopupInterval = setInterval(hidePopup, 1000);
this.showCustomToast("edoStereo: Spotify Pause Blocker Enabled", { type: "success", timeout: 6000 });
}
disableSpotifyPauseBlocker() {
if (XMLHttpRequest.prototype.realOpen) {
XMLHttpRequest.prototype.open = XMLHttpRequest.prototype.realOpen;
delete XMLHttpRequest.prototype.realOpen;
}
if (this.hidePopupInterval) {
clearInterval(this.hidePopupInterval);
}
this.showCustomToast("edoStereo: Spotify Pause Blocker Disabled", { type: "warning", timeout: 6000 });
}
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 optimal edoStereo performance",
{ type: "warning", timeout: 7000 }
);
}
return true;
}
return false;
}
onStop() {
Patcher.unpatchAll();
if (this.disconnectPatcher) this.disconnectPatcher();
this.disableSpotifyPauseBlocker();
}
getSettingsPanel() {
const panel = this.buildSettingsPanel();
panel.addListener((id, value) => {
if (id === "enableSpotifyPauseBlocker") {
if (value) {
this.enableSpotifyPauseBlocker();
} else {
this.disableSpotifyPauseBlocker();
}
}
});
const noteElement = document.createElement("div");
noteElement.className = "edoStereo-settings-note";
noteElement.innerHTML = `
<p style="color: #FF0000; margin-top: 10px;">Note: After changing any setting, please rejoin the voice channel for the changes to take effect.</p>
<p style="color: #00FF00; margin-top: 5px;">Current settings: Channel ${this.settings.stereoChannelOption}, Bitrate ${parseInt(this.settings.bitrateOption)/1000}kbps, Spotify Pause Blocker: ${this.settings.otherSettings.enableSpotifyPauseBlocker ? "Enabled" : "Disabled"}</p>
`;
panel.getElement().append(noteElement);
return panel.getElement();
}
};
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();