feat: two-way sync
This commit is contained in:
parent
2ee8ea5c1e
commit
6c6e209836
1 changed files with 16 additions and 4 deletions
20
index.ts
20
index.ts
|
@ -1,22 +1,34 @@
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { FluxDispatcher } from "@webpack/common";
|
import { FluxDispatcher } from "@webpack/common";
|
||||||
|
|
||||||
|
let muted = false;
|
||||||
|
let socket: WebSocket;
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "muter",
|
name: "muter",
|
||||||
description: "muter companion plugin. Mirrors system mutes to Discord.",
|
description: "muter companion plugin. Mirrors system mutes to Discord.",
|
||||||
authors: [{ name: "isitreallyalive", id: 1269669249056510026n }],
|
authors: [{ name: "isitreallyalive", id: 1269669249056510026n }],
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
const socket = new WebSocket("ws://localhost:3034");
|
socket = new WebSocket("ws://localhost:3034");
|
||||||
|
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
let mute = event.data.size > 0;
|
muted = event.data.size > 0;
|
||||||
FluxDispatcher.dispatch({
|
FluxDispatcher.dispatch({
|
||||||
type: "AUDIO_SET_SELF_MUTE",
|
type: "AUDIO_SET_SELF_MUTE",
|
||||||
context: "default",
|
context: "default",
|
||||||
mute
|
mute: muted
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo: try to fix weird virtual bug
|
// 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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue