From 6c6e2098364bc70659c57856375ba10ccb3888e7 Mon Sep 17 00:00:00 2001 From: newt Date: Sun, 17 Nov 2024 12:41:41 +0000 Subject: [PATCH] feat: two-way sync --- index.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 3cbe96a..a016895 100644 --- a/index.ts +++ b/index.ts @@ -1,22 +1,34 @@ import definePlugin from "@utils/types"; import { FluxDispatcher } from "@webpack/common"; +let muted = false; +let socket: WebSocket; + export default definePlugin({ name: "muter", description: "muter companion plugin. Mirrors system mutes to Discord.", authors: [{ name: "isitreallyalive", id: 1269669249056510026n }], + start() { - const socket = new WebSocket("ws://localhost:3034"); + socket = new WebSocket("ws://localhost:3034"); socket.onmessage = (event) => { - let mute = event.data.size > 0; + muted = event.data.size > 0; FluxDispatcher.dispatch({ type: "AUDIO_SET_SELF_MUTE", context: "default", - mute + mute: muted }); }; // todo: try to fix weird virtual bug + }, + 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])); + } } -}); \ No newline at end of file +});