From c01773e9326ed5eddbd41007a8f935d8657c20d9 Mon Sep 17 00:00:00 2001 From: redbaron2k7 <76609332+redbaron2k7@users.noreply.github.com> Date: Tue, 13 Aug 2024 12:12:41 -0600 Subject: [PATCH] WebcamStartNotifier --- src/plugins/webcamStartNotifier/README.md | 5 +++ src/plugins/webcamStartNotifier/index.ts | 37 +++++++++++++++++++++++ src/utils/constants.ts | 4 +++ 3 files changed, 46 insertions(+) create mode 100644 src/plugins/webcamStartNotifier/README.md create mode 100644 src/plugins/webcamStartNotifier/index.ts diff --git a/src/plugins/webcamStartNotifier/README.md b/src/plugins/webcamStartNotifier/README.md new file mode 100644 index 000000000..8e6bf038c --- /dev/null +++ b/src/plugins/webcamStartNotifier/README.md @@ -0,0 +1,5 @@ +# videoStartNotifier Plugin for Vencord + + Plays a sound notification when a user starts/stops their video in a voice chat. The sounds are the stream start/stop sounds but modified pitch + +Idea from [Vencord Plugin Request #1026](https://github.com/Vencord/plugin-requests/issues/1026) \ No newline at end of file diff --git a/src/plugins/webcamStartNotifier/index.ts b/src/plugins/webcamStartNotifier/index.ts new file mode 100644 index 000000000..20ccf86bb --- /dev/null +++ b/src/plugins/webcamStartNotifier/index.ts @@ -0,0 +1,37 @@ +import definePlugin from "@utils/types"; +import { SelectedChannelStore } from "@webpack/common"; +import { Devs } from "@utils/constants"; + +const startSound = "https://raw.githubusercontent.com/redbaron2k7/videoStartNotifier//main/start.mp3"; +const stopSound = "https://raw.githubusercontent.com/redbaron2k7/videoStartNotifier/main/stop.mp3"; + +function playNotification(isVideoOn: boolean) { + new Audio(isVideoOn ? startSound : stopSound).play(); +} + +export default definePlugin({ + name: "WebcamStartNotifier", + description: "Plays a sound when someone starts/stops their webcam in a voice channel", + authors: [Devs.redbaron2k7], + + flux: (() => { + const videoStates = new Map(); + + return { + VOICE_STATE_UPDATES: ({ voiceStates }: { voiceStates: Array<{ userId: string, channelId: string, selfVideo?: boolean; }>; }) => { + const currentChannelId = SelectedChannelStore.getVoiceChannelId(); + if (!currentChannelId) return; + + voiceStates.forEach(state => { + if (state.channelId !== currentChannelId) return; + + const prevVideoState = videoStates.get(state.userId); + if (state.selfVideo !== undefined && prevVideoState !== undefined && prevVideoState !== state.selfVideo) { + playNotification(state.selfVideo); + } + videoStates.set(state.userId, state.selfVideo ?? false); + }); + } + }; + })(), +}); \ No newline at end of file diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 35525cd17..1a200da55 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -545,6 +545,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ surgedevs: { name: "Chloe", id: 1084592643784331324n + }, + redbaron2k7: { + name: "redbaron2k7", + id: 1142923640778797157n } } satisfies Record);