2024-11-17 12:21:16 +00:00
|
|
|
import definePlugin from "@utils/types";
|
|
|
|
import { FluxDispatcher } from "@webpack/common";
|
|
|
|
|
2024-11-17 12:41:41 +00:00
|
|
|
let muted = false;
|
|
|
|
let socket: WebSocket;
|
|
|
|
|
2024-11-17 12:21:16 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "muter",
|
|
|
|
description: "muter companion plugin. Mirrors system mutes to Discord.",
|
|
|
|
authors: [{ name: "isitreallyalive", id: 1269669249056510026n }],
|
2024-11-17 12:41:41 +00:00
|
|
|
|
2024-11-17 12:21:16 +00:00
|
|
|
start() {
|
2024-11-17 12:41:41 +00:00
|
|
|
socket = new WebSocket("ws://localhost:3034");
|
2024-11-17 12:21:16 +00:00
|
|
|
|
|
|
|
socket.onmessage = (event) => {
|
2024-11-17 12:41:41 +00:00
|
|
|
muted = event.data.size > 0;
|
2024-11-17 12:21:16 +00:00
|
|
|
FluxDispatcher.dispatch({
|
|
|
|
type: "AUDIO_SET_SELF_MUTE",
|
|
|
|
context: "default",
|
2024-11-17 12:41:41 +00:00
|
|
|
mute: muted
|
2024-11-17 12:21:16 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// todo: try to fix weird virtual bug
|
2024-11-17 12:41:41 +00:00
|
|
|
},
|
|
|
|
flux: {
|
|
|
|
AUDIO_TOGGLE_SELF_MUTE: () => {
|
|
|
|
const buf = new ArrayBuffer(1);
|
|
|
|
const view = new Uint8Array(buf);
|
|
|
|
if (!muted) view[0] = 1;
|
|
|
|
socket.send(new Blob([buf]));
|
|
|
|
}
|
2024-11-17 12:21:16 +00:00
|
|
|
}
|
2024-11-17 12:41:41 +00:00
|
|
|
});
|