From f64ce6168d6e22143e81cf7a572ca645dbf40f44 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 3 Apr 2026 21:14:00 +1100 Subject: [PATCH] refactor: update sound file handling to resolve base URL dynamically --- src/app/features/call/CallSounds.ts | 41 ++++++++++++++++++----------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/app/features/call/CallSounds.ts b/src/app/features/call/CallSounds.ts index a9df927..10d5560 100644 --- a/src/app/features/call/CallSounds.ts +++ b/src/app/features/call/CallSounds.ts @@ -13,19 +13,30 @@ export enum CallSoundType { CallDialing = 'call_dialing', } -/** - * Maps sound types to their URL paths (served from public folder) - */ -const SOUND_SOURCES: Record = { - [CallSoundType.MicMute]: './sound/Mic_Mute.ogg', - [CallSoundType.MicUnmute]: './sound/Mic_Unmuted.ogg', - [CallSoundType.Deafen]: './sound/Speakers_Deafen.ogg', - [CallSoundType.Undeafen]: './sound/Speakers_Undeafen.ogg', - [CallSoundType.CallJoined]: './sound/Call_Joined.ogg', - [CallSoundType.CallDepart]: './sound/Call_Depart.ogg', - [CallSoundType.CallDialing]: './sound/Call_Dialing.ogg', +const SOUND_FILES: Record = { + [CallSoundType.MicMute]: 'Mic_Mute.ogg', + [CallSoundType.MicUnmute]: 'Mic_Unmuted.ogg', + [CallSoundType.Deafen]: 'Speakers_Deafen.ogg', + [CallSoundType.Undeafen]: 'Speakers_Undeafen.ogg', + [CallSoundType.CallJoined]: 'Call_Joined.ogg', + [CallSoundType.CallDepart]: 'Call_Depart.ogg', + [CallSoundType.CallDialing]: 'Call_Dialing.ogg', }; +/** + * Resolves the base URL for sounds. + * In Electron production, sounds are in resources/sound/ as plain files. + * In dev or browser, sounds are served from public/sound/. + */ +async function resolveSoundBaseUrl(): Promise { + const electronAudio = (window as any).electron?.audio; + if (electronAudio?.getSoundBaseUrl) { + const base: string | null = await electronAudio.getSoundBaseUrl(); + if (base) return base; + } + return './sound'; +} + /** * Manages call-related sound effects. * Handles playing local sounds and coordinating with remote participants. @@ -38,15 +49,15 @@ export class CallSounds { private isDeafened = false; constructor() { - this.preloadSounds(); + resolveSoundBaseUrl().then((base) => this.preloadSounds(base)); } /** * Preloads all call sounds for instant playback */ - private preloadSounds(): void { - Object.entries(SOUND_SOURCES).forEach(([type, src]) => { - const audio = new Audio(src); + private preloadSounds(base: string): void { + Object.entries(SOUND_FILES).forEach(([type, file]) => { + const audio = new Audio(`${base}/${file}`); audio.preload = 'auto'; this.audioElements.set(type as CallSoundType, audio); });