Merge pull request #2 from SKATTKOOKIE/bugfix/make-sound-only-occur-to-connected-users

Fixed issue where everyone in community could
This commit is contained in:
Brandon 2026-02-27 19:41:34 +00:00 committed by GitHub
commit b2ba36a765
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 35 additions and 2 deletions

View File

@ -6,6 +6,9 @@ export function injectSounds(webContents: Electron.WebContents) {
window.__soundsInjected = true;
let ctx = null;
let currentUserId = null;
let currentChannelId = null;
function getAudioContext() {
if (!ctx) ctx = new AudioContext();
return ctx;
@ -37,6 +40,16 @@ export function injectSounds(webContents: Electron.WebContents) {
setTimeout(() => playTone(440, 0.3), 150);
}
function playUserJoinSound() {
playTone(880, 0.15);
setTimeout(() => playTone(1100, 0.2), 150);
}
function playUserLeaveSound() {
playTone(440, 0.15);
setTimeout(() => playTone(220, 0.3), 150);
}
const OriginalWebSocket = window.WebSocket;
window.WebSocket = class extends OriginalWebSocket {
@ -47,8 +60,28 @@ export function injectSounds(webContents: Electron.WebContents) {
try {
const data = JSON.parse(event.data);
if (data.type === "VoiceChannelJoin") playConnectSound();
if (data.type === "VoiceChannelLeave") playDisconnectSound();
if (data.type === "Ready" && data.users) {
const self = data.users.find(u => u.relationship === "User");
if (self) currentUserId = self._id;
}
if (data.type === "VoiceChannelJoin" && data.state?.id === currentUserId) {
currentChannelId = data.id;
playConnectSound();
}
if (data.type === "VoiceChannelLeave" && data.user === currentUserId) {
currentChannelId = null;
playDisconnectSound();
}
if (data.type === "VoiceChannelJoin" && data.state?.id !== currentUserId && currentChannelId && data.id === currentChannelId) {
playUserJoinSound();
}
if (data.type === "VoiceChannelLeave" && data.user !== currentUserId && currentChannelId && data.id === currentChannelId) {
playUserLeaveSound();
}
} catch {}
});